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

    Distance between two points

    SDK Help
    0
    3
    326
    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 06/01/2014 at 23:11, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   13,14,15 
      Platform:      
      Language(s) :

      ---------
      How do I get the distance between two points, in global space?
      I have tried to subtract two vectors, and then use GetLenth(), but I get different results depending on the order of the two vectors, and have a feeling I do not do it right.

      Yes, it is a basic question I assume, but I have not needed this before now.
      To clairify, in this case I want to know how this is done for two null objects, just to make it as simple as possible.

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

        On 07/01/2014 at 07:20, xxxxxxxx wrote:

        Hi ingvar,

        your approach doesn't sound very wrong.

          
        Matrix mg1 = op1->GetMg();
        Matrix mg2 = op2->GetMg();
          
        Vector p1 = op->GetPointR()[42];
        Vector p2 = op->GetPointR()[31];
          
        Float distance = ((mg2 * p2) - (mg1 * p1)).GetLength();
        

        what did you do differently?

        Best,
        -Niklas

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

          On 07/01/2014 at 12:25, xxxxxxxx wrote:

          Hi Niklas!

          > your approach doesn't sound very wrong.
          And you are so right, I have done it correctly. But i used some numbers from another part of my code, where I did it wrong!! So I though my latest calculation also was wrong.
          Still I learnt something from you post, I have done it the simple way, like this:

                  Matrix mgA = opA->GetMg();
              	Matrix mgB = opB->GetMg();
                  Real distance = (mgA.off - mgB.off).GetLength();
          

          And this works, for Nulls, as well as PolygonObjects.
          Now  also can calculate the distance between points too, thanks!

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