> ## Documentation Index
> Fetch the complete documentation index at: https://docs.generalrobotics.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Orientation

> A class to represent the orientation as a quaternion

```python theme={null}
from grid_types import Orientation
```

A class to represent the orientation as a quaternion

## Fields

<ResponseField name="x" type="float">
  x component of quaternion
</ResponseField>

<ResponseField name="y" type="float">
  y component of quaternion
</ResponseField>

<ResponseField name="z" type="float">
  z component of quaternion
</ResponseField>

<ResponseField name="w" type="float">
  w component of quaternion (scalar) Can be initialized with either quaternion components or Euler angles
</ResponseField>

## Constructor

```python Signature theme={null}
Orientation(
    x: Union[float, int, np.ndarray, list],
    y: Union[float, int] = None,
    z: Union[float, int] = None,
    w: Optional[Union[float, int]] = None,
)
```

Initialize an Orientation object.

This constructor supports multiple initialization methods:

1. Using quaternion components (x, y, z, w)
2. Using Euler angles (roll, pitch, yaw) where the first three arguments
   are interpreted as roll, pitch, and yaw respectively
3. Using a rotation matrix (3x3 numpy array or list)
4. Using a quaternion array (4-element list or numpy array)

<ParamField body="x" required>
  x component of quaternion, roll angle, rotation matrix, or quaternion array
</ParamField>

<ParamField body="y">
  y component of quaternion or pitch angle. Ignored when x is an array.
</ParamField>

<ParamField body="z">
  z component of quaternion or yaw angle. Ignored when x is an array.
</ParamField>

<ParamField body="w">
  w component of quaternion. When None, x, y, z are interpreted as Euler angles.
</ParamField>

## Methods

### `conjugate()`

```python Signature theme={null}
conjugate() -> Orientation
```

Return the conjugate of the quaternion (-x, -y, -z, w).
For a unit quaternion, the conjugate is its inverse.

**Returns:**

Orientation: New orientation representing the conjugate.

### `from_dict()`

```python Signature theme={null}
from_dict(data: dict) -> Orientation
```

Deserialize from dictionary

### `normalize()`

```python Signature theme={null}
normalize() -> Orientation
```

Return a normalized version of this quaternion

**Returns:**

Orientation: New orientation with normalized quaternion components

### `to_axis_angle()`

```python Signature theme={null}
to_axis_angle(degrees: bool = False) -> np.ndarray
```

Convert quaternion to axis-angle representation.

<ParamField body="degrees" default="False">
  If True, the angle is returned in degrees. Defaults to False.
</ParamField>

**Returns:**

np.ndarray: 3 dimensional vector which is co-directional to the axis of rotation and
whose norm gives the angle of rotation.

### `to_dict()`

```python Signature theme={null}
to_dict() -> dict
```

Serialize to dictionary for JSON transfer

### `to_euler()`

```python Signature theme={null}
to_euler(order: str = 'xyz') -> Tuple[float, float, float]
```

Convert quaternion to Euler angles.

<ParamField body="order" default="'xyz'">
  Order of rotations. Defaults to "xyz". Supported orders include "xyz", "zyx", "yzx", etc.
</ParamField>

**Returns:**

tuple\[float, float, float]: Tuple of (roll, pitch, yaw) in radians.

### `to_matrix()`

```python Signature theme={null}
to_matrix() -> np.ndarray
```

Convert quaternion to a rotation matrix

**Returns:**

np.ndarray: 3x3 rotation matrix

## Example

```python theme={null}
orientation = Orientation(x, y, z, w)
orientation = Orientation(roll, pitch, yaw)
```


## Related topics

- [Customizing RL Training](/simulation/isaac/reinforcement-learning/customizing-training.md)
- [Sensors](/simulation/isaac/sensors.md)
- [ROS2 Communication](/simulation/isaac/comms.md)
- [MDP Config](/simulation/isaac/session_configuration/mdp.md)
- [Camera Calibration](/deployment/camera-calibration.md)
