3 Ascending to the 3D world

 

This chapter covers

  • Building a mental model for 3D vectors
  • Doing 3D vector arithmetic
  • Using the dot product and cross product to measure lengths and directions
  • Rendering a 3D object in 2D

The 2D world is easy to visualize, but the real world has three dimensions. Whether we are using software to design a building, animate a movie, or run an action game, our programs need to be aware of the three spatial dimensions in which we live.

In a 2D space, like a page of this book, we have a vertical and a horizontal direction. Adding a third dimension, we could also talk about points outside of the page or arrows perpendicular to the page. But even when programs simulate three dimensions, most computer displays are two-dimensional. Our mission in this chapter is to build the tools we need to take 3D objects measured by 3D vectors and convert them to 2D so our objects can show up on the screen.

A sphere is one example of a 3D shape. A successfully drawn 3D sphere could look like the one shown in figure 3.1. Without the shading, it would just look like a circle.

Figure 3.1 Shading on a 2D circle makes it look like a 3D sphere.

3.1 Picturing vectors in 3D space

3.1.1 Representing 3D vectors with coordinates

3.1.2 3D drawing with Python

3.1.3 Exercises

3.2 Vector arithmetic in 3D

3.2.1 Adding 3D vectors

3.2.2 Scalar multiplication in 3D

3.2.3 Subtracting 3D vectors

3.2.4 Computing lengths and distances

3.2.5 Computing angles and directions

3.2.6 Exercises

3.3 The dot product: Measuring vector alignment

3.3.1 Picturing the dot product

3.3.5 Exercises

sitemap