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

New transformNormal function, for transforming normal vectors.

parent aba4d605
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ spaces. The following functions are provided: ...@@ -11,6 +11,7 @@ spaces. The following functions are provided:
:nosignatures: :nosignatures:
transform transform
transformNormal
scaleOffsetXform scaleOffsetXform
invert invert
concat concat
...@@ -437,8 +438,8 @@ def transform(p, xform, axes=None, vector=False): ...@@ -437,8 +438,8 @@ def transform(p, xform, axes=None, vector=False):
: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: A ``(4, 4)`` affine transformation matrix with which to
points in ``p``. transform the 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),
...@@ -448,7 +449,8 @@ def transform(p, xform, axes=None, vector=False): ...@@ -448,7 +449,8 @@ def transform(p, xform, axes=None, vector=False):
:arg vector: Defaults to ``False``. If ``True``, the points are treated :arg vector: Defaults to ``False``. If ``True``, the points are treated
as vectors - the translation component of the transformation as vectors - the translation component of the transformation
is not applied. is not applied. If you set this flag, you pass in a ``(3, 3)``
transformation matrix.
:returns: The points in ``p``, transformed by ``xform``, as a ``numpy`` :returns: The points in ``p``, transformed by ``xform``, as a ``numpy``
array with the same data type as the input. array with the same data type as the input.
...@@ -476,6 +478,14 @@ def transform(p, xform, axes=None, vector=False): ...@@ -476,6 +478,14 @@ def transform(p, xform, axes=None, vector=False):
else: return t else: return t
def transformNormal(p, xform, axes=None):
"""Transforms the given point(s), under the assumption that they
are normal vectors. In this case, the points are transformed by
``invert(xform[:3, :3]).T``.
"""
return transform(p, invert(xform[:3, :3]).T, axes, vector=True)
def _fillPoints(p, axes): def _fillPoints(p, axes):
"""Used by the :func:`transform` function. Turns the given array p into """Used by the :func:`transform` function. Turns the given array p into
a ``N*3`` array of ``x,y,z`` coordinates. The array p may be a 1D array, a ``N*3`` array of ``x,y,z`` coordinates. The array p may be a 1D array,
......
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