Applying 4x4 transformation to 3-element vector with numpy

Nobody nobody at nowhere.com
Wed Oct 9 12:44:16 EDT 2013


On Tue, 08 Oct 2013 23:10:16 -0700, John Nagle wrote:

>     I only need affine transformations.  This is just moving
> the coordinate system of a point, not perspective rendering. I have to do
> this for a lot of points, and I'm hoping numpy has some way to do this
> without generating extra garbage on the way in and the way out.

In which case, Christian's answer is correct.

For an affine transformation, the bottom row of the 4x4 matrix will be
[0 0 0 1], so you have:

[x']   [a b c d] [x]   [ax+by+cz+d]
[y'] = [e f g h] [y] = [ex+fy+gz+h]
[z']   [i j k l] [z]   [ix+jy+kz+l]
[1 ]   [0 0 0 1] [1]   [1         ]

 => 

[x']   [ax+by+cz+d]   [a b c] [x]   [d]
[y'] = [ex+fy+gz+h] = [e f g] [y] + [h]
[z']   [ix+jy+kz+l]   [i j k] [z]   [l]

IOW:
	xyz_ = m[:3,:3] * xyz + m[:3,3:]

(where xyz is a column vector or 3xN array)





More information about the Python-list mailing list