Which Way is Up?
New to 3D? Make sure you know which axis is “up” with this primer on 3D coordinate systems.
What is a Coordinate System?
A coordinate system is simply a way of using numbers or letters to represent the position of a point in space. You may not realize it, but if you’ve ever used a spreadsheet or played a game of Battleship, then you have already used a coordinate system. For example, when you say “Column 2, Row 4″ in a spreadsheet, or “B-5″ in a game of Battleship, you are naming the “coordinate” of the position you are interested in.
What is the Cartesian Coordinate System?
There are many different types of coordinate systems, but some are more common than others. One of the most common–and the type you will use most often in 3D graphics–is called the Cartesian coordinate system. The Cartesian coordinate system is named after mathematician and philosopher RenÃ© Descartes, the author of the famous phrase “I think, therefore I am”.
A 2D Cartesian coordinate system, also called a rectangular coordinate system, is formed from two axes–or reference lines–that are at right angles from each other. The horizontal axis is named X, and the vertical axis is named Y. The point where the two lines cross is called the “origin” of the coordinate system.
By measuring the distance along the X- and Y-axes, you can find the position of a point. For example, if someone were to tell you a point was located at (4, 2) this would mean that the point would be located 4 units to the right and 2 units up from the origin. A point positioned at (-3, 1) would be located exactly 3 units to the left of the origin, and one unit up.
A 3D Cartesian coordinate system works exactly the same as a 2D system, but adds a third axis named Z. By specifying the X, Y, and Z coordinate of a point, you can find the location of any position in 3D space.
Orientations and Right-Handed Versus Left-Handed Coordinate Systems
Most people have no trouble using a 2D coordinate system, but one of the things that sometimes makes 3D coordinate systems tricky is the fact that no one can seem to agree on which direction the X-, Y- and Z-axes should point. Mathematicians often use a system where the Y-axis points up and down, and the Z-axis points in and out. Engineers, on the other hand, use a system where the Z-axis points up and down and the Y-axis points in and out. Aargh.
In most 3D computer graphics systems, the positive X-axis points to the right, and the positive Y-axis points up. This makes sense because the same is true for many 2D displays. That way, the definitions don’t have to change when the Z-axis is added; the Z simply adds in-and-out movement to the existing setup. Of course, this leaves only the question of whether positive Z points into the screen, or out of the screenâ€¦ and naturally, people can’t agree.
This means there are two types of 3D Cartesian coordinate systems that you will find when working with computer graphics: left-handed and right-handed. In a left-handed system, the Z-axis points inwards toward the screen. In a right-handed system, the Z-axis points outwards away from the screen.
You can remember which one is which with a simple trick. Start by pointing the fingers of either your left or right hand in the positive X direction (to the right). Turn your hand so that your palm is facing the positive Y direction (up), curling your fingers in the direction of positive Y as well. Stick out your thumb. The direction your thumb is pointing shows you which direction the Z-axis goes for that coordinate system.
How Do I Know Which One to Use?
Check the manual! Seriously, though, different 3D programs are pretty much evenly split between left-handed and right-handed systems. The best way to know for sure which system yours uses is to read the documentation.
If you don’t have a manual, as a general rule of thumb OpenGL applications use a right-handed coordinate system, and DirectX applications use a left-handed coordinate system. This is not an absolute; there are certainly many cases where this is untrue. However, OpenGL is internally right-handed and DirectX is internally left-handed, and more often than not application programmers tend to use the coordinate system that matches whichever rendering API they consider “native”.