mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Make sure rotate_vector works on 2d vectors
This commit is contained in:
parent
56f331e8c4
commit
662598fcef
1 changed files with 15 additions and 7 deletions
|
@ -53,6 +53,12 @@ def quaternion_conjugate(quaternion):
|
|||
|
||||
|
||||
def rotate_vector(vector, angle, axis=OUT):
|
||||
if len(vector) == 2:
|
||||
# Use complex numbers...because why not
|
||||
z = complex(*vector) * np.exp(complex(0, angle))
|
||||
return np.array([z.real, z.imag])
|
||||
elif len(vector) == 3:
|
||||
# Use quaternions...because why not
|
||||
quat = quaternion_from_angle_axis(angle, axis)
|
||||
quat_inv = quaternion_conjugate(quat)
|
||||
product = reduce(
|
||||
|
@ -60,6 +66,8 @@ def rotate_vector(vector, angle, axis=OUT):
|
|||
[quat, np.append(0, vector), quat_inv]
|
||||
)
|
||||
return product[1:]
|
||||
else:
|
||||
raise Exception("vector must be of dimension 2 or 3")
|
||||
|
||||
|
||||
def thick_diagonal(dim, thickness=2):
|
||||
|
|
Loading…
Add table
Reference in a new issue