From 23cbf62ebcde8ad85981e7631d71ea2fcbbc7279 Mon Sep 17 00:00:00 2001 From: BalzaniEdoardo Date: Tue, 19 Mar 2024 15:50:27 -0400 Subject: [PATCH 1/7] added rotation property --- fastplotlib/graphics/_base.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fastplotlib/graphics/_base.py b/fastplotlib/graphics/_base.py index 91ccb143e..3ed5246a3 100644 --- a/fastplotlib/graphics/_base.py +++ b/fastplotlib/graphics/_base.py @@ -142,6 +142,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.world.rotation + + @rotation.setter + def rotation(self, val): + self.world_object.world.rotation = val + @property def visible(self) -> bool: """Access or change the visibility.""" From 1f310a607306be6442588fa8a4b108e2dbeda5ed Mon Sep 17 00:00:00 2001 From: BalzaniEdoardo Date: Tue, 19 Mar 2024 17:22:55 -0400 Subject: [PATCH 2/7] added a rotate method to rotate along axis --- fastplotlib/graphics/_base.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fastplotlib/graphics/_base.py b/fastplotlib/graphics/_base.py index 3ed5246a3..b1dce0c05 100644 --- a/fastplotlib/graphics/_base.py +++ b/fastplotlib/graphics/_base.py @@ -5,6 +5,7 @@ from dataclasses import dataclass import numpy as np +import pylinalg as la from pygfx import WorldObject @@ -204,6 +205,17 @@ def __del__(self): self.deleted = True del WORLD_OBJECTS[self.loc] + def rotate(self, alpha: float, axis: Literal["x", "y", "z"] = "z"): + if axis == "x": + rot = la.quat_from_euler((alpha, 0), order="XY") + elif axis == "y": + rot = la.quat_from_euler((0, alpha), order="XZ") + elif axis == "z": + rot = la.quat_from_euler((0, alpha), order="XY") + 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""" From 22cfa4f214a501dd43fae35153e13adc33271449 Mon Sep 17 00:00:00 2001 From: BalzaniEdoardo Date: Tue, 19 Mar 2024 17:46:46 -0400 Subject: [PATCH 3/7] fixed axis --- fastplotlib/graphics/_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fastplotlib/graphics/_base.py b/fastplotlib/graphics/_base.py index b1dce0c05..62c64dbba 100644 --- a/fastplotlib/graphics/_base.py +++ b/fastplotlib/graphics/_base.py @@ -205,13 +205,13 @@ def __del__(self): self.deleted = True del WORLD_OBJECTS[self.loc] - def rotate(self, alpha: float, axis: Literal["x", "y", "z"] = "z"): + def rotate(self, alpha: float, axis: Literal["x", "y", "z"] = "y"): if axis == "x": rot = la.quat_from_euler((alpha, 0), order="XY") elif axis == "y": - rot = la.quat_from_euler((0, alpha), order="XZ") - elif axis == "z": 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) From 3c41a0955cd93c858313b21ace91efe971181fe9 Mon Sep 17 00:00:00 2001 From: BalzaniEdoardo Date: Tue, 19 Mar 2024 17:50:33 -0400 Subject: [PATCH 4/7] added docstrings --- fastplotlib/graphics/_base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fastplotlib/graphics/_base.py b/fastplotlib/graphics/_base.py index 62c64dbba..5224348c1 100644 --- a/fastplotlib/graphics/_base.py +++ b/fastplotlib/graphics/_base.py @@ -206,6 +206,15 @@ def __del__(self): 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 radiants. + axis : + Rotation axis label. + """ if axis == "x": rot = la.quat_from_euler((alpha, 0), order="XY") elif axis == "y": From 77bdb41f3df7fb4c6af81922c8f9c2abaf077f1d Mon Sep 17 00:00:00 2001 From: BalzaniEdoardo Date: Wed, 27 Mar 2024 18:48:02 -0400 Subject: [PATCH 5/7] rotate in local coord --- fastplotlib/graphics/_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastplotlib/graphics/_base.py b/fastplotlib/graphics/_base.py index 5224348c1..a31a6a43c 100644 --- a/fastplotlib/graphics/_base.py +++ b/fastplotlib/graphics/_base.py @@ -145,11 +145,11 @@ def position_z(self, val): @property def rotation(self): - return self.world_object.world.rotation + return self.world_object.local.rotation @rotation.setter def rotation(self, val): - self.world_object.world.rotation = val + self.world_object.local.rotation = val @property def visible(self) -> bool: From 5f6039543c2ac8ee6cb8f5869f65582d1811462f Mon Sep 17 00:00:00 2001 From: BalzaniEdoardo Date: Wed, 27 Mar 2024 18:52:02 -0400 Subject: [PATCH 6/7] fix typo --- fastplotlib/graphics/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastplotlib/graphics/_base.py b/fastplotlib/graphics/_base.py index a31a6a43c..3c1e4a2c2 100644 --- a/fastplotlib/graphics/_base.py +++ b/fastplotlib/graphics/_base.py @@ -211,7 +211,7 @@ def rotate(self, alpha: float, axis: Literal["x", "y", "z"] = "y"): Parameters ---------- alpha : - Rotation angle in radiants. + Rotation angle in radians. axis : Rotation axis label. """ From 7662e2bb838168cd54065e35c774ba478657c092 Mon Sep 17 00:00:00 2001 From: BalzaniEdoardo Date: Wed, 27 Mar 2024 19:01:51 -0400 Subject: [PATCH 7/7] black-ed --- fastplotlib/graphics/_base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastplotlib/graphics/_base.py b/fastplotlib/graphics/_base.py index 3c1e4a2c2..f7a0ec102 100644 --- a/fastplotlib/graphics/_base.py +++ b/fastplotlib/graphics/_base.py @@ -222,7 +222,9 @@ def rotate(self, alpha: float, axis: Literal["x", "y", "z"] = "y"): 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!") + raise ValueError( + f"`axis` must be either `x`, `y`, or `z`. `{axis}` provided instead!" + ) self.rotation = la.quat_mul(rot, self.rotation)