Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rotation #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass

import numpy as np
import pylinalg as la

from pygfx import WorldObject

Expand Down Expand Up @@ -142,6 +143,14 @@ def position_y(self, val):
def position_z(self, val):
self.world_object.world.z = val

@property
def rotation(self):
return self.world_object.local.rotation

@rotation.setter
def rotation(self, val):
self.world_object.local.rotation = val

@property
def visible(self) -> bool:
"""Access or change the visibility."""
Expand Down Expand Up @@ -196,6 +205,28 @@ def __del__(self):
self.deleted = True
del WORLD_OBJECTS[self.loc]

def rotate(self, alpha: float, axis: Literal["x", "y", "z"] = "y"):
"""Rotate the Graphic with respect to the world.

Parameters
----------
alpha :
Rotation angle in radians.
axis :
Rotation axis label.
"""
if axis == "x":
rot = la.quat_from_euler((alpha, 0), order="XY")
elif axis == "y":
rot = la.quat_from_euler((0, alpha), order="XY")
elif axis == "z":
rot = la.quat_from_euler((0, alpha), order="XZ")
else:
raise ValueError(
f"`axis` must be either `x`, `y`, or `z`. `{axis}` provided instead!"
)
self.rotation = la.quat_mul(rot, self.rotation)


class Interaction(ABC):
"""Mixin class that makes graphics interactive"""
Expand Down