Basic Coordinate Geometry

Our goal in this course is to understand the physics and, consequently, the underlying mathematics involved in describing the motion of objects. Ultimately, we will use these concepts to accurately model the movement of objects within a game world. Since motion is fundamentally a result of an object changing its position over time, we must first establish a precise and powerful way to describe an object's location. We begin this foundational process by introducing the coordinate system, a mathematical framework that assigns a unique address to every point in space. We will first master this system in two dimensions (2D), learning about points, distance, and the critical properties of lines and circles, which form the basis of flat-world geometry. Following this, we will extend these essential concepts into three dimensions (3D) to deal with distance, midpoints, and the geometry of planes and spheres, providing the spatial framework necessary for realistic game world modeling.

Points and Coordinate Systems in 2D

In mathematics, there are several coordinate systems available to describe the location of a point in two or three dimensions. For our purposes, the rectangular or Cartesian coordinate system will be the most appropriate. In two dimensions, we most often use the x-coordinate for the horizontal component of the location and the y coordinate for the vertical component of the location. The image below shows a standard 2-dimensional Cartesian coordinate system.

A picture of the Cartesian plane with the x-axis on the horizontal and the y-axis on the vertical. The quadrants are labeled. Quadrant 1 is where x>0 and y>0. Quadrant 2 is where x<0 and y>0. Quadrant 3 is where x<0 and y<0. Quadrant 4 is where x>0 and y<0. The point where the axes intersect is labeled x=0 and y=0 with the name labeled as the origin

In the plane, the x-axis runs left to right with larger values to the right, while the y-axis runs up and down with larger values above. Each point in the plane can be referred to by its x and y coordinate pair $(x,y)$. This is called the ordered pair. The point with ordered pair $(0,0)$ is called the origin.
It is worth mentioning that the coordinates on the computer screen have the positive y-direction pointing down and the origin in the upper left-hand corner. One can work in the standard coordinate system and simply convert to screen coordinates before outputting.

Distance in 2 Dimensions

Given two points in 2 dimensions, the distance between them is defined as follows

(1)
\begin{align} d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2} \end{align}

This formula can be easily derived from the theorem of Pythagoras.

Image shows a right triangle with the hypotenuse running from a point labeled x one y one to another point x two y two. The hypotenuse is labeled d for distance. The two legs are labeled a and b

First, notice that the distance between the two points is just the length of the hypotenuse of a right triangle.
Side a has a length of $x_2-x_1$
Side b has a length of $y_2-y_1$
So from Pythagoras we have that $d=\sqrt{a^2+b^2}=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$

Midpoint in 2 Dimensions

Given two points in 2 dimensions, the midpoint is defined as follows

(2)
\begin{align} m= \left( \frac{x_1+x_2}{2},\frac{y_1+y_2}{2} \right) \end{align}

Notice that the x coordinate of the midpoint is the average of the two x coordinates, and likewise with the y coordinate

Lines in 2 Dimensions

Slope

One key feature of a line is the degree to which it inclines or declines. This feature is called its slope. We define the slope of a line that passes through the points $(x_1,y_1)$ and $(x_2,y_2)$ as

Image shows a line with two points labeled. The first point has coordinates x one, y one, and the second point is labeled x two, y two
(3)
\begin{align} m=\frac{y_2-y_1}{x_2-x_1}\mbox{ }\frac{\mbox{Rise}}{\mbox{Run}} \end{align}

Exercise
Find the slope of the line that passes through the points (2,4) and (6,-1).


The slope of a line is an indicator of how quickly the line rises or falls. For a line that rises from left to right, the slope is positive. For a line that falls, the slope is negative. For a vertical line, the slope is undefined. For a horizontal line, the slope is zero. The image below illustrates this fact.
An image showing several lines of different slopes passing through the origin. The horizontal is labeled m equals zero. Lines going up to the right are labeled with increasing positive m as they become steeper. Lines going down to the right are labeled with decreasing negative m. A vertical line is labeled as m undefined

Parallel Lines

Two lines that are parallel rise or fall at the same rate; therefore, their slopes are equal, assuming they exist. In other words, if $m_1=m_2$, then the two lines are parallel. If both slopes are undefined, then both lines are vertical and are therefore parallel.

Perpendicular Lines

In the case of perpendicular lines, as one line rises, the other falls, and the faster one rises, the slower the other falls. Specifically, the slopes are related as opposite reciprocals, assuming they exist. That is to say, $m_1=-\frac{1}{m_2}$. For the case of a vertical and a horizontal line, one line has a slope of 0, while the other line has an undefined slope.

Point Slope Form

We can now use our definition of slope to create an equation of a line. Given a line with slope m that passes through the point $(x_1,y_1)$, every point $(x,y)$ on that line satisfies the equation

(4)
\begin{align} m=\frac{y-y_1}{x-x_1} \end{align}

