Jump to content
  • Advertisement
Sign in to follow this  
markgame66

Distance Between Two Vectors?

This topic is 3611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Incorrect , that is the lenght of a vector .
Without specifing the metrix used , your question is vague.
I suppose you want to compute the distance beetween two oriented vectors don't you ?
There are 2 ways
the first is to compute the distance using the application point of these 2 vectors, the other is finding the closest point on segments using the direction vectors.
Its up to you to use this methods to your benefit.
Elaborate more deeply yout problem if you want a correct answer

Share this post


Link to post
Share on other sites
Hi thanks for you replies,

Basically I have two vectors. 1) Is the current location of my robot, the other is it's way point. I want to work out the distance between the two.

So that I can work out hoe close the robot is to it's Way Point. I'm trying to find a solution to a problem where the steering command makes the robot thrash about as it approaches the way point. So I thought if I knew the distance between them then I'd have something to tune the steering cmd with

Thanks

Mark

Share this post


Link to post
Share on other sites
You should do it the way Erik Rufelt mentioned:

Subtract the second vector from the first, and then compute the length of the resulting vector:

float calcdist(vector3d v1, v2)
{
v.x = v1.x - v2.x;
v.y = v1.y - v2.y;
v.z = v1.z - v2.z;
return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
}

Hope this helps!

Share this post


Link to post
Share on other sites
To explain why your original question was ambiguous:

A vector has a start point and an end point. How can you find the distance between a four points? However, most of the time the starting point is not used, and is assumed to be the origin (this is probably the way your vector class works, and the way you think about vectors). In that context, it still doesn't make sense, but you could have asked for the distance between the two end points.

Equally valid interpretation of your original question could have been:
What is the distance between the two start points?
What is the minimum distance between the two line segments going from the start point and end point of each vector?

Share this post


Link to post
Share on other sites
Quibbling a bit here..

A vector is not a point, nor is a vector 2 points.

A vector is a direction and magnitude.

Most game programmers use their vector type for both vectors and points, but in the math world thats actualy a big no-no.

vector = vector + vector
vector = vector - vector
vector = point - point
vector = vector * scaler
vector = vector / scaler

point = point + vector
point = point - vector

now, 'point + point' does not yield a vector, nor does it yield a point. The same goes for 'point * scaler' and so on.

In the math world if you asked what the distance is between two vectors, you would most likely get an ANGLE as an answer.

"Those two vectors are 15 degrees apart"

Share this post


Link to post
Share on other sites
Quote:
Original post by Rockoon1
A vector is not a point, nor is a vector 2 points.


Agreed, but a vector has a start point and an endpoint. (I guess the actual terms are initial point and terminal point. Or tail and head.) point + point of course does not yield a vector, it makes no sense to add points. It also doesn't make sense to subtract points, and I think a particularly pedantic mathematician would say that is no more valid than adding points and getting a vector.

If a mathematician gave me an angle when I asked for a distance, I would have scoffed. Perhaps I am wrong, but an angle does not give distance. Any reasonable mathematician would have balked at that question and said it was extremely ambiguous. My post was to clarify why it was ambiguous.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ezbez
Quote:
Original post by Rockoon1
A vector is not a point, nor is a vector 2 points.


Agreed, but a vector has a start point and an endpoint. (I guess the actual terms are initial point and terminal point. Or tail and head.)

No.
A vector is something that behaves like a vector from an algebraic point of view, no points are involved. When we have vectors we can introduce "points" in our algebraic toybox as something that can be summed to vectors to get other points in a way that, for some popular vector spaces, gives affine spaces that match our geometric intuition.

What has an initial point and a terminal point is the line segment, which is not a vector because it cannot be summed meaningfully to other segments.
Instead of addition, multiplication by a scalar and other arithmetic with coordinates, geometric loci like segments, being sets of points, have set operations.
Less philosophically, both n-dimensional vectors and n-dimensional points are uniquely represented by n numbers, while a line segment is determined by its two endpoints which amount to 2n numbers: it cannot be a vector.
Quote:

point + point of course does not yield a vector, it makes no sense to add points. It also doesn't make sense to subtract points, and I think a particularly pedantic mathematician would say that is no more valid than adding points and getting a vector.

There is a substantial difference, which you seem to miss, between subtracting and adding points: subtracting points gives vectors by definition, adding points is nonsensical.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!