Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    direction between points

    SDK Help
    0
    7
    588
    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
      Helper
      last edited by

      On 11/11/2013 at 03:53, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   r14 
      Platform:      
      Language(s) :     C++  ;

      ---------
      hm, i am still having problems to detect the direction between two points. i thought this would work, but it seems not:

      Vector angle = VectorToHPB(point_to-point_from);

      how do i get the correct angle between two points?

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 11/11/2013 at 05:52, xxxxxxxx wrote:

        Howdy,

        Well, I think what you need is the Dot Product. The dot product of 2 normalized vectors gives you the cosine of the angle between them. 😉

        Adios,
        Cactus Dan

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 11/11/2013 at 08:17, xxxxxxxx wrote:

          There's also the  VectorAngle() function in the SDK that you can use. If you want to test the angle of two splines. Using their points rather than their axis values.

          //This example gets the angle between two splines  
          //NOTE: This does NOT!! test the angle between the two spline objects axis values  
          //      You need to move the points of the splines to get a result from this code  
          //      It doesn't care how the two spline objects are oriented to eachother  
            
            BaseObject *sp1 = doc->SearchObject("s1");  
            SplineObject *s1 = ToPoint(sp1);  
            BaseObject *sp2 = doc->SearchObject("s2");  
            SplineObject *s2 = ToPoint(sp2);  
            
            Vector *s1pnts = s1->GetPointW();                //Get all the points...We only have two points in the spline  
            Vector *s2pnts = s2->GetPointW();                //Get all the points...We only have two points in the spline  
            
            Vector vec1 = s1pnts[1]-s1pnts[0];               //The first spline's vector  
            Vector vec2 = s2pnts[1]-s2pnts[0];               //The second spline's vector  
            
            Real angle_rad = VectorAngle(vec1, vec2);        //This gets the angle bewteen the two spline vectors in radians  
            Real angle_deg = angle_rad*180.0/pi;             //Converts radians to degrees  
            GePrint(RealToString(angle_deg));
          

          -ScottA

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 11/11/2013 at 08:35, xxxxxxxx wrote:

            Howdy,

            Ah! I've never noticed the VectorAngle() function in the SDK.
            I've always just done it myself like this:

            Real angle = ACos(!v1 * !v2);
            

            Adios,
            Cactus Dan

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 11/11/2013 at 09:08, xxxxxxxx wrote:

              thank you for your inputs. i came across the VectorAngle today, too. but it seems it doesn't return what i want. because if i rotate an object by the retrieved value, it behaves wrong when the second point passes the axis of the first point. generally i am trying to rotate an object placed at point x so it points the direction from point x-1 to point x+1. somehow i need to divide the result of VectorAngle by two, also.

              btw, what would i need to do if i need 3-dimensional rotation?

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 11/11/2013 at 22:54, xxxxxxxx wrote:

                here is a shot of what is happening.

                edit: ok, got it now. in my previous approach i missed using the normalized vectors. now it seems to work:

                VectorToHPB(from.GetNormalized() - to.GetNormalized())

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 12/11/2013 at 11:10, xxxxxxxx wrote:

                  Howdy,

                  Yes, vectors need to be normalized to get a proper angle calculation. 😉

                  Adios,
                  Cactus Dan

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