Module 2 ended with a promise: we already know how to move objects around the scene, but we do not yet know how to measure it. Before computing distances, angles or intersections we need to take a calm look at the stage where everything happens: the coordinate system. So far we have used it while taking it for granted ("right-handed, Y up"); in this lesson we study it properly. We will see which arbitrary decisions it hides, why every engine and every tool makes different ones and how to translate between them, how the coordinate planes divide space, how the distance between two points is measured and what other ways there are of giving a position—cylindrical and spherical coordinates—which turn out to be far more convenient for describing the ship's orbit around the lighthouse or an orbit camera.
The Cartesian coordinate system in 3D
A Cartesian coordinate system in space consists of:
- An origin \(O\), the reference point. In "Stellar Lighthouse" it is the base of the lighthouse.
- Three axes through the origin, pairwise perpendicular: X, Y and Z.
- A unit of length common to the three axes (in our scene, 1 unit = 1 meter).
With those three ingredients, every point in space is identified by an ordered triple \((x, y, z)\): how far you have to travel along each axis to get from the origin to the point. The correspondence is exact in both directions: each point has exactly one triple and each triple, exactly one point.
The ship is at \((8, 3, 6)\). Read as a recipe: from the base of the lighthouse, 8 m along X, 3 m upward along Y and 6 m along Z. Order matters: \((8, 3, 6)\) and \((6, 3, 8)\) are different points.
In the language of Module 1, a coordinate system is an origin plus a basis: the triple \((8, 3, 6)\) holds the coordinates, in the standard basis, of the vector that goes from the origin to the ship. And in the language of Module 2, the ship's model matrix defines another coordinate system (the ship's local one), with a different origin and different axes. Everything we say here holds for any of them.
Right hand, left hand and the "up axis"
When drawing the three axes, two decisions have to be made that mathematics does not impose. They are pure conventions, which is why every program has picked its own.
First decision: the orientation (the "handedness")
Place the X axis pointing to the right and the Y axis pointing up. The Z axis, perpendicular to both, can still point in two directions: toward you or into the screen. Those two possibilities give two families of systems that cannot be superimposed by rotating them, just like your two hands:
- Right-handed. With your right hand, the thumb is X, the index finger is Y and the middle finger is Z. With X to the right and Y up, Z comes out of the screen toward you.
- Left-handed. The same with your left hand. With X to the right and Y up, Z goes into the screen.
A numerical test: build the matrix whose columns are the directions of the three axes of one system, expressed in the other. As we saw in "Matrices and Determinants", the sign of the determinant indicates the orientation: if it is \(+1\), the two systems have the same handedness; if it is \(-1\), opposite handedness.
Second decision: which axis points up
Engines that grew out of on-screen graphics tend to use Y up (X and Y are the screen axes and Z is depth). Tools that come from design and architecture tend to use Z up (X and Y are the ground plane, as on a map, and Z is height).
Who uses what
| Engine or tool | Handedness | "Up" axis | Usual "forward" axis | Usual unit |
|---|---|---|---|---|
| OpenGL (classic convention) | Right | +Y | −Z | Free |
mini3d (this course) |
Right | +Y | −Z | 1 m |
| DirectX (classic convention) | Left | +Y | +Z | Free |
| Unity | Left | +Y | +Z | 1 m |
| Unreal Engine | Left | +Z | +X | 1 cm |
| Blender | Right | +Z | −Y | 1 m |
Two caveats: OpenGL and DirectX are graphics libraries, and the handedness shown in the table is the traditional one of their examples and utilities, not a technical requirement. And the "forward" axis depends on the object: in mini3d the camera looks toward −Z, whereas the ship has its longitudinal axis along its local +Z.
The practical consequence is immediate: a model exported from one tool and imported into another without conversion shows up lying on its side, mirrored or a hundred times too big. It is not a fault in the model: the coordinates were written in one "language" and read in another.
Converting between conventions
Going from one convention to another is a change of coordinate system, exactly what we studied in the last lesson of Module 2. Since the origins coincide and the axes are only permuted or flipped, a 3×3 matrix containing nothing but zeros, ones and minus ones is enough.
The recipe is the column method: column \(j\) of the conversion matrix is axis \(j\) of the source system, written in the target system.
From Blender to mini3d
In Blender, X points to the right, Z up and Y into the screen. Let's see where each axis goes:
- Blender's X (right) is our X: \((1, 0, 0)\).
- Blender's Y (into the screen) is our −Z, because our Z comes out toward the viewer: \((0, 0, -1)\).
- Blender's Z (up) is our Y: \((0, 1, 0)\).
\[ C_{\text{Blender}} = \begin{pmatrix} 1 & 0 & 0 \ 0 & 0 & 1 \ 0 & -1 & 0 \end{pmatrix} \qquad \begin{pmatrix} x \ y \ z \end{pmatrix}_{\text{mini3d}} = \begin{pmatrix} x_b \ z_b \ -y_b \end{pmatrix} \]
Its determinant is \(+1\): both conventions are right-handed and the conversion is a rotation (of −90° about X, the matrix \(R_x(-90°)\) from Module 2).
From Unity to mini3d
Unity also has X to the right and Y up, but it is left-handed: its Z goes into the screen. Only the sign of Z has to change:
\[ C_{\text{Unity}} = \begin{pmatrix} 1 & 0 & 0 \ 0 & 1 & 0 \ 0 & 0 & -1 \end{pmatrix} \]
Its determinant is \(-1\): it is a reflection, the sign that we are switching handedness.
From Unreal to mini3d
In Unreal, X is forward, Y is right and Z is up, in centimeters. Forward is our −Z, right is our X and up is our Y. On top of that we have to divide by 100:
\[ C_{\text{Unreal}} = \frac{1}{100}\begin{pmatrix} 0 & 1 & 0 \ 0 & 0 & 1 \ -1 & 0 & 0 \end{pmatrix} \]
Without the scale factor, the determinant is \(-1\): another change of handedness.
import numpy as np
blender_to_mini3d = np.array([[1.0, 0.0, 0.0],
[0.0, 0.0, 1.0],
[0.0, -1.0, 0.0]])
unity_to_mini3d = np.diag([1.0, 1.0, -1.0])
unreal_to_mini3d = 0.01 * np.array([[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
[-1.0, 0.0, 0.0]])
# The same ship position, as each program would give it
print(blender_to_mini3d @ np.array([8.0, -6.0, 3.0]))
print(unity_to_mini3d @ np.array([8.0, 3.0, -6.0]))
print(unreal_to_mini3d @ np.array([-600.0, 800.0, 300.0]))
print(round(np.linalg.det(blender_to_mini3d)), round(np.linalg.det(unity_to_mini3d)))Three different triples describe the same point. For the way back we use the inverse, which—these being orthogonal matrices when there is no scale—is the transpose.
Two warnings about conversions with a negative determinant:
- Transformations have to be converted too. If you have a matrix \(M\) (a rotation, for example) expressed in the other convention, converting the points is not enough: the equivalent matrix in ours is \(C,M,C^{-1}\), the change-of-basis formula from the previous lesson.
- A change of handedness reverses the direction of rotations and the order in which the vertices of triangles are traversed. We will come back to this when we discuss the cross product and, in Module 5, the faces of a mesh.
Coordinate planes and planes parallel to them
Each pair of axes determines a coordinate plane. There are three, and each is described by a very simple condition: the coordinate that does not appear in its name is zero.
| Plane | Axes it contains | Condition | In the scene (Y up) |
|---|---|---|---|
| XZ | X and Z | \(y = 0\) | The "ground": the horizontal plane through the base of the lighthouse |
| XY | X and Y | \(z = 0\) | Vertical plane parallel to the screen in the initial view |
| YZ | Y and Z | \(x = 0\) | Vertical plane containing the lighthouse tower and the camera |
Notice the logic: in the XZ plane, the coordinates \(x\) and \(z\) are free (they can take any value) and the coordinate \(y\) is fixed. Two free coordinates give an object of dimension 2: a plane. The "top-down view" we used in Module 1 was nothing other than looking at the XZ plane from above, forgetting about height.
If the fixed coordinate equals some other constant, we get a plane parallel to the coordinate plane:
- \(y = 3\): the horizontal plane 3 m up. The ship \((8, 3, 6)\) flies in it; the camera \((0, 5, 20)\) is 2 m above it.
- \(y = 12\): the horizontal plane at the height of the lighthouse lamp.
- \(x = 8\): a vertical plane, parallel to YZ, that passes through the ship.
So giving a point \((8, 3, 6)\) amounts to saying that it is the only point common to the three planes \(x = 8\), \(y = 3\) and \(z = 6\).
The axes are described in the same way, by fixing two coordinates: the Y axis is the set of points with \(x = 0\) and \(z = 0\), that is, the intersection of the YZ and XY planes. The lighthouse tower, from \((0, 0, 0)\) to \((0, 12, 0)\), is a piece of the Y axis.
The eight octants
In the plane, the two axes divide space into four quadrants. In 3D, the three coordinate planes divide it into eight regions, the octants, one for each combination of signs of \((x, y, z)\): \(2 \cdot 2 \cdot 2 = 8\).
The first octant is the one with all three coordinates positive, \((+, +, +)\). There is no universal numbering for the other seven, so the safest option is to name them by their signs.
| Object | Coordinates | Signs | Where it is |
|---|---|---|---|
| Ship | \((8, 3, 6)\) | \((+, +, +)\) | First octant |
| Main nozzle | \((6.4, 2, 4.8)\) | \((+, +, +)\) | First octant |
| Stray asteroid | \((-6, 2, 10)\) | \((-, +, +)\) | On the other side of the YZ plane |
| Ship as seen from the camera | \((8, -2, -14)\) | \((+, -, -)\) | Below and in front, in the camera's system |
| Camera | \((0, 5, 20)\) | \((0, +, +)\) | On the YZ plane: in no octant |
Points with a zero coordinate lie on the boundary and belong to no octant. The fourth row is a reminder that the octant depends on the system: the ship is in the first octant of the world and in a different one of the camera's system.
Signs are a cheap way of classifying space. Knowing that two objects are in opposite octants lets us rule out many checks without a single multiplication; structures such as octrees are based on repeating this division into eight recursively.
Distance between two points and midpoint
Pythagoras, twice
How far is the ship \((8, 3, 6)\) from the base of the lighthouse \((0, 0, 0)\)? We solve it by applying the Pythagorean theorem twice:
- On the ground. The ship's "shadow" on the XZ plane is \((8, 0, 6)\). Its distance from the origin is the hypotenuse of a triangle with legs 8 and 6: \(\sqrt{8^2 + 6^2} = \sqrt{100} = 10\).
- Vertically. That 10 m line on the ground and the height of 3 m are the legs of a second right triangle, whose hypotenuse is the distance we are after: \(\sqrt{10^2 + 3^2} = \sqrt{109} \approx 10.44\).
Putting the two steps together, the inner root disappears: \(\sqrt{8^2 + 6^2 + 3^2}\). For any two points \(A = (x_1, y_1, z_1)\) and \(B = (x_2, y_2, z_2)\), what counts are the differences of coordinates:
\[ d(A, B) = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2} \]
Example. Distance from the ship to the camera \((0, 5, 20)\): the differences are \((-8, 2, 14)\), so \(d = \sqrt{64 + 4 + 196} = \sqrt{264} \approx 16.25\) m.
Since the differences are squared, it makes no difference which way round we subtract: \(d(A, B) = d(B, A)\). And the distance is 0 only when the two points coincide.
Midpoint
The midpoint of a segment is obtained by averaging the coordinates, one by one:
\[ M = \left( \frac{x_1 + x_2}{2},\ \frac{y_1 + y_2}{2},\ \frac{z_1 + z_2}{2} \right) \]
It is the case \(t = 0.5\) of the linear interpolation we saw in "Vectors and Vector Spaces". The midpoint between the ship and the camera is \(\left(\frac{8+0}{2}, \frac{3+5}{2}, \frac{6+20}{2}\right) = (4, 4, 13)\); a good spot, for example, to place a floating label between the two.
def midpoint(a, b):
return (np.asarray(a, dtype=float) + np.asarray(b, dtype=float)) / 2.0
ship = np.array([8.0, 3.0, 6.0])
lighthouse = np.array([0.0, 0.0, 0.0])
camera = np.array([0.0, 5.0, 20.0])
print(round(float(np.sqrt(np.sum((ship - lighthouse) ** 2))), 4))
print(round(float(np.sqrt(np.sum((camera - ship) ** 2))), 4))
print(midpoint(ship, camera))In the next lesson we will turn this calculation into the function distance, built on the concept of the norm of a vector.
Cylindrical coordinates
The ship orbits the lighthouse. In Cartesian coordinates, its position along the orbit is awkward: \(x\) and \(z\) change at the same time in a far from obvious way. But a clue has just turned up in the distance calculation: the ship's shadow is 10 m from the axis of the tower. During a circular orbit, that number does not change; the only thing that changes is which way the ship lies as seen from the tower. That is the idea behind cylindrical coordinates: replace \(x\) and \(z\) with a radius and an angle, and keep the height.
- Radius \(\rho\): distance from the vertical axis (the Y axis). Always \(\rho \ge 0\).
- Azimuth \(\varphi\): angle of rotation about the Y axis, measured in the ground plane from +Z toward +X.
- Height \(y\): the same Cartesian coordinate.
The name comes from the fact that the points with constant \(\rho\) form a cylinder around the axis.
The origin and the direction of the azimuth are, once again, a convention. We choose "from +Z toward +X" because that way the azimuth coincides with the angle of the rotation \(R_y\) from Module 2: the point with azimuth \(\varphi\) is the result of applying \(R_y(\varphi)\) to the point \((0, y, \rho)\).
From cylindrical to Cartesian:
\[ x = \rho \sin\varphi \qquad y = y \qquad z = \rho \cos\varphi \]
From Cartesian to cylindrical:
\[ \rho = \sqrt{x^2 + z^2} \qquad \varphi = \operatorname{atan2}(x, z) \qquad y = y \]
The function atan2(x, z) returns the angle whose sine is proportional to \(x\) and whose cosine is proportional to \(z\), taking the signs of both into account to get the quadrant right. A plain arctangent of \(x/z\) would confuse opposite points and would fail when \(z = 0\).
Example. For the ship \((8, 3, 6)\): \(\rho = \sqrt{64 + 36} = 10\), \(\varphi = \operatorname{atan2}(8, 6) \approx 53.13°\), \(y = 3\). It is no coincidence that the 53.13° angle of the orientation matrix \(N = R_y(53.13°)\) reappears: the ship's longitudinal axis, \(n_3 = (0.8, 0, 0.6)\), points exactly in the direction that goes from the tower to the ship.
With these coordinates, the orbit is trivial: \(\rho = 10\) and \(y = 3\) fixed, and the azimuth growing with time.
def cartesian_to_cylindrical(p):
"""Returns (radius, azimuth, height); azimuth in radians from +Z toward +X."""
x, y, z = p
return float(np.hypot(x, z)), float(np.arctan2(x, z)), float(y)
def cylindrical_to_cartesian(radius, azimuth, height):
return np.array([radius * np.sin(azimuth), height, radius * np.cos(azimuth)])
radius, azimuth, height = cartesian_to_cylindrical(ship)
print(radius, round(np.degrees(azimuth), 2), height)
# Four positions on the ship's orbit, every 90 degrees
for degrees in [0, 90, 180, 270]:
print(degrees, np.round(cylindrical_to_cartesian(10.0, np.radians(degrees), 3.0), 3) + 0.0)(The trailing + 0.0 only stops NumPy from displaying a -0. caused by rounding.)
Spherical coordinates
For a camera that orbits a target, the natural thing is to fix the distance to the target and control two angles with the mouse: one to go around and another to go up or down. Those are spherical coordinates:
- Radius \(r\): distance from the origin. Always \(r \ge 0\).
- Azimuth \(\varphi\): the same angle as in cylindrical coordinates, about the Y axis, from +Z toward +X.
- Elevation \(\varepsilon\): angle above (positive) or below (negative) the horizontal plane, between −90° and +90°.
They work like geographic longitude and latitude: the azimuth is the longitude and the elevation, the latitude. The points with constant \(r\) form a sphere.
To derive the formulas, all we need is the vertical right triangle from the section on distance: the hypotenuse is \(r\), the vertical leg is the height \(y = r \sin\varepsilon\) and the horizontal leg is the cylindrical radius \(\rho = r \cos\varepsilon\). Substituting that \(\rho\) into the cylindrical formulas:
From spherical to Cartesian:
\[ x = r \cos\varepsilon \sin\varphi \qquad y = r \sin\varepsilon \qquad z = r \cos\varepsilon \cos\varphi \]
From Cartesian to spherical:
\[ r = \sqrt{x^2 + y^2 + z^2} \qquad \varphi = \operatorname{atan2}(x, z) \qquad \varepsilon = \arcsin!\left(\frac{y}{r}\right) \]
Example. For the ship: \(r = \sqrt{109} \approx 10.44\), \(\varphi \approx 53.13°\) and \(\varepsilon = \arcsin(3 / 10.44) \approx 16.70°\). From the base of the lighthouse, the ship is seen 10.44 m away, turning 53.13° from the Z axis and looking up 16.70°.
| Cartesian | Cylindrical | Spherical | |
|---|---|---|---|
| Data | \((x, y, z)\) | \((\rho, \varphi, y)\) | \((r, \varphi, \varepsilon)\) |
| Ship | \((8, 3, 6)\) | \((10,\ 53.13°,\ 3)\) | \((10.44,\ 53.13°,\ 16.70°)\) |
| Camera | \((0, 5, 20)\) | \((20,\ 0°,\ 5)\) | \((20.62,\ 0°,\ 14.04°)\) |
| Ideal for | Adding, transforming with matrices | Orbits, helices, towers | Orbit cameras, radars, directions |
Many physics books use, instead of the elevation, the polar angle measured from the vertical axis (90° − \(\varepsilon\)), and with Z up as well. If you copy a formula from another source, check its convention first.
An orbit camera around the ship
Spherical coordinates measure from the origin, but an orbit camera revolves around its target. The solution is to convert the offset to Cartesian coordinates and add it to the target's position: a translation.
def cartesian_to_spherical(p):
"""Returns (radius, azimuth, elevation), with the angles in radians."""
x, y, z = p
radius = float(np.sqrt(x * x + y * y + z * z))
if radius == 0.0:
return 0.0, 0.0, 0.0 # at the origin the angles are undefined
return radius, float(np.arctan2(x, z)), float(np.arcsin(y / radius))
def spherical_to_cartesian(radius, azimuth, elevation):
horizontal = radius * np.cos(elevation)
return np.array([horizontal * np.sin(azimuth),
radius * np.sin(elevation),
horizontal * np.cos(azimuth)])
radius, azimuth, elevation = cartesian_to_spherical(ship)
print(round(radius, 4), round(np.degrees(azimuth), 2), round(np.degrees(elevation), 2))
print(spherical_to_cartesian(radius, azimuth, elevation))
# Orbit camera: 15 m from the ship, azimuth 30 degrees, elevation 20 degrees
camera_offset = spherical_to_cartesian(15.0, np.radians(30.0), np.radians(20.0))
print(np.round(ship + camera_offset, 3))Moving the mouse horizontally changes the azimuth; vertically, the elevation; the wheel, the radius. The camera moves on a sphere centered on the ship without anyone having to think about \(x\), \(y\), \(z\).
Trouble spots
Both systems have points where some angle is no longer defined:
- On the Y axis (\(\rho = 0\)), the azimuth is arbitrary: the lighthouse tower is not "toward" any side of itself.
- At the poles of spherical coordinates (\(\varepsilon = \pm 90°\)) the same thing happens, which is why orbit cameras usually clamp the elevation to something like ±89°.
Nor does it make sense to operate directly on these coordinates: they cannot be added or multiplied by matrices the way Cartesian coordinates can. The working pattern is always the same: think and control in cylindrical or spherical coordinates, convert to Cartesian and do the arithmetic there.
A first look at the equation of a plane
We have described the coordinate planes and their parallels with conditions such as \(y = 3\). That condition is an equation in which \(x\) and \(z\) just happen not to appear. Written out in full:
\[ 0 \cdot x + 1 \cdot y + 0 \cdot z - 3 = 0 \]
What happens if we allow the other coefficients to be nonzero? Recall the ship's route in the top-down view from Module 1: \(x + z = 14\). In 3D, that equation says nothing about \(y\), which stays free: it describes a vertical wall raised on that line on the ground. The ship is in it (\(8 + 6 = 14\)), whatever height it flies at.
And if all three coordinates appear, the plane is tilted. In general:
\[ A x + B y + C z + D = 0 \]
is the general equation of a plane (provided \(A\), \(B\) and \(C\) are not all zero). The coordinate planes are its simplest cases. For example, \(x + 2y + 2z - 17 = 0\) is a tilted plane that passes through the points \((13, 0, 2)\), \((9, 4, 0)\) and \((9, 0, 4)\), as we can check by substituting: \(13 + 0 + 4 = 17\), \(9 + 8 + 0 = 17\), \(9 + 0 + 8 = 17\).
The underlying intuition is a count of degrees of freedom. A point in space has three free coordinates. Each linear equation ties them together and removes one degree of freedom:
| Conditions | Degrees of freedom left | Object |
|---|---|---|
| None | 3 | All of space |
| One equation | 2 | A plane |
| Two equations (non-parallel planes) | 1 | A line |
| Three equations (in general position) | 0 | A point |
So two planes that intersect do so in a line. The planes \(y = 3\) and \(x + z = 14\) share all the points of the form \((x,\ 3,\ 14 - x)\): a horizontal line, 3 m up, that passes through the ship. And if the two planes are parallel (like \(y = 3\) and \(y = 12\)), they do not intersect. The last row is just what we were doing in "Systems of Linear Equations": solving a system of three equations with a unique solution means finding the point where three planes meet.
For now we will leave it at this idea. What the coefficients \(A\), \(B\), \(C\) and \(D\) mean geometrically, how to obtain the plane through three points and how to compute the line in which two planes intersect are the subject of the lesson "Equations of Planes and Lines", once we have the necessary vector tools.
Common Mistakes and Tips
- Mixing conventions without noticing. If a model shows up lying on its side, mirrored or at an absurd size, suspect the axis convention and the units first. Convert only once, at the boundary (on import), and always work in the engine's convention.
- Converting the points but not the rotations. With a change of handedness, rotations change direction. Matrices are converted with \(C,M,C^{-1}\), not by leaving them as they were.
- Using
arctan(x / z)instead ofarctan2(x, z). The former fails with \(z = 0\) and cannot tell a point from its opposite. - Forgetting the order of the arguments of
arctan2. With our azimuth convention (from +Z toward +X) it isarctan2(x, z). In mathematical formulas with Z up you will seearctan2(y, x): these are different conventions, not interchangeable formulas. - Degrees and radians. NumPy functions work in radians. Convert with
np.radianson the way in and withnp.degreeswhen displaying. - Adding spherical or cylindrical coordinates. They are not the components of a vector. To combine positions, switch to Cartesian coordinates.
- Believing that \(x + z = 14\) is a line in 3D. In the plane it is; in space, a single linear equation is always a plane. A line needs two.
- Tip. When in doubt about a conversion formula, test it with a point you know by heart: the point \((0, 0, 1)\) must give azimuth 0, and \((1, 0, 0)\), azimuth 90°.
Exercises
Exercise 1. The stray asteroid is at \((-6, 2, 10)\). a) What are its octant signs? b) How far is it from the ship \((8, 3, 6)\) and from the camera \((0, 5, 20)\)? Which one is it closer to? c) Find the midpoint between the lighthouse lamp \((0, 12, 0)\) and the ship.
Exercise 2. The ship is in a circular orbit around the tower, with \(\rho = 10\) and \(y = 3\). a) At which Cartesian point will it be when its azimuth has increased by 90° from the current one? Work it out by hand using \(\sin 53.13° = 0.8\) and \(\cos 53.13° = 0.6\). b) Express the position of the stray asteroid in cylindrical coordinates.
Exercise 3. a) An artist sends you the position of an object in Blender: \((-6, -10, 2)\). Which point is it in mini3d? b) The ship wants to aim its antenna at the lighthouse lamp. Compute the position of the lamp in spherical coordinates relative to the ship (axes parallel to the world's): distance, azimuth and elevation.
Solutions
Solution 1.
a) Signs \((-, +, +)\): it is on the other side of the YZ plane from the ship, above the ground and with positive \(z\).
b) Relative to the ship, the differences are \((8 - (-6),\ 3 - 2,\ 6 - 10) = (14, 1, -4)\), and \(d = \sqrt{196 + 1 + 16} = \sqrt{213} \approx 14.59\). Relative to the camera, \((0 + 6,\ 5 - 2,\ 20 - 10) = (6, 3, 10)\), and \(d = \sqrt{36 + 9 + 100} = \sqrt{145} \approx 12.04\). It is closer to the camera.
c) \(M = \left(\frac{0 + 8}{2}, \frac{12 + 3}{2}, \frac{0 + 6}{2}\right) = (4, 7.5, 3)\).
Solution 2.
a) The new azimuth is \(\varphi + 90°\). Using \(\sin(\varphi + 90°) = \cos\varphi = 0.6\) and \(\cos(\varphi + 90°) = -\sin\varphi = -0.8\):
\[ x = 10 \cdot 0.6 = 6 \qquad y = 3 \qquad z = 10 \cdot (-0.8) = -8 \]
The ship will be at \((6, 3, -8)\). Check: \(\sqrt{6^2 + 8^2} = 10\), it is still 10 m from the axis.
b) \(\rho = \sqrt{(-6)^2 + 10^2} = \sqrt{136} \approx 11.66\); \(\varphi = \operatorname{atan2}(-6, 10) \approx -30.96°\) (negative: from +Z we have to turn toward −X); \(y = 2\).
Solution 3.
a) Applying \((x_b, z_b, -y_b)\): \((-6,\ 2,\ 10)\). It is the stray asteroid.
b) First we express the lamp relative to the ship by subtracting coordinates: \((0 - 8,\ 12 - 3,\ 0 - 6) = (-8, 9, -6)\). Then we convert:
\[ r = \sqrt{64 + 81 + 36} = \sqrt{181} \approx 13.45 \qquad \varphi = \operatorname{atan2}(-8, -6) \approx -126.87° \qquad \varepsilon = \arcsin!\left(\frac{9}{13.45}\right) \approx 41.99° \]
The lamp is 13.45 m away, "behind and to the left" in the top-down view (azimuth −126.87°) and 41.99° above the horizontal. Typical mistake: converting \((0, 12, 0)\) directly, which would give the position of the lamp relative to the world origin, not relative to the ship.
Conclusion
A Cartesian coordinate system is an origin, three perpendicular axes and a unit, but it hides two arbitrary decisions—the handedness and the axis that points up—that every engine makes in its own way; translating between conventions is a change of basis with a matrix of zeros, ones and minus ones, whose determinant gives away whether the handedness changes. The three coordinate planes divide space into eight octants, the distance between two points is the Pythagorean theorem applied to the differences of coordinates, and cylindrical and spherical coordinates offer a much more natural description of orbits and orbit cameras, on condition that we go back to Cartesian coordinates to compute. Finally, we have seen that a linear equation in \(x\), \(y\), \(z\) describes a plane and that two planes intersect in a line. All along we have been subtracting the coordinates of points to obtain "differences": those differences are vectors. In the next lesson, "Vectors in 3D Space", we will give them the treatment they deserve: we will measure their length with the norm, normalize them to keep only their direction and use them to move the ship toward a target.
