Skip to content

xwhy.plots.create_rotation_frames

Generate camera rotation frames for 3D Plotly animations.

Parameters:

Name Type Description Default
radius float

Distance of the camera from the origin in the XY plane.

2.0
height float

Z-axis position of the camera.

0.8
num_steps int

Number of animation frames.

100

Returns:

Type Description
list[dict[str, Any]]

A list of Plotly animation frame dictionaries for a rotating view.

Source code in src/xwhy/plots/point_cloud.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def create_rotation_frames(
    radius: float = 2.0,
    height: float = 0.8,
    num_steps: int = 100,
) -> list[dict[str, Any]]:
    """Generate camera rotation frames for 3D Plotly animations.

    Args:
        radius: Distance of the camera from the origin in the XY plane.
        height: Z-axis position of the camera.
        num_steps: Number of animation frames.

    Returns:
        A list of Plotly animation frame dictionaries for a rotating view.

    """
    angles = np.linspace(0, 2 * np.pi, num_steps)
    frames: list[dict[str, Any]] = []

    for angle in angles:
        frame = {
            "layout": {
                "scene": {
                    "camera": {
                        "eye": {
                            "x": radius * float(np.cos(angle)),
                            "y": radius * float(np.sin(angle)),
                            "z": height,
                        }
                    }
                }
            }
        }
        frames.append(frame)

    return frames