---
title: trajectory
---

<div class="python-reference">
<a id="fastvideo.models.dits.hyworld.trajectory-functions"></a>
<a id="fastvideo.models.dits.hyworld.trajectory"></a>

<h2 id="fastvideo.models.dits.hyworld.trajectory.rot_x"><code>fastvideo.models.dits.hyworld.trajectory.rot_x</code></h2>
<pre class="doc-signature"><code>rot_x(theta)</code></pre>

<details><summary>Source</summary><pre><code>def rot_x(theta):
    c, s = np.cos(theta), np.sin(theta)
    return np.array(&#91;&#91;1, 0, 0&#93;, &#91;0, c, -s&#93;, &#91;0, s, c&#93;&#93;)</code></pre></details>
<h2 id="fastvideo.models.dits.hyworld.trajectory.rot_y"><code>fastvideo.models.dits.hyworld.trajectory.rot_y</code></h2>
<pre class="doc-signature"><code>rot_y(theta)</code></pre>

<details><summary>Source</summary><pre><code>def rot_y(theta):
    c, s = np.cos(theta), np.sin(theta)
    return np.array(&#91;&#91;c, 0, s&#93;, &#91;0, 1, 0&#93;, &#91;-s, 0, c&#93;&#93;)</code></pre></details>
<h2 id="fastvideo.models.dits.hyworld.trajectory.rot_z"><code>fastvideo.models.dits.hyworld.trajectory.rot_z</code></h2>
<pre class="doc-signature"><code>rot_z(theta)</code></pre>

<details><summary>Source</summary><pre><code>def rot_z(theta):
    c, s = np.cos(theta), np.sin(theta)
    return np.array(&#91;&#91;c, -s, 0&#93;, &#91;s, c, 0&#93;, &#91;0, 0, 1&#93;&#93;)</code></pre></details>
<h2 id="fastvideo.models.dits.hyworld.trajectory.generate_camera_trajectory_local"><code>fastvideo.models.dits.hyworld.trajectory.generate_camera_trajectory_local</code></h2>
<pre class="doc-signature"><code>generate_camera_trajectory_local(motions)</code></pre>
<h3>list of dict</h3>
<p>&#123;"forward": 1.0&#125;, &#123;"yaw": np.pi/2&#125;, &#123;"pitch": np.pi/6&#125;, &#123;"right": 1.0&#125;
- forward: Translation (Forward or Backward)
- yaw:   Rotate (Left or Right)
- pitch: Rotate (Up or Down)
- right: Translation (Right or Left)
- third_yaw: Third Perspective Rotate (Left or Right)</p>
<details><summary>Source</summary><pre><code>def generate_camera_trajectory_local(motions):
    &quot;&quot;&quot;
    motions: list of dict
             &#123;&quot;forward&quot;: 1.0&#125;, &#123;&quot;yaw&quot;: np.pi/2&#125;, &#123;&quot;pitch&quot;: np.pi/6&#125;, &#123;&quot;right&quot;: 1.0&#125;
             - forward: Translation (Forward or Backward)
             - yaw:   Rotate (Left or Right)
             - pitch: Rotate (Up or Down)
             - right: Translation (Right or Left)
             - third_yaw: Third Perspective Rotate (Left or Right)
    &quot;&quot;&quot;

    poses = &#91;&#93;
    T = np.eye(4)
    poses.append(T.copy())

    for move in motions:
        # Rotate (Left or Right)
        if &quot;yaw&quot; in move:
            R = rot_y(move&#91;&quot;yaw&quot;&#93;)
            T&#91;:3, :3&#93; = T&#91;:3, :3&#93; @ R

        # Rotate (Up or Down)
        if &quot;pitch&quot; in move:
            R = rot_x(move&#91;&quot;pitch&quot;&#93;)
            T&#91;:3, :3&#93; = T&#91;:3, :3&#93; @ R

        # Translation (Z-direction of the camera&#x27;s local coordinate system)
        forward = move.get(&quot;forward&quot;, 0.0)
        if forward != 0:
            local_t = np.array(&#91;0, 0, forward&#93;)
            world_t = T&#91;:3, :3&#93; @ local_t
            T&#91;:3, 3&#93; += world_t

        # Translation (Z-direction of the camera&#x27;s local coordinate system)
        right = move.get(&quot;right&quot;, 0.0)
        if right != 0:
            local_t = np.array(&#91;right, 0, 0&#93;)
            world_t = T&#91;:3, :3&#93; @ local_t
            T&#91;:3, 3&#93; += world_t

        # Third Perspective Rotate (Left or Right)
        third_yaw = move.get(&quot;third_yaw&quot;, 0.0)
        if third_yaw != 0:
            theta = -third_yaw
            C = np.array(&#91;&#91;1, 0.0, 0, 0&#93;, &#91;0, 1, 0, 0&#93;, &#91;0, 0, 1, -1.0&#93;, &#91;0, 0, 0, 1&#93;&#93;)
            c_origin = C.copy()
            # Rotation around the Y-axis
            R_y = np.array(&#91;
                &#91;np.cos(theta), 0, np.sin(theta)&#93;,
                &#91;0, 1, 0&#93;,
                &#91;-np.sin(theta), 0, np.cos(theta)&#93;,
            &#93;)
            # Translation
            C&#91;:3, :3&#93; = C&#91;:3, :3&#93; @ R_y
            C&#91;:3, 3&#93; = R_y @ C&#91;:3, 3&#93;
            c_inv = np.linalg.inv(c_origin)
            c_relative = c_inv @ C
            T = T @ c_relative

        poses.append(T.copy())

    return poses</code></pre></details>
</div>
