[ Prev | Index | Next ]
Japanese English

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.

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 setCoordinateAngle (
  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 -

float[ ] getCoordinateAngle ( int coordinateID )

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.

Execution Result
Execution Result
A large and a small coordinate axis are displayed. The small coordinate system rotates with animation.

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 γ.

Author of This Article

Fumihiro Matsui
[ Founder of RINEARN, Doctor of Science (Physics), Applied Info Tech Engineer ]
Develops VCSSL, RINEARN Graph 3D and more. Also writes guides and articles.

Translation Cooperator

ChatGPT AIs
[ GPT-3.5, 4, 5, 5.1 ]
We greatly appreciate the cooperation of ChatGPT AIs in translating this article.


Sponsored Link



Japanese English
Index
[ Prev | Index | Next ]
News From RINEARN
* VCSSL is developed by RINEARN.

Exevalator v2.4 Released — MCP Support Added, Now Usable as an AI Calculation Tool
2025-11-15 - We've released Exevalator v2.4, our expression-evaluation library. Starting with this version, it supports MCP, making it usable as a calculation tool for AI assistants.

Exevalator v2.3 Released — Now Usable from Python
2025-11-04 - We've released Exevalator v2.3. Starting with this version, you can now use it from Python! With growing demand around AI tool development in mind, we share the details here.

Exevalator Updated — Easy Japanese Localization for Error Messages
2025-10-31 - Exevalator 2.2.2 is out. You can now localize error messages to Japanese with a simple copy-and-paste, and we've included several bug fixes and minor parser adjustments.

Inside RINPn Online: Architecture Overview
2025-10-22 - An inside look at the architecture of the recently launched online version of the RINPn scientific calculator. It's open source, so you can freely modify and reuse it to build your own web calculator (maybe!).

Meet RINPn Online: Use the Scientific Calculator Anywhere, Instantly
2025-10-21 - RINPn, the free scientific calculator, now has an online version you can use instantly in your browser — on both PC and smartphones. Read the announcement for details.

The VCSSL Support AI is Here! — Requires a ChatGPT Plus Account for Practical Performance
2025-08-19 - A new AI assistant for the VCSSL programming language is here to answer your questions and help with coding. This article explains how to use it and showcases plenty of real Q&A and generated code examples.

English Documentation for Our Software and VCSSL Is Now Nearly Complete
2025-06-30 - We're happy to announce that the large-scale expansion of our English documentation with the support of AI — a project that began two years ago — has now reached its initial target milestone.

VCSSL 3.4.52 Released: Enhanced Integration with External Programs and More
2025-05-25 - This update introduces enhancements to the external program integration features (e.g., for running C-language executables). Several other improvements and fixes are also included. Details inside.