[Bf-python] normalze zero len vector
Campbell Barton
cbarton at metavr.com
Sat Oct 14 12:00:06 CEST 2006
Martin Poirier wrote:
> --- Campbell Barton <cbarton at metavr.com> wrote:
>
>
>> At the moment normalizing a zero length vector makes
>> the vector (nan,
>> nan, nan) on linux- which I had checks for in one of
>> my exporters.
>> however on win32 it became (-1.#INF, -1.#INF,
>> -1.#INF) - which Im not
>> sure how to check for.
>>
>> Could we make it that .normalize() does nothing if
>> the vectors length is
>> zero?
>>
>> In the case of exporters, zero length normals come
>> from faces with no area.
>>
>
> Are you sure it's really zero-length, not just really
> small?
>
> Moreover, the easy way to check against that would be
> to do this:
>
> v.normalize()
>
> if v * v != 1:
> print "\bBEEP!"
>
>
> That is, the scalar product of a normalized vector
> will always be one (or very close to it, you might
> have to use a delta value to account for floating
> point imprecision).
>
>
>
> To go back to your original question, protecting
> against zero-length vector normalizing would be
> possible (in that case, that would be the wanted
> behavior, IMHO), however, really small values might
> cause problem too (like the infinities you
> encountered), which would be harded to account if
> wanted at all.
>
> Martin
>
Good thinking, works on linux but would you believe, it.....
On windows this is what I get.
______________________________
a= Vector(0,0,0)
a.normalize()
print a
[-1.#IND00, -1.#IND00, -1.#IND00](vector)
val= a*a
print val
-1.#IND
val == 1
True
________________________
This is very crap, and makes cross platform exporters that deal with
normals hard to do properly,
taking this into account I think it may be best to ignore zero len
vectors, however your right that small vectors may also raise this error.
PS, A swear guy is you!
http://www.youtube.com/watch?v=vr3x_RRJdd4&mode=related&search=
--
Campbell J Barton
133 Hope Street
Geelong West, Victoria 3218 Australia
URL: http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241
More information about the Bf-python
mailing list