This is how I always do it:<div><br></div><div><div>In [1]: import numpy as np</div><div><br></div><div>In [3]: tmat = np.array([[0., 1., 0., 5.],[0., 0., 1., 3.],[1., 0., 0., 2.]])</div><div><br></div><div>In [4]: tmat</div>
<div>Out[4]:</div><div>array([[ 0.,  1.,  0.,  5.],</div><div>           [ 0.,  0.,  1.,  3.],</div><div>           [ 1.,  0.,  0.,  2.]])</div><div><br></div><div>In [5]: points = np.random.random((5, 3))</div><div><br></div>
<div>In [7]: hpoints = np.column_stack((points, np.ones(len(points))))</div><div><br></div><div>In [9]: hpoints</div><div>Out[9]:</div><div>array([[ 0.17437059,  0.38693627,  0.201047  ,  1.        ],</div><div>       [ 0.99712373,  0.16958721,  0.03050696,  1.        ],</div>
<div>       [ 0.30653326,  0.62037744,  0.35785282,  1.        ],</div><div>       [ 0.78936771,  0.93692711,  0.58138493,  1.        ],</div><div>       [ 0.29914065,  0.08808239,  0.72032172,  1.        ]])</div><div><br>
</div><div>In [10]: np.dot(tmat, hpoints.T).T</div><div>Out[10]:</div><div>array([[ 5.38693627,  3.201047  ,  2.17437059],</div><div>       [ 5.16958721,  3.03050696,  2.99712373],</div><div>       [ 5.62037744,  3.35785282,  2.30653326],</div>
<div>       [ 5.93692711,  3.58138493,  2.78936771],</div><div>       [ 5.08808239,  3.72032172,  2.29914065]])</div><div><br></div><br><div class="gmail_quote">On Mon, Mar 1, 2010 at 6:12 AM, Friedrich Romstedt <span dir="ltr"><<a href="mailto:friedrichromstedt@gmail.com">friedrichromstedt@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">2010/3/1 Charles R Harris <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>>:<br>
<div class="im">> On Sun, Feb 28, 2010 at 7:58 PM, Ian Mallett <<a href="mailto:geometrian@gmail.com">geometrian@gmail.com</a>> wrote:<br>
</div><div class="im">>> Excellent--and a 3D rotation matrix is 3x3--so the list can remain n*3.<br>
>> Now the question is how to apply a rotation matrix to the array of vec3?<br>
><br>
> It looks like you want something like<br>
><br>
> res = dot(vec, rot) + tran<br>
><br>
> You can avoid an extra copy being made by separating the parts<br>
><br>
> res = dot(vec, rot)<br>
> res += tran<br>
><br>
> where I've used arrays, not matrices. Note that the rotation matrix<br>
> multiplies every vector in the array.<br>
<br>
</div>When you want to rotate a ndarray "list" of vectors:<br>
<br>
>>> a.shape<br>
(N, 3)<br>
<br>
>>> a<br>
[[1., 2., 3. ]<br>
 [4., 5., 6. ]]<br>
<br>
by some rotation matrix:<br>
<br>
>>> rotation_matrix.shape<br>
(3, 3)<br>
<br>
where each row of the rotation_matrix represents one vector of the<br>
rotation target basis, expressed in the basis of the original system,<br>
<br>
you can do this by writing:<br>
<br>
>>> numpy.dot(a, rotations_matrix)  ,<br>
<br>
as Chuck pointed out.<br>
<br>
This gives you the rotated vectors in an ndarray "list" again:<br>
<br>
>>> numpy.dot(a, rotation_matrix).shape<br>
(N, 3)<br>
<br>
This is just somewhat more in detail what Chuck already stated<br>
<div class="im">> Note that the rotation matrix<br>
> multiplies every vector in the array.<br>
<br>
</div>my 2 cents,<br>
<font color="#888888">Friedrich<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br></div>