from typing import Tuple
import torch


def min_jerk_spaces(
    N: int, T: float
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
    """
    Generates a 1-dim minimum jerk trajectory from 0 to 1 in N steps & T seconds.
    Assumes zero velocity & acceleration at start & goal.
    The resulting trajectories can be scaled for different start & goals.

    Args:
        N: Number of sample points

    Returns:
        Position trajectory of shape (N,)
        Velocity trajectory of shape (N,)
        Acceleration trajectory of shape (N,)
    """
    assert N > 1, "Number of planning steps must be larger than 1."

    t_traj = torch.linspace(0, 1, N)
    p_traj = 10 * t_traj ** 3 - 15 * t_traj ** 4 + 6 * t_traj ** 5
    pd_traj = (30 * t_traj ** 2 - 60 * t_traj ** 3 + 30 * t_traj ** 4) / T
    pdd_traj = (60 * t_traj - 180 * t_traj ** 2 + 120 * t_traj ** 3) / T ** 2

    return p_traj, pd_traj, pdd_traj