Scalar Multiplication

 < Day Day Up > 

I'm sure for many years you have been multiplying scalars by other scalars. Remember, a scalar quantity is just an ordinary number. Let's turn our attention to a scalar times a vector. If you think about a vector expressed in polar coordinates, all you have is a magnitude and a direction. When you multiply a scalar by that vector, all you're really doing is changing the magnitude by scaling it up or down. If the scalar value is a whole number, the magnitude gets larger. Likewise, if the scalar is a fraction less than 1, the magnitude gets smaller.

Scalar Multiplication in Polar Coordinates

graphics/04inl46.gif


for any scalar c and vector graphics/04inl47.gif .


Example 4.10: Scalar * Vector in Polar Coordinates

Calculate 5A if vector A = 3ft @ 22.

Solution

5A = 5(3ft @ 22) = 15ft @ 22

If you're trying to visualize the effect scalar multiplication has on a vector, take a look at Figure 4.17.

Figure 4.17. 2 * vector A.

graphics/04fig17.gif

Remember that vectors are often represented by arrows with a length that corresponds to the magnitude, and the way the vector is pointing indicates the direction. As you can see, vector 2A is twice as long as A, but it still points in the exact same direction.

If you're already set up to program a vector and it's in Cartesian coordinates, you can still perform scalar multiplication without converting back to polar coordinates. Simply multiply each component by the scalar value, and that will have the same effect.

Scalar Multiplication in Cartesian Coordinates

graphics/04equ27.gif


for any scalar c and vector graphics/04inl48.gif .


Example 4.11: Scalar * Vector in Cartesian Coordinates

Calculate A if vector graphics/04inl49.gif .

Solution

graphics/04equ28.gif


Quite often in programming, you'll hear the term normalization used. It's really just a fancy word for scaling the magnitude of a vector down to 1. Quite often, a vector is used to simply establish a direction. In fact, graphics/iee_01.gif and graphics/jee.gif are perfect examples of that. The graphics/iee_01.gif is really just a vector that's one unit long in the positive x direction. Likewise, the graphics/jee.gif is a vector with a magnitude of 1 in the positive y direction. In future sections, you'll see applications where a vector with length 1 is used to establish a direction.

Normalizing a vector in polar coordinates is very simple. Just change the magnitude to 1 and leave the direction the same. However, in the context of programming, the vector will most likely be in Cartesian coordinates before you need to normalize it. In this case you must first calculate the magnitude of the vector and then divide each component by the magnitude. Essentially, you are performing a scalar multiplication by 1 over the magnitude.

Normalizing a 2D Vector

graphics/04equ09.gif


for any vector A = [ a 1 a 2 ].


This process happens even more frequently in 3D.

Normalizing a 3D Vector

graphics/04equ10.gif


for any vector A = [ a 1 a 2 a 3 ].


NOTE

The symbol for a normalized vector is the cap. For example, when A has a magnitude of 1, it can be written as .


Example 4.12: Normalizing a Vector

Normalize vector A = [5 0 12].

Solution
  1. The first thing you need to find is the magnitude of A. (You might need to refer to the "Polar Coordinates Versus Cartesian Coordinates" section earlier in this chapter.)

    graphics/04equ11.gif


  2. Now that you know the magnitude, all that's left to do is divide each component by it:

    graphics/04equ12.gif


NOTE

To check yourself, you can always calculate graphics/04inl03.gif . It should always equal 1 if you normalized correctly.


As you can see, scalar multiplication has the effect of scaling a vector's magnitude up or down. The direction always stays the same; only the magnitude changes. Also, the process of normalization is a great example of a scalar times a vector. The next natural question to ask is, "How do I multiply two vectors?" This question is not answered quite as easily, but it is addressed in the next two sections.

Self-Assessment

1.

Does scalar multiplication affect a vector's magnitude or direction?

2.

Calculate (1/3)A if vector A = 12m/s @ 43.

3.

Calculate 6B if vector graphics/04inl50.gif .

4.

Normalize vector C = [24 10].

5.

Normalize vector D = [0 7 24].


 < Day Day Up > 


Beginning Math and Physics for Game Programmers
Beginning Math and Physics for Game Programmers
ISBN: 0735713901
EAN: 2147483647
Year: 2004
Pages: 143
Authors: Wendy Stahler

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net