def test_translate_vector(): v = Vec3(1, 1, 0) t = Transform(Quat.identity(), Vec3(4, 5, 6)) res = t.translate(v) assert res == Vec3(5, 6, 6)
def test_init_and_eq_and_ne(): t1 = Transform() assert t1.rotation == Quat.identity() assert t1.translation == Vec3.zero() rot = Quat.from_rotation_on_axis(2, np.pi) trans = Vec3(1, 2, 3) t2 = Transform(rot, trans) assert t2.rotation == rot assert t2.translation == trans t3 = Transform.identity() assert t1 == t3 assert t1 != t2 assert t3 != t2
def test_slerp(): q1 = Quat.from_rotation_on_axis(2, -np.pi / 4) q2 = Quat.from_rotation_on_axis(2, np.pi / 4) q3 = q1.slerp(q2, 0.5) q4 = q2.slerp(q1, 0.5) q_true = Quat.identity() assert q3 == q_true assert q4 == q_true q5 = q1.slerp(q2, 0.9) q_true = Quat.from_rotation_on_axis(2, (45 - 9) * np.pi / 180) assert q5 == q_true
def identity(): return Transform(Quat.identity(), Vec3.zero())
def __init__( self, orientation: Quat = Quat.identity(), position: Vec3 = Vec3.zero() ): self.rotation = orientation self.translation = position
def test_identity_constructors(): q1 = Quat.identity() assert q1 == Quat(0, 0, 0, 1)