Skip to main content
gamedev.net
🔒 Locked

Vector multiply?

Started by devronious Jul 3, 2007 at 7:54 PM 8 replies 800+ views
Original Post
devronious
devronious
When I multiply two vectors is it: (x1 * x2, y1 * y2, z1 * z2) or is it magnitude based?
Nathan Baum
Nathan Baum
Quote:
Original post by devronious
When I multiply two vectors is it:

(x1 * x2, y1 * y2, z1 * z2)

or is it magnitude based?

Vector multiplication is not defined, so there's no "correct" answer.

I generally have it be component-wise, as in your first option, to maintain consistency with addition and subtraction, which are always component-wise.

Sometimes it is defined to be the dot or cross products, although I prefer to be explicit and use names involving "dot" and "cross" for such functions.

I'm not sure how a "magnitude based" multiplication of two vectors would work.
devronious
devronious
LightBringer,

Thanks, I was more refering to applying an acceleration expressed as a vector3(xyz) to a velocity which is also a vector3(xyz). Is that what you were refering to? Sorry for the confusion.

Nathan,

Thanks,

I've came to the conclusion that I have to multiply components like in the first too. If I don't then it's not spacially correct as far is heading (Direction). ie: applying an acceleration along a different direction to that of the velocity. The acelleration should alter the velocity's direction based on it's own direction which nullifies trying to use non-directional magnitudes as the path way. Trying to fit a camel thru the eye of a needle, it wont be a camel when it comes out the other side will it?

-Devin
Alrecenk
Alrecenk
The most common vector multiplications are the dot product and the cross product though there are others. There is not an explicit definition of vector multiplication, but you can consider your vectors as matrices and multiply those using matrix multiplication which is defined. In fact the dot and cross products can be defined using matrix operations.

Given vectors U and V as column matrices U dot V = T(U) * V where T is the transpose.

Given Vectors U and V with components U1 U2 etc the cross product UxV can be defined as the determinant of the matrix
i  j  kU1 U2 U3V1 V2 V3

where i,j,k are the standard basis vectors for 3D vectors.
Alrecenk
Alrecenk
Unless I'm missing something, there shouldn't be any need for vector multiplication when adding acceleration to velocity.
Stani R
Stani R
Quote:
Original post by devronious
Thanks, I was more refering to applying an acceleration expressed as a vector3(xyz) to a velocity which is also a vector3(xyz). Is that what you were refering to? Sorry for the confusion.


That wasn't what I meant, but if that's what you want to do, then I'm not sure why you are multiplying to begin with. If you multiply velocity by acceleration, you'll end up with something really strange like square meters per cubic second (if you had worked with scalars). Acceleration is the derivative of velocity, so you'll want numerical integration techniques here, and not multiplication, right?
T1Oracle
T1Oracle
Vf = A * T + V0
Xf = V * T + 1/2 * A * T2 + X0

Does that clear it up for you?

[Edited by - T1Oracle on July 3, 2007 11:49:18 PM]
Programming since 1995.
Dirk Gregorius
Dirk Gregorius
Elementwise vector multiplication is only seldom defined (IIRC I came across it in some statistic books). Anyway it is useful sometimes. Think of a matrix vector multiplication. When the matrix is diagonal (think non-uniform scaling) you can save the matrix as a vector and the matrix vector multiplication boils down to an elementwise multiplication.

E.g. when applying a local impulse on a rigid body. The local inertia tensor is stored as a vector and the apply impulse simply becomes

dw_local = Vec3Mul( invI_local, L_local )

where in invI_lcoal (local inertia tensor) and L_local (angular impulse in body coordinates) are both vectors. These operation maps also nicely on SSE intrinsics so it is often an effective optimization, especially in your deep inner loops.
devronious
devronious
Thanks, wow there are some good answers here. Thanks for all the help.

I'm sorry for misleading you a bit. I said multiply but meant add. The multiply portion comes in with the time factor of the frame rate being rendered. I have to multiply the time factor against the velocity and acceleration to get the proper relational elapse of motion for each individual frame.

I've learned things from this since my math is a bit weak at best.

T1Oracle included T into the equation which I carelessly left out (my bad, sorry)

Vout = Vin + (t * a)
Pout = Pin + (t * Vout)

where Vout is the next velocity(expressed as a Vector3), a is the acceleration (expressed as a Vector3) and Pout is the next Vector position(expressed as a Vector3). And t is a scalar of time if I'm using that term correctly.

Thanks again, I got it to work I beleive. I like the impulse answer regarding rigid bodies cause it tends to be more phyics related then game math (which, I know, are mostly the same but losely at times).

-Devin

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.