Sign in to follow this  

I confused with the two operator

This topic is 4376 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

vector v1 ,v2 ,v3 1. v3.x = v1.x * v2.x; v3.y = v1.y * v2.y; v3.z = v1.z * v2.z; 2. float f = v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; I think 2 is dot product. but what is 1?? has it mathematicly definition? Has it function in D3DX lib? I know there is D3DXVec3Dot for 2. where does 1 come to play?

Share this post


Link to post
Share on other sites
Yes, the second operator is the dot product.

The first is simply a component-wise multiplication, which doesn't have a meaning in geometric terms, but is usefull for other things. Vectors are often used to store more than gemetric vectors, for example, they might be used to store color components or texture coordinates. An example of how you might use the first opperator is this: Say you have a vector holding color values for Red, green and blue. Now say you want to eliminate the green component, halve the blue, and double the red, for whatever reason you might have to do such a thing. Then, you simply multiply the color vector by a vector (2.0f, 0.0f, 0.5f). Basically anwhere you would need to multiply vector components by seperate values it is usefull.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ravyne
Yes, the second operator is the dot product.

The first is simply a component-wise multiplication, which doesn't have a meaning in geometric terms, but is usefull for other things. Vectors are often used to store more than gemetric vectors, for example, they might be used to store color components or texture coordinates. An example of how you might use the first opperator is this: Say you have a vector holding color values for Red, green and blue. Now say you want to eliminate the green component, halve the blue, and double the red, for whatever reason you might have to do such a thing. Then, you simply multiply the color vector by a vector (2.0f, 0.0f, 0.5f). Basically anwhere you would need to multiply vector components by seperate values it is usefull.


thanks
are there existed functin to do ? like float v3 = componentMul(v1,v2)?

Share this post


Link to post
Share on other sites
There doesn't need to be one, because it holds no single definable mathematical reason for existence (unlike the dot product). What Ravyne is getting at is it's just a multiplication of whatever XYZ is in v1, by whatever XYZ is in v2. What they contain, and what the result is used for, is entirely up to the user/programmer.

For instance, scaling a vector by 2.


v1 = { 1, 1, 1 } <-- your source vector

v2 = { 2, 2, 2 } <-- what you want to scale it by

vout.x = v1.x * v2.x;
vout.y = v1.y * v2.y;
vout.z = v1.z * v2.z;

in this instance, it would be the same as just multiplying each component of v1 by a single scalar 's' (and it would be 2).

however, if you want to scale different components separately (like the RGB method he described), you see where three different values are useful.

they don't even HAVE to be vector components, they could be 'a', 'b', 'c', but using the same datatype allows them to be passed around without extra work.

Share this post


Link to post
Share on other sites
Mathematical this is just a spezial case of the Matrix-Multiplication.
If you have a matrix with entries only on the diagonal.

If X=(x1,x2,x3) is your source vector, mulitplying with

v1,0,0
0,v2,0 = M
0,0,v3

would result into
M*X=(v1*x1,v2*x2,v3*x3)

(Just my 2 Cents)
Nathan

Share this post


Link to post
Share on other sites
Quote:
Original post by LonelyStar
Mathematical this is just a spezial case of the Matrix-Multiplication.
If you have a matrix with entries only on the diagonal.

If X=(x1,x2,x3) is your source vector, mulitplying with

v1,0,0
0,v2,0 = M
0,0,v3

would result into
M*X=(v1*x1,v2*x2,v3*x3)

To complete LonelyStar's post: The mentioned matrix denotes a scaling. So you could say that the product of interest is a kind of efficient implementation of scaling a vector, but I think its application in this form is rare in practise, since it is most often concatenated into a full transformation matrix.

Share this post


Link to post
Share on other sites
component wise multiplications are also usefull for lighting equations. where basically the same thing needs to be applied to each component. for example I got a rgb light intensity vector and a rgb surface reflection vector.

pixelColor = (normal DOT direction)compMul(light,relection)

Share this post


Link to post
Share on other sites

This topic is 4376 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this