Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Why doesn't c4d.Vector.GetAngle throw an error for the null vector?

    Cinema 4D SDK
    python s26
    2
    2
    421
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      HerrMay
      last edited by

      Hi guys,

      TL;DR
      Shouldn't c4d.Vector.GetAngle throw a e.g. ZeroDivisionError when invoked on a identity vector, that is a c4d.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

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @HerrMay
        last edited by ferdinand

        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:

        26ea0c5e-9de3-4885-bc15-34b4ee3342da-image.png

        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):

        123bbf8a-568b-49a5-9ff3-2bac41f61339-image.png

        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 :

        ebfd4607-e872-42ef-898c-d3a2de4d8dd8-image.png

        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

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • First post
          Last post