def test_trackball__identity(): origin_original = Point3(0., 1., 6.8) trackball = Trackball(origin_original, Point3(0., 1., 0.)) origin_new = trackball.drag(Point2(0, 0)) _assert_vectors_eq(origin_original, origin_new)
def test_transform__identity(): z_axis = Point3(0., 0., 6.8) up = Point3(0, 1, 0) transform = Transform.to_world(z_axis, up) z_axis_new = transform.transform_direction(Point3(0, 0, 1)) _assert_vectors_eq(z_axis.normalized(), z_axis_new)
def spherical_to_cartesian(phi, theta): y = math.cos(theta) x = math.sin(theta) * math.cos(phi) z = math.sin(theta) * math.sin(phi) return Point3(x, y, z)
def drag(self, point): velocity = 0.1 delta = (point - self.anchor) * velocity radians = delta / 180. * math.pi cartesian = coordinates.spherical_to_cartesian(math.pi / 2 - radians.x, math.pi / 2 + radians.y) transform = Transform.to_world((self.origin - self.target), Point3(0, 1, 0)) new_origin_direction = transform.transform_direction(cartesian) return self.target + new_origin_direction * self.radius
def transform_direction(self, direction): x = np.array([direction.x, direction.y, direction.z, 0.]) result = self.data.dot(x) return Point3(*self.data.dot(x)[:3])
def test_cartesian_zero(): cartesian = coordinates.spherical_to_cartesian(math.pi / 2, math.pi / 2) _assert_vectors_eq(cartesian, Point3(0, 0, 1))