# Distance between two points

• 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.

• 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();
Vector p2 = op->GetPointR();

Float distance = ((mg2 * p2) - (mg1 * p1)).GetLength();
``````

what did you do differently?

Best,
-Niklas

• 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!