Math Moments – Navigating in 3-D Space

We can navigate in 3-D to any point (xR, yR, zR), in Cartesian Coordinates, by starting at the origin (0, 0, 0) and in the 2-D, x-y plane, walking in the x-direction (1, 0, 0) a distance xR, then turning left 90 degrees and walking a distance yR in the y-direction (0, 1, 0), still on the x-y plane.  This is the same as we did in 2-D except we put an extra ‘0’ in the third ‘z’ direction.  At this point we are still on the x-y plane at the point (xR, yR, 0).  The z-direction is straight up, so we would now need a ladder to climb up or a shovel to dig down, it is helpful to pretend we can fly (or dig).  From this point (xR, yR, 0) on the x-y “ground” plane, we fly straight up in the z-direction (0, 0, 1) a distance zR, and we successfully arrive at the point (xR, yR, zR).

We can express this journey with vectors, as we did in 2-D, by connecting (adding) lines together to form the path:

   (xR, yR, zR) = (1, 0, 0)*xR + (0, 1, 0)*yR + (0, 0, 1)*zR
                        = (xR, 0, 0) + (0, yR, 0) + (0, 0, zR)
                        = (xR, yR, zR)

        And using dot product notation, this can be written:

   (xR, yR, zR) = (1, 0, 0)*xR + (0, 1, 0)*yR + (0, 0, 1)*zR
                        = [(1, 0, 0), (0, 1, 0), (0, 0, 1)].(xR, yR, zR)

The [(1, 0, 0), (0, 1, 0), (0, 0, 1)] matrix is called the identity matrix.

We could also arrive faster by flying along a straight line connecting the two. Fly along a direction (Dx, Dy, Dz), from the origin directly to this point, (xR, yR, zR) a distance “R” away:

   (xR, yR, zR) = (Dx, Dy, Dz)*R

        Where the distance ‘R’ is found by:

    R2 = xR2 + yR2 + zR2

From the equation above for this line, we can easily find the direction vector from the origin to any point (xR, yR, zR), similar to what we did in 2-D.

      (Dx, Dy, Dz) = (xR/R, yR/R, zR/R)

Recall that the direction vector always has a distance of 1 unit, as seen in the diagram above.  In the diagram, we have attempted to show a 3-D path on a 2-D piece of paper.  Note that in the diagram, Dr is the distance from the origin to the point (Dx, Dy, 0) in the x-y plane. From the Pythagorean theorem, we find that the length:

      Dr2 = Dx2 + Dy2    and
      Dr2 + Dz2 = 1        thus combining these
      Dx2 + Dy2 + Dz2 = 1.

The total length of the distance vector is 1 unit, as required.  Everything is consistent.  Now we use the definition of the ‘Sin’ and ‘Cos’ and can see, from the diagram above, that:

     Cos(Axy) = Dx/Dr
     Sin(Axy) = Dy/Dr

      Cos(Az) = Dr/1
      Sin(Az) = Dz/1

    Thus

       Dx = Cos(Axy)*Dr = Cos(Axy)*Cos(Az)
       Dy = Sin(Axy)*Dr = Sin(Axy)*Cos(Az)
       Dz = Sin(Az)

And so, if we stand at the origin facing in the x-direction, and rotate our “head” an angle Axy to the left, and then tilt our head an angle Az off the x-y plane to look directly at the point (xR, yR, zR), we can find the direction vector pointing to this point using these angles:

   (Dx, Dy, Dz) = (Cos(Axy)*Cos(Az), Sin(Axy)*Cos(Az), Sin(Az))

       And then draw the line to this point:

    (xR, yR, zR) = (Dx, Dy, Dz)*R

Now that we are staring at a point in the sky, with our nose pointed directly at the point, we can ask about “reference frame” of our head.  What direction is our left ear pointing, for example.  Our left ear is pointing in the direction, still in the x-y plane, that is 90 to the left of the Axy angle we rotated our head (-Dy/Dr, Dx/Dr, 0). We divide by Dr because in 3-D we must make the length of the direction vector equal to 1.  If this seems vague, look back and review how to find 90 degree directions in the 2-D plane in the top diagram taken from previous posts.

