Quaternion — Aspose.3D FOSS for Java

Overview

Quaternion represents a unit quaternion used for rotation. It avoids gimbal lock and provides smooth interpolation between orientations. The Transform class stores rotation as a Quaternion accessible via getRotation() / setRotation().

Package: com.aspose.threed

import com.aspose.threed.*;

Constructor

SignatureDescription
Quaternion()Identity quaternion (1, 0, 0, 0)
Quaternion(double w, double x, double y, double z)Constructs from four components

Public Fields

Quaternion uses public fields for component access (not getter/setter methods):

FieldTypeAccessDescription
wdoubleq.wScalar (real) part
xdoubleq.xX component of the vector part
ydoubleq.yY component of the vector part
zdoubleq.zZ component of the vector part

Computed Properties

NameTypeGetterDescription
lengthdoublegetLength()Magnitude of the quaternion (should be 1.0 for a unit quaternion)

Static Fields

FieldTypeDescription
IDENTITYQuaternionThe identity quaternion (1, 0, 0, 0) – no rotation

Static Methods

MethodReturn TypeDescription
Quaternion.fromEuler(double x, double y, double z)QuaternionCreates a quaternion from Euler angles in degrees
Quaternion.fromAngleAxis(double angle, Vector3 axis)QuaternionCreates a quaternion from an angle (radians) and rotation axis

Instance Methods

MethodReturn TypeDescription
normalize()QuaternionReturns a unit-length copy
conjugate()QuaternionReturns the conjugate (negated vector part)
inverse()QuaternionReturns the multiplicative inverse
toEulerAngles()Vector3Converts to Euler angles in degrees
toMatrix()Matrix4Converts to a 4x4 rotation matrix

Example

import com.aspose.threed.Scene;
import com.aspose.threed.Node;
import com.aspose.threed.*;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("rotated");

// Create from Euler angles (degrees)
Quaternion q = Quaternion.fromEuler(0.0, 90.0, 0.0);
node.getTransform().setRotation(q);

// Read back as Euler
Vector3 euler = node.getTransform().getEulerAngles();
System.out.println(euler);   // approximately (0, 90, 0)

// Create from angle-axis
Quaternion q2 = Quaternion.fromAngleAxis(Math.toRadians(45), Vector3.UNIT_Y);
node.getTransform().setRotation(q2);

// Combine rotations via multiply
Quaternion start = Quaternion.IDENTITY;
Quaternion end = Quaternion.fromEuler(0.0, 180.0, 0.0);
Quaternion combined = Quaternion.multiply(start, end);

See Also