D3DXVECTOR3

Started by
12 comments, last by dehseth 15 years, 9 months ago
Hello ppl, I am a lil bit confused about definition of D3DXVECTOR3 in directX 9. As far as I know a vector is a quantity, defined by both magnitude and direction. In directX 9 if you define a D3DXVECTOR3 type variable, your variable has 3 parameter which are x, y, z. These x, y, z is a point in space. So how come a point is defined as vector? I mean you need at least 2 points to define a vector right? So where's the second point? What am I missing here? How is the funcion D3DXVec3Normalize works wiht having 1 point paramaters in space? Is the second point (0,0,0) ?? Thank you...
MCA
Advertisement
In 3D space, vectors are usually described as coordinates in the vector basis. That is:
(x,y,z) = x i + y j + z k


While points use the same notation, it's actually syntactic sugar: a point is said to have coordinates [x,y,z] when in fact it is the vector from the origin to that point that has coordinates (x,y,z).

Quote:Original post by dehseth
So how come a point is defined as vector? I mean you need at least 2 points to define a vector right? So where's the second point? What am I missing here?


The (x, y, z) is the vector's end point. It's start point is assumed to be the origin.

I know that to express a vector that has not got as start point the O point, you have just to make PointB-PointA.

But the new vector is not also a vector = (PointB-PointA) and O point?

I thought that all vector, in the end, are rapresented as a vector with O point as start point
When you take a new vector PointB - PointA, that gives you a new vector from the origin O, which has the same magnitude and direction as the line from points A to B. ie the line from the origin is parallel to the line A to B and has the same size.

Remember, vectors don't have a position, only magnitude and direction. All vectors can be thought of as originating from the origin O.
Don't confuse the mathematical definition of "vector" with D3DXVECTOR3.

Your understanding of the mathematical term "vector" is correct.

D3DXVECTOR3 is just a label for a C++ structure - that's all - it's just a name. It's a place to store 3 float values.

How you use those 3 values is what is important. If you want to store 3 values describing a point in space, that's fine. If you want to store 3 values you're going to use as a mathematical vector, that's fine, also.

The D3DXVECTOR3 structure could just as well have been named D3DXFloat3Structure and serve exactly the same purpose.

As a programmer, you have to know what you're storing in a D3DXVECTOR3 variable and choose and use the appropriate D3DXVec3 functions.

If you store a point position in the variable and call D3DXVec3Normalize(), you'll get bad results because that's a function that is to be used if you're using the variable as a normal vector (in the mathematical sense).

If you store a point position in the variable and call D3DXVec3TransformCoord(), that will give you predictable results because that's a function that is to be used if you're using the variable as a position in space.

EDIT: If you're familiar with the Standard Library and have used vector<structure> to store values, then you know that vector<> is an ordered array of values. It has nothing to do with "vectors in space." In the same sense, D3DXVECTOR3 is just an ordered array of 3 float values.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I already know all you advices.
Obiously all depends from HOW i'm using the structure, becouse it can be considered as a vector and as a point, ok it's fine.

Now, let's consider this case.
I've got 2 points, A(1,2,3) and B (5,6,4).

I want to make a D3DXVECTOR3 that describes the vector that it's passing in there 2 points.

Now i know (mabye THIS could be wrong) that we can found the vector that passes across this 2 point making B-A
So i will receive a C point (4,4,1) in a D3DXVECTOR3.

But, as i know and also the user said in previous post, all vectors consider their initial point as origin. So the C vector (that should be the vector that goes across points A and B) it's equal to the vector that goes across the origin and C, or not?

Something like this
Cacca fresca

If my reasoning it's wrong, so i apologize and i ask you:

Giving point A and point B, how to fill D3DXVECTOR3 to have got a vector that goes across the 2 points?

Thank you
Mmm, mabye it should go in Math and Theory section.
Quote:how to fill D3DXVECTOR3 to have got a vector that goes across the 2 points?

You can't.

With 3 values, you can describe a position OR you can describe a direction, but you can't do both.

It's similar to creating lighted vertices for a mesh. You have a position and a normal. It needs 2 D3DXVECTOR3s.

As you know, XVincentX, you can combine the information you need in a matrix if you want, using D3DXMatrixRotation ( or ..YawPitchRoll ) to specify the direction, and D3DXMatrixTranslation() to specify the position. Then multiply the rotation matrix by the translation matrix to specify the position and direction both.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Quote:
But, as i know and also the user said in previous post, all vectors consider their initial point as origin. So the C vector (that should be the vector that goes across points A and B) it's equal to the vector that goes across the origin and C, or not?


The mathematical vector represents a displacement. When mathematical vectors are used as points, that displacement is assumed to be from the origin, but that is not true in the general case. A pure mathematical vector does not consider the concept of 'origin' -- it only describes the magntitude and direction of a displacement, an offset.

In other words, in your picture, the two blue lines represent the same vector; the origin of those lines is irrelevant, only the direction and magnitude matter.

Given two 'points' (or vectors interpreted as points) A and B, the operation B - A produces a vector representing the displacement of B relative to A.
Quote:Original post by Buckeye
Quote:how to fill D3DXVECTOR3 to have got a vector that goes across the 2 points?

You can't.

With 3 values, you can describe a position OR you can describe a direction, but you can't do both.

It's similar to creating lighted vertices for a mesh. You have a position and a normal. It needs 2 D3DXVECTOR3s.

As you know, XVincentX, you can combine the information you need in a matrix if you want, using D3DXMatrixRotation ( or ..YawPitchRoll ) to specify the direction, and D3DXMatrixTranslation() to specify the position. Then multiply the rotation matrix by the translation matrix to specify the position and direction both.


So, from the vector (B-A) rapresent a direction of all vector flush to the one that passes in A and B points, it's right?

This topic is closed to new replies.

Advertisement