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

transform method now has a 'vector' option, which skips translation.

parent 1614e9ee
No related branches found
No related tags found
No related merge requests found
...@@ -412,24 +412,28 @@ def axisBounds(shape, ...@@ -412,24 +412,28 @@ def axisBounds(shape,
else: return (lo, hi) else: return (lo, hi)
def transform(p, xform, axes=None): def transform(p, xform, axes=None, vector=False):
"""Transforms the given set of points ``p`` according to the given affine """Transforms the given set of points ``p`` according to the given affine
transformation ``xform``. transformation ``xform``.
:arg p: A sequence or array of points of shape :math:`N \\times 3`. :arg p: A sequence or array of points of shape :math:`N \\times 3`.
:arg xform: An affine transformation matrix with which to transform the :arg xform: An affine transformation matrix with which to transform the
points in ``p``. points in ``p``.
:arg axes: If you are only interested in one or two axes, and the source :arg axes: If you are only interested in one or two axes, and the source
axes are orthogonal to the target axes (see the note below), axes are orthogonal to the target axes (see the note below),
you may pass in a 1D, ``N*1``, or ``N*2`` array as ``p``, and you may pass in a 1D, ``N*1``, or ``N*2`` array as ``p``, and
use this argument to specify which axis/axes that the data in use this argument to specify which axis/axes that the data in
``p`` correspond to. ``p`` correspond to.
:returns: The points in ``p``, transformed by ``xform``, as a ``numpy`` :arg vector: Defaults to ``False``. If ``True``, the points are treated
array with the same data type as the input. as vectors - the translation component of the transformation
is not applied.
:returns: The points in ``p``, transformed by ``xform``, as a ``numpy``
array with the same data type as the input.
.. note:: The ``axes`` argument should only be used if the source .. note:: The ``axes`` argument should only be used if the source
...@@ -442,7 +446,10 @@ def transform(p, xform, axes=None): ...@@ -442,7 +446,10 @@ def transform(p, xform, axes=None):
""" """
p = _fillPoints(p, axes) p = _fillPoints(p, axes)
t = np.dot(xform[:3, :3], p.T).T + xform[:3, 3] t = np.dot(xform[:3, :3], p.T).T
if not vector:
t = t + xform[:3, 3]
if axes is not None: if axes is not None:
t = t[:, axes] t = t[:, axes]
......
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