Multiplying this equation on both sides by $x-x_1$ yeilds the following

(5)
\begin{equation} y-y_1=m(x-x_1) \end{equation}

This is the so-called point slope form of the equation of a line.

Exercise
Find the point-slope equation of the line that has slope $m=\frac{1}{2}$ and passes through the point $(2,-3)$.

Example
Find the point-slope equation on the line that passes through the points $(-1,3)$ and $(2,-6)$.

Slope Intercept Form

Now say we have a line with slope m and passing through the point $(0,b)$. This point lies on the y-axis since its x coordinate is zero. We call this point the y-intercept of the line. If we plug this information into the point-slope equation, we get

(6)
\begin{eqnarray} y-b&=&m(x-0)\\ y-b&=&mx\\ y&=&mx+b \end{eqnarray}

This equation is the so-called slope-intercept form of the equation of a line. It is a specific case of the point-slope form.

Standard Form

The one limitation of both of these forms is that they require the slope, but as we saw previously, vertical lines have an undefined slope. In fact, vertical lines consist of all points with a common x value; therefore, they have an equation of the form $x=a$. This is a special case of the more general standard form of the equation of a line, which is given by

(7)
\begin{equation} Ax+By=C \end{equation}

The equation of any line can be expressed in this form.

Example
Find the equation in standard form for the line with slope-intercept form of $y=3x+4$
Example
Find the equation in standard form for the line with point-slope form of $y-2=4(x+5)$

Example
Find the equation in standard form for the vertical line $x-4=8$

Circles

Standard Form

A circle can be defined as the set of points that are all a fixed distance r, radius, from a common center, $(x_0,y_0)$.

Image shows a circle with center labeled x zero y zero. An arbitrary point on the circle is labeled x y. A line segment running from the center to the arbitrary point is labeled r

We already know that in 2D distance is defined as $d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$. Since a circle is the set of points whose distance is r from the point $(x_0,y_0)$, the distance formula yields the formula

(8)
\begin{eqnarray} r=\sqrt{(x-x_0)^2+(y-y_0)^2}\\ r^2=(x-x_0)^2+(y-y_0)^2\\ \end{eqnarray}

This is the so-called standard form of the equation of a circle in 2D.

Exercise
Find the center and radius of the circle $x^2-4x+y^2+10y=7$

Points and Coordinate Systems in 3D

In 3 dimensions, the Cartesian coordinate system has three perpendicular axes. The original x and y axes from the xy-plane plus the z-axis that runs perpendicular to the xy-plane. In the right-handed coordinate system, the positive z-axis is pointing out of the screen, and in the left-handed coordinate system, the positive z-axis is pointing into the screen.

rightandleft.jpg

To determine handedness, you lay your hand flat on the x-axis with your fingers pointing in the positive x direction. Now curve your fingers in the direction of the positive y-axis. The direction your thumb is pointing will be the positive z direction.

In mathematics, it is somewhat standard to use a right-handed system with the positive z direction being up and the positive x direction being out.

Image shows a right-handed 3D coordinate system. The right-handed system shows the positive x-axis pointing right, the positive y-axis pointing up, and the positive z-axis pointing out.

Every point in 3-dimensional space can be uniquely defined by its ordered triple $(x,y,z)$.

Distance in 3 Dimensions

Our formula from 2 Dimensions can be extended to 3 dimensions by twice applying the theorem of Pythagoras.

(9)
\begin{align} d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2} \end{align}
Image shows two points in three dimensions connected by a line segment labelled d. The first point has coordinates x one y one z one and the second point has coordinates x two y two z two. A third point forms a right triangle by being located below point 2 but in the same z-plane as point 1. Its coordinates are then x two y two z one. The distance from point 3 to point 1 is labelled a and the distance between point 3 to point 2 is labelled b

Notice that the z component is the same for the endpoints of side a. Therefore, our 2-dimensional distance formula applies and

(10)
\begin{align} a=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2} \end{align}

Since only the z coordinate is different on the endpoints of side b, we know that

(11)
\begin{align} b=\sqrt{(z_2-z_1)^2} \end{align}

Now applying the theorem of Pythagoras, we get

(12)
\begin{align} d=\sqrt{a^2+b^2}=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2} \end{align}

Exercise
Find the distance between (1,3,-1) to (4,5,6)

Midpoint in 3 Dimensions

Given two points in 3 dimensions, the midpoint is defined as follows

(13)
\begin{align} m= \left( \frac{x_1+x_2}{2},\frac{y_1+y_2}{2},\frac{z_1+z_2}{2} \right) \end{align}

Again each coordinate is the average of the corresponding original two coordinates.

Exercise
Find the midpoint of the points (8,20,6) and (9,10,1)

Planes in 3 Dimensions

