From 6ac88d39a386b2f505bb43fc7fb78ec61fcb3aa6 Mon Sep 17 00:00:00 2001 From: Michael Winkler Date: Sun, 3 Nov 2024 21:53:29 +0100 Subject: [PATCH] added as_homogeneous_matrix method to LCS --- weldx/transformations/local_cs.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/weldx/transformations/local_cs.py b/weldx/transformations/local_cs.py index 9076a6cbe..99c97c2f4 100644 --- a/weldx/transformations/local_cs.py +++ b/weldx/transformations/local_cs.py @@ -728,6 +728,32 @@ def as_rotation(self) -> Rot: # pragma: no cover """ return Rot.from_matrix(self.orientation.values) + def as_homogeneous_matrix(self, translation_unit: QuantityLike) -> np.ndarray: + """Get a homogeneous transformation matrix from the coordinate system + orientation. + + Returns + ------- + numpy.ndarray + Numpy array representing the homogeneous transformation matrix. + + """ + + if self.is_time_dependent: + time_dim = self.time.shape[0] + else: + time_dim = 1 + + rotation = np.resize(self.orientation.data, (time_dim, 3, 3)) + translation = np.resize( + self.coordinates.data.to(translation_unit).m, (time_dim, 3) + ) + homogeneous_matrix = np.zeros((time_dim, 4, 4)) + homogeneous_matrix[:, :3, :3] = rotation + homogeneous_matrix[:, :3, 3] = translation + + return homogeneous_matrix + def _interp_time_orientation(self, time: Time) -> xr.DataArray: """Interpolate the orientation in time.""" if "time" not in self.orientation.dims: # don't interpolate static