Game Development Community

How to find distance between two points?

by Lee Latham · in Torque Game Engine · 02/07/2007 (7:11 pm) · 3 replies

I swear I've done a ton of searching on this, and it seems to elementary, but I just can't find it. Is there a function that will simply take two points and return a single floating point distance?

I find some old posts about vectorDistance, but it doesn't seem to be in there any more... :-(

Lee

#1
02/07/2007 (7:28 pm)
These functions should come in handy for you:

// VectorMath.
   // Vector manipulation functions:

   // Returns a+b.
   VectorAdd(Vector3F a, Vector3F b);

   // Returns a-b.
   VectorSub(Vector3F a, Vector3F b);

   // Returns a scaled by scalar (ie, a*scalar).
   VectorScale(Vector3F a, float scalar);

   // Returns a scaled such that length(a) = 1.
   VectorNormalize(Vector3F a);

   // Calculate the dot product of a and b.
   VectorDot(Vector3F a, Vector3F b);

   // Calculate the cross product of a and b.
   VectorCross(Vector3F a, Vector3F b);

   // Calculate the distance between a and b.
   VectorDist(Vector3F a, Vector3F b);

   // Calculate the length of a vector.
   VectorLen(Vector3F v);

   // Create an orthogonal basis from the given vector. Return a matrix.
   VectorOrthoBasis(AngAxisF aaf);

To directly answer your question:

// Calculate the distance between a and b.
   VectorDist(Vector3F a, Vector3F b);
#2
02/07/2007 (11:19 pm)
That did the trick!

I must have missed it when skimming over the other ones I don't understand. I've been looking around the net for a nice explanation of the others (I never got very far in math, but it doesn't seem TOO far out).

Thanks!
#3
02/08/2007 (9:36 am)
That returns in Torque metres, right?