-
Notifications
You must be signed in to change notification settings - Fork 1
Coordinate Systems
##Conceptual Overview:
Coordinate Systems can be thought of as where you are viewing the world from and this serves as a good conceptual model for how they are implemented in this Library. Following this model, if you shift based on a CoordinateSystem, the objects will shift in the opposite way because you are moving "yourself" and not the objects when you are changing CoordinateSystems. To see this, just look at an object in front of you. If you move left a step, it is perceived the same as if the object moved right a step and you stayed still and this is how the CoordinateSystems work. Because of this, CoordinateSystems are useful because we can switch easily to different view for certain objects without losing how it is related to the rest of the objects. This concept can be used to simplify calculations from 3D to 2D and make them much easier to preform by shifting to a CoordianteSystem in which the calculations done will have no component in one of the axis directions. An example of a simplified calculation by using CoordinateSystems would be finding the length of a geometry. If created a geometry and kept track of the local CoordinateSystem, if you then modify the geometry in the WorldCoordinateSystem and want to find its new length, you could do some complicated 3D math to figure this out or you could shift it back to its local CoordinateSystems and do an easier calculation using only one dimension instead of three. Using CoordinateSystems these types of ways is the same idea of reference frames and is actually a limited application of reference frames, if that helps with conceptualizing them and their power. ##CoordinateSystem Properties: This implementation is for a very specific type of coordinate system.These CoordinateSystems are only Cartesian Coordinate Systems and they follow the right-hand rule, which is how 3D space is usually represented. These pieces are broken into more detail below:
Cartesian Coordinate System - Each axis is separated from the other two axes by 90 degrees. These axes are formed by the intersection of 3 planes so that no matter where you are in the CoordinateSystem, the three axes will always be separated by 90 degrees
Right-Hand Rule - This is a rule for determining how the axes relate to each other and which directions are positive and negative along the axis. By using this rule, if you know two of the axes directions, then you can find out which way should be the positive direction for the third axis. Representation in Code:
While there are many ways to represent coordinate systems, this implementation CoordinateSystems has two main parts: Origin - The translation from the WorldCoordinateSystem's origin to the local CoordinateSystem's origin stored in translationToOrigin as a Point
Extrinsic Tait-Bryan angles (a specific type of Euler angles) - The set of rotations around the WorldCoordinateSystem's axes to perform in X-Y-Z order (order is important!) to get to the local CoordinateSystem's orientation, each stored in separate variables: xAxisRotationAngle, yAxisRotationAngle, zAxisRotationAngle. Note: While Euler angles are often limited so that the second angle is limited, but in this scheme we limit all the angles to [0, 2pi] so we do not have to worry about converting any inputted angles if they are outside the range.
##WorldCoordinateSystem: Another concept that is used in this class is of a "WorldCoordinateSystem." This is an arbitrary CoordinateSystem that is used as the basis and reference for all the CoordinateSystems. Since it is arbitrary and the reference, it's pieces will always be "zero" no matter where it is placed. This is the same as when you are graphing a line: you draw a X-Axis and an Y-Axis, which positions are arbitrary, and then draw the line based on those axes, except in 3-Dimensions.
##CoordinateSystem Math: Because the order of rotations about the axes matters with Euler angles, you cannot combine CoordinateSystems by adding the respective angles together. If you do want to combine CoordinateSystems, you can shift one of the CoordinateSystems with the other, but it is important to remember that order matters so which one you shift and which one you shift with are important. This shift function "adds" the angles together by putting them into rotation matrices and then multiplying them in the correct order and then extracting the angles from the resulting rotation matrix. If you need to rotate a CoordinateSystem, the same thing applies. Instead of just adding the angles to the Euler angles of the CoordinateSystem, you must shift the CoordinateSystem with the Rotation in the Shift in order to guarantee correct results. Moving the origin of the CoordinateSystem can be done by simply adding to the translationToOrigin, although it is still advised to do it with a Shift to maintain consistency and because the Shift function has support for if the Shift it is not relative to the WorldCoordinateSystem.
##Orientation and Uniqueness: These CoordinateSystems do NOT represent a unique orientation. Many different combinations of Euler angle can lead to the same orientation based on the WorldCoordinateSystem so you cannot just compare the angles to see if they are oriented the same. In order to determine if two CoordinateSystems represent the same orientation, in the areDirectionsEquivalent() method (used in the equality operator) we put the Euler angles into a different form, Quaternions, to determine if they are the same orientation.