I have a list of 3D coordinates:
list={{1., 0., 0.}, {0.987688, 0.156434, 0.},
{0.951057, 0.309017, 0.}, {0.891007, 0.45399, 0.}, {0.809017, 0.587785, 0.}, {0.707107, 0.707107, 0.},
{0.587785,0.809017, 0.}, {0.45399, 0.891007, 0.}, {0.309017, 0.951057, 0.}, {0.156434, 0.987688, 0.},
{0., 1., 0.}, {-0.156434, 0.987688, 0.},
{-0.309017, 0.951057, 0.}, {-0.45399, 0.891007, 0.},
{-0.587785, 0.809017, 0.}, {-0.707107, 0.707107, 0.},
{-0.809017, 0.587785, 0.}, {-0.891007, 0.45399, 0.},
{-0.951057, 0.309017, 0.}, {-0.987688, 0.156434, 0.},
{-1., 0., 0.}}.
I'd like to rotate all the coordinates in the list in one shot, using something like this:
Rotate[list, 180 Degree, {-1, -2, -1}]}} (*Axis angle rotation.*)
I haven't gotten this to work though. I can rotate a single point at a time using a similiar method, but
that is very time consuming.
Question: Is there a way to rotate a list of numerous 3D coordinates such as in my example above, and if so, how do I code that using Mathematica 6.0.1?
Thanks in advance,
Bill
list = {
{1., 0., 0.}, {0.987688, 0.156434, 0.},
{0.951057, 0.309017, 0.}, {0.891007, 0.45399, 0.},
{0.809017, 0.587785, 0.}, {0.707107, 0.707107, 0.},
{0.587785, 0.809017, 0.}, {0.45399, 0.891007, 0.},
{0.309017, 0.951057, 0.}, {0.156434, 0.987688, 0.},
{0., 1., 0.}, {-0.156434, 0.987688, 0.},
{-0.309017, 0.951057, 0.}, {-0.45399, 0.891007, 0.},
{-0.587785, 0.809017, 0.}, {-0.707107, 0.707107, 0.}, {-0.809017,
0.587785, 0.}, {-0.891007, 0.45399, 0.},
{-0.951057, 0.309017, 0.}, {-0.987688, 0.156434, 0.},
{-1., 0., 0.}};
list2 = RotationTransform[180 Degree, {-1, -2, -1}][#] & /@ list;
ListPlot3D[{list, list2}]
Bob Hanlon
---- Bill <WDWNO...@aol.com> wrote:
=============
Rotate is for 2D rotations of graphics and other Mathematica
expressions.
RotationMatrix[180 Degree, {-1, -2, -1}] .# & /@ list
will do the trick.
It's an example of functional programming in which a function which
takes one argument (# defines the slot for the argument and &
indicates that this is a 'pure' function). The function is mapped on
every member of the list (/@ is a shortcut and infix notation for
Map). If you find it more readable you could write it as
Map[
Function[{vec},
RotationMatrix[180 Degree, {-1, -2, -1}] .vec
],
list
]
which is fully equivalent.
Cheers -- Sjoerd
On May 21, 6:06 am, Bill <WDWNORW...@aol.com> wrote:
> Hi:
>
> I have a list of 3D coordinates:
>
> list={{1., 0., 0.}, {0.987688, 0.156434, 0.},
> {0.951057, 0.309017, 0.}, {0.891007, 0.45399, 0.}, {0.809017, 0.587785, 0=
.}, {0.707107, 0.707107, 0.},
> {0.587785,0.809017, 0.}, {0.45399, 0.891007, 0.}, {0.309017, 0.951057, 0.=
}, {0.156434, 0.987688, 0.},
> {0., 1., 0.}, {-0.156434, 0.987688, 0.},
> {-0.309017, 0.951057, 0.}, {-0.45399, 0.891007, 0.},
> {-0.587785, 0.809017, 0.}, {-0.707107, 0.707107, 0.},
> {-0.809017, 0.587785, 0.}, {-0.891007, 0.45399, 0.},
> {-0.951057, 0.309017, 0.}, {-0.987688, 0.156434, 0.},
> {-1., 0., 0.}}.
>
> I'd like to rotate all the coordinates in the list in one shot, using som=
ething like this:
>
> Rotate[list, 180 Degree, {-1, -2, -1}]}} (*Axis angle rotation.*)
>
> I haven't gotten this to work though. I can rotate a single point at a ti=
me using a similiar method, but
> that is very time consuming.
>
> Question: Is there a way to rotate a list of numerous 3D coordinates s=
uch as in my example above, and if so, how do I code that using Mathematica=
Rotate[#, 180 Degree, {-1, -2, -1}] & /@ list
or
Unprotect[Rotate]
Rotate[lst_?MatrixQ,a_,axis_]:=Rotate[#,a,axis] & /@ lst
Protect[Rotate]
Regards
Jens
RotationTransform[180 Degree, {-1, -2, -1}] /@ list
Although RotationTransform does not have the attribute Listable, it still
appears to behave as if it does.
list // RotationTransform[180 Degree, {-1, -2, -1}]
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/
Bill,
If you wish to rotate graphics, use
Graphics3D[Rotate[Point[list], 180 Degree, {-1, -2, -1}]]
If you need the coordinates transformed, use
RotationTransform[180 Degree, {-1, -2, -1}] /@ list
or even
RotationTransform[180 Degree, {-1, -2, -1}][list]
Graphics3D[Rotate[Line[list], 180 =B0, {-1, -2, -1}]]
Graphics3D[Rotate[Point[list], 180 =B0, {-1, -2, -1}]]
If you inspect the output with FullForm you will notice that the
rotation is not resolved by the Kernel, but obviously only the rendering
system will be doing the final rotate. I think this might be much more
efficient.
If you have things that consist of more than just one graphics
primitive, you can rotate them all together by grouping them with a
list, e.g.:
lineandpoints = {Red, Point[list], Opacity[0.5], Black, Line[list]};
Graphics3D[Rotate[lineandpoints,180 Degree, {-1, -2, -1}]]
hth,
albert
w = Normalize@{-1, -1, -1}
l1 = RotationMatrix[180 \[Degree], w].# & /@ list
l2 = list.RotationMatrix[180 \[Degree], w]
l1 == l2
Graphics3D[{
Point[list],
Red, Point[l2],
Green, Line[{{0, 0, 0}, w}],
Blue, Line /@ Transpose[{list, l2}]
}]
Januk
On May 21, 12:06 am, Bill <WDWNORW...@aol.com> wrote:
> Hi:
>
> I have a list of 3D coordinates:
>
> list={{1., 0., 0.}, {0.987688, 0.156434, 0.},
> {0.951057, 0.309017, 0.}, {0.891007, 0.45399, 0.}, {0.809017, 0.587785, 0=
.}, {0.707107, 0.707107, 0.},
> {0.587785,0.809017, 0.}, {0.45399, 0.891007, 0.}, {0.309017, 0.951057, 0.=
}, {0.156434, 0.987688, 0.},
> {0., 1., 0.}, {-0.156434, 0.987688, 0.},
> {-0.309017, 0.951057, 0.}, {-0.45399, 0.891007, 0.},
> {-0.587785, 0.809017, 0.}, {-0.707107, 0.707107, 0.},
> {-0.809017, 0.587785, 0.}, {-0.891007, 0.45399, 0.},
> {-0.951057, 0.309017, 0.}, {-0.987688, 0.156434, 0.},
> {-1., 0., 0.}}.
>
> I'd like to rotate all the coordinates in the list in one shot, using som=
ething like this:
>
> Rotate[list, 180 Degree, {-1, -2, -1}]}} (*Axis angle rotation.*)
>
> I haven't gotten this to work though. I can rotate a single point at a ti=
me using a similiar method, but
> that is very time consuming.
>
> Question: Is there a way to rotate a list of numerous 3D coordinates s=
uch as in my example above, and if so, how do I code that using Mathematica=
Bill,
You can rotate all at once by matrix multiplication using the rotation
matrix. For example, if you wanted to rotate 45 degrees
counterclockwise about the {0,0,1} axis, you would use:
RotationMatrix[\[Pi]/4, {0, 0, 1}].Transpose[list] // Transpose
As long as the dimensions of list are nx3, n can be any positive
integer.
Nick.
There is the function ListPointPlot3D[list] that would generate a 3D
plot that you can easily click & drag to rotate, or you could then use
Rotate, e.g.
ll = ListPointPlot3D[list]
Rotate[ll, 180 Degree]
-Bob
rotate3D[p_, t_, {ax_, ay_, az_}] := Module[
{s,w,x,y,z,m},
s = Sin[t * .5]; (* evaluate terms *)
w = Cos[t * .5];
x = st ax;
y = st ay;
z = st az;
m = {{1-2(y y + z z), 2(x y - w z), 2(w y + x z)},
{ 2(w z + x y), 1-2(x x + z z), 2(y z - w x)},
{ 2(x z - w y), 2(w x + y z), 1-2(x x + y y)}};
If[MatrixQ[p], Map[Chop[Dot[m, #]] &, p], Chop[m.p]]
]
Thank you to all who replied!
Thanks again,
Bill