Euler Angle-Based Attitude Control of Coordinate Systems
Up to this point, the rotations and spins of coordinate systems we've covered have involved incrementally rotating a system based on its current orientation. However, in some cases, you may want to directly control the orientation of a coordinate system. This section introduces how to do just that.
Sponsored Link
Euler Angles
Z-X-Z Euler Angles
To describe the orientation of a 3D coordinate system, we need the concept of Euler angles. Euler angles express the posture of a coordinate system using three special angles.
There are various types and interpretations of Euler angles depending on the field or reference material, but here we will focus on the Z-X-Z Euler angles, which are commonly used in engineering.
Let the three angles used in the Euler angle system be denoted as α (alpha), β (beta), and γ (gamma). In the Z-X-Z Euler angle system, the orientation of a coordinate system is determined as follows:
- First, the system is rotated α radians around the Z-axis.
- Then, it is rotated β radians around the X-axis.
- Finally, it is rotated γ radians around the Z-axis again.
This sequence defines the final orientation of the coordinate system.
Limitations of Euler Angles
Once you define values for α, β, and γ, the orientation of the coordinate system is uniquely determined.
However, the reverse is not always true. That is, a single orientation may correspond to multiple combinations of α, β, and γ. This means that Euler angles have certain orientations that they are not good at representing, and this can sometimes lead to unexpected issues. One of the most well-known problems related to this is the phenomenon called gimbal lock.
To avoid such issues, it's often better not to rely solely on Euler angles. Instead, you can use other methods such as the "rotCoordinate" and "spinCoordinate" functions, which allow rotation around arbitrary axes, depending on the situation.
Euler Angle-Based Attitude Control
Setting Orientation via Euler Angles
To specify the orientation of a coordinate system using Euler angles, use the setCoordinateAngle(...) function:
- Function Format -
int coordinateID,
float alpha, float beta, float gamma
)
The parameters are as follows:
- coordinateID: The ID of the coordinate system to modify.
- alpha, beta, gamma: The first, second, and third angles in the Z-X-Z Euler angle system.
Retrieving Euler Angles
To obtain the Euler angles that represent the orientation of a coordinate system, use the getCoordinateAngle(...) function.
- Function Format -
The parameter "coordinateID" specifies which coordinate system to retrieve the orientation from.
This function returns an array of Euler angles (Z-X-Z system). The returned array contains:
- [0]: α (first angle),
- [1]: β (second angle),
- [2]: γ (third angle).
As mentioned earlier, multiple Euler angle combinations can represent the same orientation. This function will return one possible combination, so keep in mind that the result is not necessarily unique.
Example Program
Let's place a local coordinate system within the world coordinate system, and make it spin like a top through animation. To make it visually clear, we'll attach a smaller coordinate axis model to the local system and a larger one to the world system.
import graphics3d.Graphics3DFramework;
import Graphics3D;
import Math; // for using sin function
// Variable to store the ID of the coordinate system
int coord;
// Time counter (in frame update units)
int t = 0;
// Function called at the start of the program
void onStart ( int rendererID ) {
// Optional: set window size and background color
setWindowSize( 800, 600 );
setBackgroundColor( 0, 0, 0, 255 );
// Create a local coordinate system
coord = newCoordinate( );
// Mount it onto the world coordinate system
mountCoordinate( coord, rendererID );
// Attach a small axis model to the local coordinate system
int axis1 = newAxisModel( 1.5, 1.5, 1.5 );
mountModel( axis1, rendererID, coord );
// Attach a large axis model to the world coordinate system
int axis2 = newAxisModel( 3.0, 3.0, 3.0 );
mountModel( axis2, rendererID );
}
//Function called multiple times per second to update the screen
void onUpdate (int renderer) {
// Control orientation using Euler angles
setCoordinateAngle(
coord,
0.08*t, 0.5*sin(0.03*t), 0.3*t
);
// Advance time counter
t++;
}
Sample.vcssl
When this program runs, you'll see coordinate axis models displayed on a black screen. The large axis is attached to the world coordinate system, and the smaller one to the local system.

The local coordinate system performs a complex motion resembling the precession of a spinning top.
- The slow revolution around the Z-axis is due to the first angle α.
- The wobbly motion of the Z-axis is caused by the second angle β.
- The rapid spinning of the entire system is due to the third angle γ.
- 3D Computer Graphics
- Setting Up the Foundation
- Mouse Control and Animation
- Using the Framework
- Creating and Placing Light Sources (and Adjusting Their Properties)
- Creating and Placing Models / Standard Models
- Creating and Placing Polygons, and Various Types of Polygons
- Moving 3D Objects
- Rotating 3D Objects
- Scaling 3D Objects
- Flipping 3D Objects
- Setting Colors for 3D Objects
- Configuring the Shape of 3D Objects
- Fill Settings for 3D Objects
- Material Settings for 3D Objects
- Understanding Coordinate Systems: Concepts, Creation, and Placement
- Moving Coordinate Systems
- Walking Coordinate Systems
- Controlling the Origin Position of a Coordinate System
- Rotating Coordinate Systems
- Spinning a Coordinate System
- Euler Angle-Based Attitude Control of Coordinate Systems
- Camera Work
- Creating, Placing, and Performing Basic Operations on Vectors
- Coordinate Transformations
- Screen Projection
- Collision Detection