Re: Vector operations,
- To: mathgroup at smc.vnet.net
- Subject: [mg70018] Re: [mg69993] Vector operations,
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Sat, 30 Sep 2006 05:12:52 -0400 (EDT)
- Organization: Mathematics & Statistics, Univ. of Mass./Amherst
- References: <200609291048.GAA22401@smc.vnet.net>
- Reply-to: murray at math.umass.edu
I presume you used:
<<Geometry`Rotations`
Let's take, for example:
mat = RotationMatrix2D[Pi/3];
If you had wanted to rotate a single vector, say
v={1,2}
by that matrix, you would use the dot product:
mat.v
Now the dot infix notation is an abbreviation for the actual function
involved, namely, Dot. That is, the expression "mat.v" is shorthand for:
Dot[mat, v]
So you have a two-argument function Dot that you want to use with a
fixed first argument (mat) but various second arguments. The standard
way to handle this in Mathematica is to form a pure function like this:
Dot[mat, #]&
(That's a nameless function that dots things with mat.)
Finally, to cause this function to act upon each of the vectors in a
list of vectors such as....
vectors = {{1/2, 1/2}, {1, 0}, {0, 1}, {0, 0}};
use the function Map:
Map[Dot[mat, #]&, vectors]
The result will be the desired list of rotated vectors.
One more thing, to avoid the nested brackets, you can use the
abbreviation func /@ lis instead of Map[func, lis]. With this
abbreviation, then, the desired expression to rotate all the vectors is:
Dot[mat, #]& /@ vectors
Of course if you're going to be repeatedly rotating vectors by the same
angle, you may want to define a function to do it:
rot[vec_] := mat.vec
Then to rotate all the vectors in the list at once:
Map[rot, vectors]
or, abbreviated:
rot /@ vectors
Isn't that nice!
mickey wrote:
> Hi,
>
> I have a list of vectors such as
>
> {{1/2, 1/2}, {1, 0}, {0, 1}, {0, 0}}
>
> I want to rotate them all by the same angle. Right now, what I do is
> multiply each by RotationMatrix2D[t] and iterate over the list. Is there
> a more efficient way to do this?
>
> Thanks,
> -M
>
>
--
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
- References:
- Vector operations,
- From: mickey <micky@hotmail.com>
- Vector operations,