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

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


Sponsored Link



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

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.

Released: Latest Version of VCSSL with Fixes for Behavioral Changes on Java 24
2025-04-22 - VCSSL 3.4.50 released with a fix for a subtle behavioral change in absolute path resolution on network drives, introduced in Java 24. Details inside.

Released the Latest Versions of RINEARN Graph and VCSSL - Now Supporting Customizable Tick Positions and Labels!
2024-11-24 - Starting with this update, a new "MANUAL" tick mode is now supported, allowing users to freely specify the positions and labels of ticks on the graph. We'll explain the details and how to use it.

Released Exevalator 2.2: Now Compatible with TypeScript and Usable in Web Browsers
2024-10-22 - The open-source expression evaluation library, Exevalator, has been updated to version 2.2. It now supports TypeScript and can be used for evaluating expressions directly in web browsers. Explains the details.

Behind the Scenes of Creating an Assistant AI (Part 1: Fundamental Knowledge)
2024-10-07 - The first part of a series on how to create an Assistant AI. In this article, we introduce the essential knowledge you need to grasp before building an Assistant AI. What exactly is an LLM-based AI? What is RAG? And more.

Launching an Assistant AI to Support Software Usage!
2024-09-20 - We've launched an Assistant AI that answers questions about how to use RINEARN software and helps with certain tasks. Anyone with a ChatGPT account can use it for free. We'll explain how to use it.

Software Updates: Command Expansion in RINEARN Graph, and English Support in VCSSL
2024-02-05 - We updated our apps. This updates include "Enhancing the Command-Line Features of RINEARN Graph" and "Adding English Support to VCSSL." Dives into each of them!