# How to rotate a vector?

**URL:** <https://blenderartists.org/t/how-to-rotate-a-vector/558311>\
**Category:** Python Support\
**Created:** [November 30, 2012, 3:02pm UTC](https://blenderartists.org/t/how-to-rotate-a-vector/558311 "2012-11-30T15:02:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moshus](https://blenderartists.org/user_avatar/blenderartists.org/moshus/32/928324_2.png) [@moshus](https://blenderartists.org/u/moshus)\
**Post date:** [November 30, 2012, 3:02pm UTC](https://blenderartists.org/t/how-to-rotate-a-vector/558311/1 "2012-11-30T15:02:58Z")

</div>

Hi, everyone out there.

I was starting to play around with the game engine (Blender 2.63) and stumbled into a problem not beeing able to rotate Vector.  
While the Api says there is a function in the vector class which takes two arguments : rotate(axis,angle),  
the Compiler on the other Hand sayed he wanted only one argument in Form of a rotationmatrix.  
Ok, i thougth. Lets do that so i created that Matrix by

rot\_mat = mathutils.Matrix.Rotation( angle, 3, mathutils.Vector( (0, 0, 1) ) )

and tried to rotate the Vector with it

rotated\_vector = vector\_to\_rotate.rotate( rot\_mat )

But after that rotated\_vector is None.

I searched quite while to found a solution, without success.

I would be glad, if someone gives me hint how to do that.

excuse, me for my poor english skills

---

<div class="post-metadata">

**Author:** ![kastoria](https://blenderartists.org/user_avatar/blenderartists.org/kastoria/32/20196_2.png) [@kastoria](https://blenderartists.org/u/kastoria)\
**Post date:** [December 1, 2012, 12:49pm UTC](https://blenderartists.org/t/how-to-rotate-a-vector/558311/2 "2012-12-01T12:49:14Z")

</div>

You can rotate a vector with an Euler, Quaternion, or a Matrix. The results of doing the rotation are applied to the object itself. Try this in the python console.

```auto

&gt;&gt;&gt; mat = Matrix.Rotation(math.pi / 2, 4, "Z")
&gt;&gt;&gt; vec = Vector( (1, 0, 0) )
&gt;&gt;&gt; vec.rotate(mat)
&gt;&gt;&gt; vec

```

Note that the angle is specified in radians. “pi/2” is 90 degrees.

---

<div class="post-metadata">

**Author:** ![moshus](https://blenderartists.org/user_avatar/blenderartists.org/moshus/32/928324_2.png) [@moshus](https://blenderartists.org/u/moshus)\
**Post date:** [December 1, 2012, 3:57pm UTC](https://blenderartists.org/t/how-to-rotate-a-vector/558311/3 "2012-12-01T15:57:24Z")

</div>

Fine, thanks a alot. That did the job.  
I was a bit lazy yesterday while reading the API and didnt recognized the type of the axis given in Matrix.Rotation  
But in case of the vector the Api did not seem to be correct or is has the behaviour of vector changed in 2.64?  
Anyway i now can rotate my vectors.
