#### Archived

This topic is now archived and is closed to further replies.

# distance between vectors

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

## Recommended Posts

I haven''t done alot of maths lately which has made me fogot alot of things. However what I want to know is how to get the distance between vector and vector in 3D space. The idea I have looks something like this: |v3| = |(v2-v1)| Heh, I''m not good at writing math formulas, but hey it makes me look smarter So if you don''t understand it then: v3 = v2-v1; v3.length = sqrt(v3.x*v3.x+v3.y+v3.y+v3.z+v3.z); Is this correct?

##### Share on other sites
Distance between two vectors? Vectors are not fixed in space; they have magnitude and direction, but not position, so the concept of "distance" doesn''t seem to make much sense.

##### Share on other sites
I think he/she meant vertex.

[edited by - Newfound Ajarn on November 11, 2003 11:42:02 PM]

##### Share on other sites
correct, vectors do not have position so you can't have a distance between them. if you are talking about specific vectors anchored at specific points, then you just need to find the distance between the two points which is:

v = vector between 2 points
v = (p1.x - p2.x, p1.y - p2.y, p1.z - p2.z);
distance between the points = |v| = sqrt(v.x^2 + v.y^2 + v.z^2);

-me

[edited by - Palidine on November 11, 2003 11:46:39 PM]

##### Share on other sites
You accidentally put "+" instead of "*" between the Y and the Z terms. Fix that, and you''ve got it.

##### Share on other sites
quote:

Distance between two vectors? Vectors are not fixed in space; they have magnitude and direction, but not position, so the concept of "distance" doesn't seem to make much sense.

I knew this would come up, and I thought about editing my post but I thought; "na, they can't be that priggish", well I was wrong.

quote:

You accidentally put "+" instead of "*" between the Y and the Z terms. Fix that, and you've got it.

typo

[edited by - angry on November 11, 2003 12:06:44 AM]

##### Share on other sites
Just for reference: Angel (Interactive Computer Graphics et al.) describes the difference between what you call a vector and a point as a true-vector and a position-vector.

A vector is simply a mathematical data structure - some people choose to think of it that way whilst others choose to think of it in more semantic terms: point and vector (where vector denotes a direction with magnitude). The fact is, if you regard a vector simply as a data structure then a vector can represent a position with respect to the origin in any 3D space.

Quite clearly, there are 2 schools of thought on this...

##### Share on other sites
Vectors do not even have to contain numbers! Vector spaces can be taken over lots of different fields.

##### Share on other sites
Just curious how you would define distance? Personally I would call distance a measure of how close two values are to one another. Also if a point is a position vector then how can there be a distance between points, but not vectors since a point is a vector.

##### Share on other sites
A point can be represented by a vector, but not the other way around. Distance can be defined in many ways ( in maths we call then metrics ), any distance or metric function must fulfil...

1) d(x,y) = 0 iff x = y
2) d(x,y) = d(y,x) for all x,y in the space
3) d(x,y) <= d(x,z) + d(z,y) for all x,y,z in the space

The Euclidean distance we most commonly use for vectors in an example of this

##### Share on other sites
And of course we can define a metric on any set using the discrete metric,

d(x,y) == 0 if x=y
d(x,y) == 1 if x!=y

and the sets don''t have to contain numbers at all. The discrete metric is useless in practice though (e.g. limits of sequences only defined for sequences which reach the limit and stay there).

##### Share on other sites
quote:
Original post by LilBudyWizer
Just curious how you would define distance? Personally I would call distance a measure of how close two values are to one another. Also if a point is a position vector then how can there be a distance between points, but not vectors since a point is a vector.

Well, you''d find the vector that connects the two end points of the two position vectors. That''ll give you the displacement, find the magnetude of the displacement to find the distance.

Personally, I consider a point an abstract concept that can be accurately modelled using a position vector.

quote:

Vectors do not even have to contain numbers

So, what, a 0 dimensional vector? Sounds pretty useless to me. How can a vector contain no numbers?

You have to remember that you''re unique, just like everybody else.

##### Share on other sites
Distance between two points (you''ll need to get actual positions to work with from the vectors):

