Chapter 3 Multiple Coordinate Spaces
3.5 Coordinate Space Transformations
Suppose that in our virtual world a robot is attempting to pick up a herring sandwich. We know the position of the sandwich and the position of the robot in world coordinates. To pick up the sand- wich, the robot must be able to answer some basic questions in its own coordinate space, such as, “Which way should I turn to face the sandwich?” “How far away is the sandwich?” “Which way do I move my herring sandwich scoop to get in position to pick up the sandwich?”
Suppose that we wish to render an image of the robot picking up the sandwich, and the scene is illuminated by a light mounted in the center of the robot’s chest. We know the position of the light within the robot’s object space, but in order to properly light the scene, we must know the position of the light in world space.
These two problems are different aspects of the same basic problem — we know how to express a point in one coordinate space, and we need to express that point in some other coordinate space. The technical term for this computation is acoordinate space transformation. We need to transformthe position from world space to object space (in the example of the sandwich) or from
object space to world space (in the example of the light). Notice that neither the sandwich nor the light reallymove.We are just expressing their locations in a different coordinate space.
In Section 3.2.4, we learned that we can transform between object and world space by using inertial space as an intermediary. We can transform between object space and inertial space by rotation, and we can transform between inertial space and world space by translation.
Suppose we are attempting to transform the center point of the light from the robot’s object space into world space. We know where the light is located in the robot’s object space — the large rectangle at the center of its chest. We can see in Figure 3.6 that it is located on the object’sy-axis in the positive direction, so itsxcoordinate is 0. To be specific, let’s say the light is at location (0,100) in object space. Instead of thinking about how to transform the point from object space into world space, however, we are going to think about how to transform object axes into world axes. This will in fact give us a general transformation that we can apply to any point, not just the light.
We first rotate to transform the object space axes into inertial axes. We can visualize the transfor- mation by imagining the object coordinate space rotating to line up the object axes with the inertial axes. If we rotate the object space axes in Figure 3.6 clockwise 45°, we get the inertial space axes in Figure 3.7. Note that on the axes of inertial space, the light is now in the positiveydirection and the negativex direction, so the location of the light in inertial space would be something like (–300,600).
32
Chapter 3: Multiple Coordinate SpacesSecond, we translate to transform the axes from inertial to world space. We can visualize the trans- formation by imagining the origin moving from the origin of the inertial coordinate space in Figure 3.7 down and to the left to line up with the world origin. Notice that the light is now in the positive direction on both of the world axes, and so it is at (1200,1000) in world space.
To summarize the example, in order to transform the axes from inertial space to world space: 1. The object axes are transformed to inertial axes by rotating them clockwise 45°.
2. The inertial axes are transformed to world axes by moving them down and to the left. 3. Therefore, the object axes are transformed to world axes by rotating them clockwise 45°and
then moving them down and to the left.
From the perspective of a point on the object, like the light in the large rectangle on the robot’s chest, the opposite happens:
1. The point is transformed from (0,100) in the object space to (–300,600) in inertial space by rotating itcounterclockwise45°.
2. The point is transformed from (–300,600) in inertial space to (1200,1000) in world space by movingup and right.
3. Therefore, a point is transformed from object space to world space by rotating it counterclockwise45°and then moving itup and right.
Figure 3.8: The robot in world space Figure 3.7: The robot in inertial space
Why are the rotation and translation for a point in the opposite direction than they were for the axes? It’s like driving around in a car. For example, if you move forward, the world seems to move backward. If you turn left, the world appears to move right. The world does the opposite of what you do.
The beauty of this method is that by first thinking about what happens to the axes, we come up with a transformation that can be applied to any point. We’ll talk about this more in Section 8.1.
3.6 Exercises
1. Draw a nested space hierarchy tree for the sheep described in Section 3.3, assuming that its head, ears, upper legs, lower legs, and body move independently.
2. Suppose our object axes are transformed to world axes by rotating them counterclockwise around they-axis by 42°and then translating six units along thez-axis and 12 units along the x-axis. Describe this transformation from the perspective of a point on the object.
3. Which coordinate space is the most appropriate in which to ask the following questions? (Object, inertial, camera, or world)
a. Is my computer in front of me or behind me? b. Is the book east or west of me?
c. How do I get from one room to another? d. Can I see my computer?
Vectors
Vectors are the formal mathematical entities we use to do 2D and 3D math. The wordvectorhas two distinct, but related, meanings. One meaning is primarily abstract and mathematical, while the other meaning is geometric. Many books will focus on one interpretation or the other. However, in order to be proficient with 3D math, we will need to understand both interpretations of vectors and how the two interpretations are related.
35
This chapter introduces the concept of vectors. It is divided into three main sections.
n Section 4.1 covers some of the basic mathematical properties of vectors. The main concepts are:
u Vector
u Scalar
u Vector dimension
u Row vs. column vectors
n Section 4.2 discusses how vectors may be interpreted geometrically. The main con- cepts are:
u How to draw a vector
u Position and displacement
u How to express a vector as an array of numbers
u How to express a vector as a series of displacements
n Section 4.3 discusses the often confusing relationship between points and vectors. The main concepts are:
u Relative position
4.1 Vector — A Mathematical Definition
To mathematicians, avectoris a list of numbers. Programmers will recognize the synonymous termarray. Mathematically, a vector is simply anarrayof numbers. If this abstract definition of a vector doesn’t inspire you, don’t worry. Like many mathematical subjects, we must first introduce some terminology and notation before we can get to the “fun stuff.”
4.1.1 Vectors vs. Scalars
Mathematicians distinguish between vector andscalar(pronounced SKAY-lur) quantities.Scalar is the technical term for an ordinary number. We use this term specifically when we wish to emphasize that a particular quantity is nota vector quantity. For example, as we will discuss shortly, “velocity” and “displacement” are vector quantities, while “speed” and “distance” are scalar quantities.
4.1.2 Vector Dimension
Thedimensionof a vector tells how many numbers the vector contains. Vectors may be of any positive dimension, including one. In fact, a scalar can be considered a 1D vector. In this book, we will primarily be interested in 2D, 3D, and (later) 4D vectors.
4.1.3 Notation
When writing a vector, mathematicians surround the list of numbers with square brackets. For example: [1, 2, 3]. When we write a vector inline in a paragraph, we usually put commas between the numbers. When we write it out in an equation, the commas are often omitted. In either case, a vector written horizontally is called arowvector. Vectors are also frequently written vertically:
A vector written vertically is acolumnvector. In this book, we will use both notations. For now, the distinction between row and column vectors won’t matter. However, in Section 7.1.8 we will discuss why, in certain circumstances, the distinction is critical.
When we wish to refer to the individual components in a vector, we use subscript notation. In math literature, integer indices are used to access the elements. For example,v1refers to the first
element inv. However, since we are specifically interested in 2D, 3D, and 4D vectors, rather than vectors of arbitrary dimensionn, we will rarely use this notation. Instead, we will usexandyto refer to the elements in a 2D vector,x,y, andzto refer to elements in a 3D vector, andx,y,z, andw to refer to elements in a 4D vector. Equation 4.1 illustrates both notations: