Skip to content
Snippets Groups Projects
Commit a5073f9d authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

ENH: transform.decompose accepts 3x3 matrix

parent 077fd7eb
No related branches found
No related tags found
No related merge requests found
...@@ -178,7 +178,7 @@ def decompose(xform, angles=True): ...@@ -178,7 +178,7 @@ def decompose(xform, angles=True):
It is assumed that the given transform has no perspective components. Any It is assumed that the given transform has no perspective components. Any
shears in the affine are discarded. shears in the affine are discarded.
:arg xform: A ``(4, 4)`` affine transformation matrix. :arg xform: A ``(3, 3)`` or ``(4, 4)`` affine transformation matrix.
:arg angles: If ``True`` (the default), the rotations are returned :arg angles: If ``True`` (the default), the rotations are returned
as axis-angles, in radians. Otherwise, the rotation matrix as axis-angles, in radians. Otherwise, the rotation matrix
...@@ -187,7 +187,8 @@ def decompose(xform, angles=True): ...@@ -187,7 +187,8 @@ def decompose(xform, angles=True):
:returns: The following: :returns: The following:
- A sequence of three scales - A sequence of three scales
- A sequence of three translations - A sequence of three translations (all ``0`` if ``xform``
was a ``(3, 3)`` matrix)
- A sequence of three rotations, in radians. Or, if - A sequence of three rotations, in radians. Or, if
``angles is False``, a rotation matrix. ``angles is False``, a rotation matrix.
""" """
...@@ -198,9 +199,13 @@ def decompose(xform, angles=True): ...@@ -198,9 +199,13 @@ def decompose(xform, angles=True):
# The next step is to extract the translations. This is trivial; # The next step is to extract the translations. This is trivial;
# we find t_x = M_{4,1}, t_y = M_{4,2}, and t_z = M_{4,3}. At this # we find t_x = M_{4,1}, t_y = M_{4,2}, and t_z = M_{4,3}. At this
# point we are left with a 3*3 matrix M' = M_{1..3,1..3}. # point we are left with a 3*3 matrix M' = M_{1..3,1..3}.
xform = xform.T xform = xform.T
translations = xform[ 3, :3]
xform = xform[:3, :3] if xform.shape == (4, 4):
translations = xform[ 3, :3]
xform = xform[:3, :3]
else:
translations = np.array([0, 0, 0])
M1 = xform[0] M1 = xform[0]
M2 = xform[1] M2 = xform[1]
...@@ -261,7 +266,7 @@ def decompose(xform, angles=True): ...@@ -261,7 +266,7 @@ def decompose(xform, angles=True):
if angles: rotations = rotMatToAxisAngles(R.T) if angles: rotations = rotMatToAxisAngles(R.T)
else: rotations = R.T else: rotations = R.T
return [sx, sy, sz], translations, rotations return np.array([sx, sy, sz]), translations, rotations
def rotMatToAffine(rotmat, origin=None): def rotMatToAffine(rotmat, origin=None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment