- Home /
What happens when you multiply two vectors?
Now that I know what happens when you generally multiply it with a number, what happens when you multiply a vector3 with another vector3?
Answer by Molix · May 07, 2010 at 01:00 AM
You can use Vector3.Scale to multiply two vectors, component by component, e.g.
var v1 : Vector3 = Vector3( 1, 2, 3 );
var v2 : Vector3 = Vector3( 4, 5, 6 );
var vScaled : Vector3 = Vector3.Scale( v1, v2 ); // = ( 4, 10, 18 )
in linear algebra component-wise multiplication is also called the Convolution of two vectors. Sometimes you'll see this as .Convolve(v1, v2).
Answer by Eric5h5 · May 07, 2010 at 12:51 AM
You get an error message.
Which is kind of disapointing, really. Why did the Unity $$anonymous$$m not implement the *
operator?
@ruudlenders, I know I'm a bit late at this, but the reason is that it is ambiguous. Based on stuff I'd seen in the past, I'd more expect a * operator on vectors to cross multiply them, which is entirely different.
The Scale function does what you expected the * operator to do.
Answer by Kiwasi · Dec 26, 2014 at 10:12 PM
Further detail since this has come to the top. There are two generally accepted ways to multiply Vector3. As the * would be ambiguous as to which call is being made Unity has implemented neither as default. You can still call static methods on Vector3 to use either.
One is called the dot product. It returns a scalar with a magnitude equivalent to the area of the parallagram between the two vectors. In practical terms the dot product of normalised vectors is equal to the cosine of the angle between them. This can produce really quick angle checks on normalised vectors.
The other is called the cross product. It returns a vector perpendicular to both vectors. Useful for obvious reasons. Particularly when working with planes and surfaces.
there is a third standard-ish interpretation of multiplying two vectors, which is Convolution, aka component-wise multiplication.
the convolution of 2D vectors A and B is [A.x * B.x, A.y * B.y]
.
in Unity, you obtain this by the Scale() class method of Vector. eg, Vector2 A_Convolve_B = Vector2.Scale(A, B)
.
why, yes. yes it is. you heard it here second, folks !
Your answer
Follow this Question
Related Questions
Is it possible to clamp a Vector magnitude upwards (i.e. clamp to minLength)? 2 Answers
CharacterController on Moving Surface 4 Answers
Creating Hint Vector 1 Answer
how do i calculate the angle to fire a bullet to intercect 1 Answer
Stuck trying to change the position of my Main Camera through scripting 1 Answer