The analog to a line in 3D is a plane. So, whereas the line has the general form, $Ax+By=C$, the plane has the general form, $Ax+By+Cz=D$. So, for example, the equation $x+2y+3z=6$ will be represented graphically as a plane. Sketching curves and surfaces in 3D by hand requires some practice and a little artistic effort. For general surfaces, there are various slicing techniques that can help you build up the 3D picture. Due to the simple geometry of planes, the easiest approach is to compute the intercepts with the three major axes and then sketch the portion of the plane that lies in-between.

Example
Sketch $x+2y+3z=6$

Spheres

The 3D analog of a circle is a sphere. By definition it is the set of all points $(x,y)$ a fixed distance $r$, called the radius, from a center $(x_0,y_0,z_0$ Using the definition of distance in 3D we get the standard form of the equation of a sphere;

(14)
\begin{equation} r^2=(x-x_0)^2+(y-y_0)^2+(z-z_0)^2 \end{equation}

Example
Give the equation of the sphere with center $(2,0,-5)$ and radius 3.

Example
Find the center and radius of $x^2+y^2+z^2+4x-8y+12z=0$

Exercises

  1. Draw a right-handed 3D coordinate system with the positive x-axis pointing out.
  2. In Unreal Engine, the positive $z$-axis points up. You are configuring a custom camera space where the player looks down the positive $z$-axis. Draw a left-handed 3D coordinate system where the positive $x$-axis points to the left. Label all three axes ($x$, $y$, and $z$) clearly on your diagram.
  3. A 3D modeler creates a mesh in Blender, which uses a right-handed coordinate system with positive $z$ up. When importing this asset into a game engine using a right-handed coordinate system where the positive $x$-axis points out toward the screen and the positive $y$-axis points right, sketch the system and determine whether the positive $z$-axis points up or down.
  4. Find the distance and midpoint between the points (4, 11, –5)ft. and (–3, 7, 2)ft.
  5. Find the distance and midpoint between the points (-2, 1)mi. and (6, -20)mi.
  6. In a 3D multiplayer title, Character A is located at position $(2, 8, -3)m$ and Character B is located at $(-4, 2, 5)m$
    1. A dynamic local co-op camera tracks both players by remaining focused at their exact midpoint. Calculate the 3D world coordinates where the camera focus point should be placed
    2. The game's proximity voice chat allows players to hear each other only if they are within a distance of $12$m. Calculate the exact distance between the characters and determine if they can hear each other.
  7. In a 2D top-down action game, an automated defense turret is located at $(-3, 4)yd.$ and a player character is positioned at $(5, -11)yd.$.
    1. The turret has a targeting range of $18\text{ yds.}$. Calculate the distance between the turret and the player. Is the player within range of being targeted?
    2. When the turret is destroyed, a health power-up drops at the exact midpoint between the player and the turret. Find the 2D coordinates for the power-up spawn location.
  8. Write the equation of a line passing through the points (6, 3) and (2,–5) in standard form.
  9. Write the equation of a line passing through the point (4,–7) that is perpendicular to the line with equation $5x-3y=9$.
  10. In a 2D stealth game, an AI guard moves back and forth along a linear path connecting Waypoint $A(5, 2)m$ and Waypoint $B(1, -6)m$. Write the linear equation representing the guard's patrol path in standard form. ($Ax + By = C$)
  11. A reflective energy barrier in a 2D arcade shooter is oriented along the line $4x - 2y = 7$. A laser beam impacts the shield at point $(3, -5)$. To compute the deflection vector, the physics solver needs the equation of a line perpendicular to the shield passing through the impact point. Write this line's equation in slope-intercept form.
  12. On a right-handed coordinate system with the z-axis pointing down, sketch a graph of the plane with equation $2x+3y-z=4$.
  13. Write the equation of a circle with center (3, 8) and radius 7.
  14. In a tactical RPG, a wizard casts an Area-of-Effect (AoE) fireball spell centered at grid coordinate $(4, 6)$ft. with an effective radius of $5ft$ft.
    1. Write the standard form equation of the circle defining the spell's damage boundary.
    2. An enemy goblin is standing at position $(8, 9)$ft. Evaluate whether the goblin takes damage by determining if its location falls inside or outside the blast radius.
  15. Write the equation of a sphere where (5, 7, 3) and (–1, 5, 4) are endpoints of a diameter.
  16. A sphere has the equation $x^2+y^2+z^2-6y+5z=14$ .
    1. Find its center and radius.
    2. Write its equation in standard form.
  17. To optimize collision detection, a game engine often generates a bounding sphere around an enemy character model. The opposite extreme vertices of the 3D model's mesh are at $(6, 8, 2)$in. and $(-2, 4, 6)$in.
    1. Find the center point and radius of the bounding sphere assuming these extreme vertices form its diameter.
    2. Write the equation of this bounding sphere in standard form.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License