Skip to content

plotting

Trajectory visualization and plotting utilities.

Important

THIS MODULE IS IN MAJOR NEED OF REFACTORING AND SHOULD NOT BE USED.

The plotting module is currently undergoing significant restructuring and should be considered unstable. The API is subject to change without notice. Use at your own risk.

This module provides visualization utilities for trajectory optimization results. It includes functions for plotting state trajectories, control inputs, constraint violations, and creating animations of the optimization process.

qdcm(q: np.ndarray) -> np.ndarray

Convert a quaternion to a direction cosine matrix (DCM).

Parameters:

Name Type Description Default
q ndarray

Quaternion array [w, x, y, z] where w is the scalar part

required

Returns:

Type Description
ndarray

3x3 rotation matrix (direction cosine matrix)

Source code in openscvx/plotting/plotting.py
def qdcm(q: np.ndarray) -> np.ndarray:
    """Convert a quaternion to a direction cosine matrix (DCM).

    Args:
        q: Quaternion array [w, x, y, z] where w is the scalar part

    Returns:
        3x3 rotation matrix (direction cosine matrix)
    """
    q_norm = (q[0] ** 2 + q[1] ** 2 + q[2] ** 2 + q[3] ** 2) ** 0.5
    w, x, y, z = q / q_norm
    return np.array(
        [
            [1 - 2 * (y**2 + z**2), 2 * (x * y - z * w), 2 * (x * z + y * w)],
            [2 * (x * y + z * w), 1 - 2 * (x**2 + z**2), 2 * (y * z - x * w)],
            [2 * (x * z - y * w), 2 * (y * z + x * w), 1 - 2 * (x**2 + y**2)],
        ]
    )