Apply rotation matrix to vector + plot it
<p>I have created a vector (v) and would like to perform the rotMatrix function on it. I cannot figure out how to call the function rotMatrix with a degree of 30 on the vector (v). I am also plotting the vectors. </p>

<p>Here is my code: </p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("white")
import math

def rotMatrix(angle):
    return np.array([[np.cos(np.degrees(angle)), np.arcsin(np.degrees(angle))], [np.sin(np.degrees(angle)), np.cos(np.degrees(angle))]])

v = np.array([3,7])
v30 = rotMatrix(np.degrees(30)).dot(v)

plt.arrow(0,0,v[0],v[1], head_width=0.8, head_length=0.8)
plt.arrow(0,0,v30[0],v30[1],head_width=0.8, head_length=0.8)
plt.axis([-5,5,0,10])
plt.show()
</code></pre>

<p>In your rotMatrix function you have used the arcsin() function. You want to use -sin() You should also convert your degrees value to radians</p>

<pre><code>return np.array([[np.cos(np.radians(angle)), 
                       -np.sin(np.radians(angle))],
                 [np.sin(np.radians(angle)),
                        np.cos(np.radians(angle))]])
</code></pre>

<p>Or slightly improve efficiently and readability by </p>

<pre><code>c = np.cos(np.radians(angle))
s = np.sin(np.radians(angle))
return np.array([[c, -s], [s, c]])
</code></pre>

<p>and the call with</p>

<pre><code>rotMatrix(30).dot(v)
</code></pre>

<p>-sin and arcsin are very different.</p>

python numpy matplotlib vector rotational-matrices