When we tilt our head, we can ask what is the direction that the top of our head points, 90 degrees up from the angle Az. It perhaps takes a bit more imagination to see this, since we are facing in the x-y plane (Dx/Dr, Dy/Dr, 0) and have tilted our head up to look at Dz, we find that the “shadow” of our head is pointed behind us, in the x-y plane (-Dx/Dr, -Dy/Dr, 0), then looking at the elevation Dr (when rotated 90 degrees) we find that (-Dx*Dz/Dr, -Dy*Dz/Dr, Dr) is the direction of the top of our head.  So, in the reference frame of our head:

     Direction of our Nose:     (Dx, Dy, Dz)
     Direction of Left ear:         (-Dy/Dr, Dx/Dr, 0)
     Direction of Top of head:  (-Dx*Dz/Dr, -Dy*Dz/Dr, Dr)

Let us verify that these direction vectors all have a length of 1.  The Nose direction we have verified.  For the Left ear direction:

    L.L = (-Dy/Dr)2 + (Dx/Dr)2 + 02 = (Dy2 + Dx2)/Dr2 = 1

For the Top of head direction:

    T.T = (-Dx*Dz/Dr)2 + (-Dy*Dz/Dr)2 + Dr2 = (Dy2 + Dx2)*Dz2/Dr2 + Dr2
                                                                    = Dz2 + Dr2 = 1

Now let’s find what happens when we find the dot product of these direction vectors, we will call them the N, L, and T directions respectively.

N.N = (Dx, Dy, Dz).(Dx, Dy, Dz) = Dx2 + Dy2 + Dz2 = 1

N.L = (Dx, Dy, Dz).(-Dy/Dr, Dx/Dr, 0) = -Dx*Dy/Dr + Dy*Dx/Dr + 0
                                                                  = 0

N.T = (Dx, Dy, Dz).(-Dx*Dz/Dr, -Dy*Dz/Dr, Dr)
        = -Dx2*Dz/Dr + -Dy2*Dz/Dr + Dz*Dr
        = -(Dx2 + Dy2)*Dz/Dr + Dz*Dr
        = -Dr2*Dz/Dr + Dz*Dr
        = 0

L.T = (-Dy/Dr, Dx/Dr, 0).( -Dx*Dz/Dr, -Dy*Dz/Dr, Dr)
       = Dy*Dx*Dz/Dr2 + -Dx*Dy*Dz/Dr2 + 0
       = 0

We also verified that L.L = 1 and T.T = 1 above.  So, in general, if we dot any of these N, L, T direction vectors with themselves, we get ‘1’, but if we dot any of them with each other, we get ‘0’.  It turns out that this is a requirement for any three perpendicular direction vectors in a 3-D Cartesian reference frame.  I find the “head” reference frame to be more natural because we can relate to it better, so I use this reference frame for whatever direction I am looking.  It is also a great reference frame for video games.

We have already seen from perpendicular 2-D paths how we can convert between a reference frame to our “ground” x-y-z reference frame.  To understand this, let’s take a journey: Fly in the Nose direction a distance SN, then fly in the Left ear direction a distance SL, and then in the Top of head direction a distance ST.  Then we will arrive at the point:

    (x, y, z) = N*SN + L*SL + T*ST

       or in dot product notation:

     (x, y, z) = [N, L, T].(SN, SL, ST)

This amazing equation lets you convert any point in your “head frame” of reference (SN, SL, ST), when your head is pointing in your Nose direction N:(Dx, Dy, Dz), to a point in the “ground” frame (x, y, z).  You might also want to do this the other way around.  Review how we did this in 2-D, by “dotting” each side by each of the direction vectors, we get:

    (SN, SL, ST) = [N, L, T].(x, y, z)

This is how video games convert a 3-D world, stored in “ground” (x, y, z) coordinates, into the perspective of the viewer’s head (SN, SL, ST) coordinates.  The details need to be worked out but using this equation we can map a 3-D world onto a 2-D screen in the viewer’s perspective, no matter the relative direction of the viewer’s head.  We will stop here, there is a lot to take in.

Standard

Leave a comment