distance = sqrt( ((x1-x2)*(x1-x2)) + ((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)) );

##### Share on other sites
I am in the school of thought that points and vectors are different things. Look up "Affine Space" for the precise mathematical description of the relationship between points and vectors.

In practice, they both look like a list of numbers, like (1,4,-3). The difference is in the operations that you can perform with them. You can:
- add two vectors, getting a vector
- multiply a vector by a number, getting a vector
- add a point and a vector, getting a point
- substract two points, getting a vector
- compute the weighted average (or baricenter) of several points, with weights that are numbers whose sum is 1, getting a point.

If you use real numbers and on top of the affine structure you have a positive definite quadratic form (a metric) then we are in the realm of "Euclidean Space".

To find the distance between two points, substract them (you get a vector) and find the size of the vector, using your metric. If you represent your points using a orthonormal reference (which you probably do), then it boils down to the formula that everybody knows.

##### Share on other sites
quote:
Original post by python_regious
quote:

Vectors do not even have to contain numbers

So, what, a 0 dimensional vector? Sounds pretty useless to me. How can a vector contain no numbers?

The set of continuous functions is a vector space, therefore any continuous function is a vector in this vector space. For a set to be a vector space, certain rules have to be met, and functions can meet these requirements, and can therefore be considered vectors in a vector space.

To build a vector space, you need base vectors. The vectors in the identity matrix of size NxN (for scalar vectors) are orthogonal and spans an N-dimensional vector space. Sine-waves on the range [-Inf, Inf] of different frequencies, and Legendre polynomials on the range [-1, 1], are orthogonal and can be used to span an infinite-dimensional vector space.

##### Share on other sites
quote:
Original post by Brother Bob To build a vector space, you need base vectors.

Actually, you don''t. Functions that map real numbers into real numbers form a good example of a vector space for which it is very difficult to find a base. A base does exist, indeed, provided that we accept the axiom of choice. But you don''t need to know one to build a vector space.

##### Share on other sites
Is a base vector the equivalent of the mapping function described in the axiom of choice, but for many dimensions?

##### Share on other sites
Hang on, continuous functions are vectors? I''m confused now, I''m thinking of vectors as the derivation from hypernumbers...

You have to remember that you''re unique, just like everybody else.

##### Share on other sites
I could be wrong, but I don''t think contineous functions are a vector. Rather they are a vector space and a specific function is a vector within that vector space.

##### Share on other sites
quote:

In practice, they both look like a list of numbers, like (1,4,-3). The difference is in the operations that you can perform with them. You can:
- add two vectors, getting a vector
- multiply a vector by a number, getting a vector
- add a point and a vector, getting a point
- substract two points, getting a vector
- compute the weighted average (or baricenter) of several points, with weights that are numbers whose sum is 1, getting a point.

Yes, you using the term ''vector'' as the semantic definition of offset-vector from an origin. If you really think about it, points are offset-vectors but just from the origin (our 3d space reference point). It is easier to conceptualize your rules written as follows:

- add 2 direction vectors, getting a direction vector
- multiply a direction vector by a scale, getting a scaled direction vector
- add a position-vector and a direction-vector, getting a position-vector
etc...

But I prefer to think of vectors as just arrays, not without any semantic meaning behind them.

##### Share on other sites
quote:
Original post by FReY
Yes, you using the term ''vector'' as the semantic definition of offset-vector from an origin.

The terminology I am using is the standard for Affine Space.
http://mathworld.wolfram.com/AffineSpace.html

quote:

If you really think about it, points are offset-vectors but just from the origin (our 3d space reference point).

I guess what you mean is that once you select a point as origin (which is an arbitrary selection), you can represent a point by the vector that you have to add to the origin to get it. True, but doesn''t change anything I said.

quote:

It is easier to conceptualize your rules written as follows:

- add 2 direction vectors, getting a direction vector
- multiply a direction vector by a scale, getting a scaled direction vector
- add a position-vector and a direction-vector, getting a position-vector
etc...

You can come up with a new language if you want, but "point" and "vector" are the standard ways of saying it. On top of that, I would not like calling points "position-vectors", because the word "vector" implies that those things can be added and multiplied by scalars, which is not true of points.

quote:

But I prefer to think of vectors as just arrays, not without any semantic meaning behind them.

I can see that. In practical terms, there are good arguments for and against having separate classes for points and vectors.
FOR:
- It more closely reflects the mathematical structures that we are using.
- It prevents some mistakes in compile time (adding two points will give an error, as that operation is undefined).
AGAINST:
- Expressions like "midpoint = .5*(point_A + point_B);" are not allowed, although the result is perfectly well defined. You would have to re-write that as "midpoint = point_A + .5*(point_B - point_A);", which is probably a little slower to evaluate.

##### Share on other sites
Of course points (position vectors) can be multiplied/divided by scalars or other vectors... Adding a position vector to another is just as valid and common. What else are you doing when you''re translating or rotating or scaling a 3d object? A transformation matrix is merely a convenient way to package together the vectors and scalars you''re adding and multiplying with.

Related to the original post, "distance" or difference between two (classical) vectors can also be a very useful concept. For example, in orbital mechanics you will often see people talking about "delta-v" which is the difference between two velocity vectors usually measured in m/s and calculated as |v2-v1| .

##### Share on other sites
quote:
Original post by alvaro
Functions that map real numbers into real numbers form a good example of a vector space for which it is very difficult to find a base.

Quite a few bases exist. That''s the theoretical fundation for Fourier transforms, Laplace transforms, wavelet transforms, Z transforms and many more (Mellin, Hankel, Gabor...)

Each of these transformations really is a function decomposition onto a specific orthonormal base of R->R (or C->).

##### Share on other sites
quote:
Original post by Fingers_
Of course points (position vectors) can be multiplied/divided by scalars or other vectors... Adding a position vector to another is just as valid and common. What else are you doing when you''re translating or rotating or scaling a 3d object? A transformation matrix is merely a convenient way to package together the vectors and scalars you''re adding and multiplying with.

When you translate or rotate or scale a 3d object you are applying an affine transformation, which a well defined operation. What I mean by "well defined" is that if your transformation does not depend on your choice of coordinates.

In a translation, you are adding a point and a vector, and you get a point. That was one of the allowed operations.

Multiplying by a scalar is not a well defined operation. If you change the origin, you get a different transformation.

quote:
Original post by Fruny Quite a few bases exist. That''s the theoretical fundation for Fourier transforms, Laplace transforms, wavelet transforms, Z transforms and many more (Mellin, Hankel, Gabor...)

Those are not really bases of the vector spaces. It is not true that any function can be expressed as a linear combination of a finite number of members of the base.

All your proposed "bases" are numerable. A base of the set of continuous real functions, for example, cannot be numerable. The functions F_a(x) = |x - a|, where a is a real number, form a linearly independent set. Any linearly independent set can be expanded to form a base, so there is a base that is not numerable. And all bases have the same cardinal.

##### Share on other sites
Based on the OPs very simple question, this discussion is waaaaaay off topic. As people have stated, yes... a vector space is a member of any member of a vector space see here for more details. You cannot really call points postitional vectors, as a many "normal" spaces would not necessarily fulfill the criterion of being a vector space. It is true however that most "normal" spaces are subsets of some vector space. As for bases, any vector space can have a basis, whether this basis is finite of not, is another matter entirely. I suspect the OP just wanted confirmation that their formula for distance between two Verticies formula was correct... which is was, so to the OP, You are correct .

PS: A vector space can be made over any field, and hence they are VERY general constructs. All you need is to fulfil the vector space criterion, and away we go. I think we should all assume that when someone says vector, unless otherwise specified... they mean a (1,2,3 or 4 dimensional usually) vector over the reals. If they want to refer to STL vectors (which are abstract vectors, over the template classes field) then they should qualify it. Just a suggestion, to try and cut down on ambiguity in future.

• ### Forum Statistics

• Total Topics
628710
• Total Posts
2984322

• 23
• 11
• 9
• 13
• 14