Why doesn't c4d.Vector.GetAngle throw an error for the null vector?
-
Hi guys,
TL;DR
Shouldn'tc4d.Vector.GetAngle
throw a e.g.ZeroDivisionError
when invoked on a identity vector, that is ac4d.Vector(0, 0, 0)
instead of return 90°?For anyone who's interested:
I'm currently trying to teach myself linear algebra and therefore trying to wrap my head around vectors, its properties, methods and dependencies.To get a better understanding I wrote my own Vector class, did research and implemented the common methods as well as the properties that define a vector.
While I'm doing this I constantly compare my vector class and the outcome of any calculation with the native c4d.Vector to test if my calculations/assumptions hold true.
When using
c4d.Vector.GetAngle
with a identity vector,c4d.Vector(0, 0, 0)
the method returns 90°. Maybe this is a stupid question but shouldn't it raise an exception that the vector has no direction as well as no length and therefore by definition no angle?Cheers,
Sebastian -
Hello Herr May,
Thank you for reaching out to us. I am not quite sure why you think it should do that.
The angle between two vectors u and v is defined as:
theta(u, v) = arccosine(~u * ~v)
I.e., the arccosine of the dot product of the two normalized vectors. This is due to the so called circle functions, specifically this identity:
Under the hood, GetAngle does exactly what I declared above (just in a bit more efficient manner, as calculating the normalized vector is much more expensive than this little trick):
As you can see, the correct solution to the arccosine of the dot product of the null vector with itself is 0.5 π, i.e., the value you got :
You could now argue if that is a sensible result for a method that is called 'GetAngle' and if it should throw an error on getting an input vector or being called on a vector with the length zero. But you have also to keep in mind that the C++ backend is used by people who will know the identity
pi_half = arccosine(~(0, 0, 0) * ~(0, 0, 0))
and might want to make use of it.Cheers,
Ferdinand