Skip to content

Commit 984ab1c

Browse files
committed
fix: add scaling/transformation matrix to bounding box
1 parent b230152 commit 984ab1c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

LoopStructural/datatypes/_bounding_box.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,23 @@ def __eq__(self, other):
668668
and np.allclose(self.maximum, other.maximum)
669669
and np.allclose(self.nsteps, other.nsteps)
670670
)
671+
672+
def matrix(self, normalise: bool = False) -> np.ndarray:
673+
"""Get the transformation matrix from local to global coordinates
674+
675+
Returns
676+
-------
677+
np.ndarray
678+
4x4 transformation matrix
679+
"""
680+
matrix = np.eye(4)
681+
L = self.global_maximum - self.global_origin
682+
L = np.max(L)
683+
matrix[0, 3] = -self.global_origin[0]/L
684+
matrix[1, 3] = -self.global_origin[1]/L
685+
matrix[2, 3] = -self.global_origin[2]/L
686+
if normalise:
687+
matrix[0,0] = 1/L
688+
matrix[1,1] = 1/L
689+
matrix[2,2] = 1/L
690+
return matrix

0 commit comments

Comments
 (0)