I get dot product results of -0
Is this on purpose?
Why can’t it just be 0 if the vectors are perpendicular?
I get dot product results of -0
Is this on purpose?
Why can’t it just be 0 if the vectors are perpendicular?
Most likely this is a rounding error. If you compare it to +0 within a (strictly positive) tolerance - which is always a good idea when comparing floating point numbers - you should have no trouble with -0 I think.
Thanks, im currently using a larger than -0.01 to get all -0 and positive dot products.
It’s an implementation detail, emerging from the particular way chosen (from all the many) to represent floating point numbers on finite binary computers. It shouldn’t make any difference numerically. You shouldn’t divide by it, obviously. But should you do so, there are also inf, -inf and NaN. All perfectly valid IEEE_754 floats too. Just mathematically rather ambiguous ones to interpret, that need more careful treatment.
FYI:
8.3.7 Floating-point types
C# supports two floating-point types: float and double. The float and double types are represented using the 32-bit single-precision and 64-bit double-precision IEC 60559 formats, which provide the following sets of values:
Positive zero and negative zero.
using some threshold / epsilon when comparing floating point values
see also
https://developer.rhino3d.com/api/rhinocommon/rhino.rhinomath/epsilonequals
and
https://developer.rhino3d.com/api/rhinocommon/rhino.rhinomath/zerotolerance
-0.01 is already very rough (ca. 90.6 Degree)
you can use scientific notation to set much lower limits
-1.0e-9
also make sure to Unitize the vectors first
maybe you get a more readable code with
https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.vector3d/vectorangle