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,13 +53,21 @@ def quaternion_conjugate(quaternion):
|
||||||
|
|
||||||
|
|
||||||
def rotate_vector(vector, angle, axis=OUT):
|
def rotate_vector(vector, angle, axis=OUT):
|
||||||
quat = quaternion_from_angle_axis(angle, axis)
|
if len(vector) == 2:
|
||||||
quat_inv = quaternion_conjugate(quat)
|
# Use complex numbers...because why not
|
||||||
product = reduce(
|
z = complex(*vector) * np.exp(complex(0, angle))
|
||||||
quaternion_mult,
|
return np.array([z.real, z.imag])
|
||||||
[quat, np.append(0, vector), quat_inv]
|
elif len(vector) == 3:
|
||||||
)
|
# Use quaternions...because why not
|
||||||
return product[1:]
|
quat = quaternion_from_angle_axis(angle, axis)
|
||||||
|
quat_inv = quaternion_conjugate(quat)
|
||||||
|
product = reduce(
|
||||||
|
quaternion_mult,
|
||||||
|
[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):
|
def thick_diagonal(dim, thickness=2):
|
||||||
|
|
Loading…
Add table
Reference in a new issue