Exemple #1
0
    def test_controlling_orientation(self):
        ref = self.vessel.orbit.body.reference_frame
        root = self.parts.root
        port = self.parts.with_title('Clamp-O-Tron Docking Port')[0]

        # Check vessel direction is in direction of root part
        # and perpendicular to the docking port
        vessel_dir = self.vessel.direction(ref)
        root_dir = root.direction(ref)
        port_dir = port.direction(ref)
        self.assertAlmostEqual(vessel_dir, root_dir, places=2)
        self.assertAlmostEqual(0, dot(vessel_dir, port_dir), places=2)

        # Control from the docking port
        self.parts.controlling = port

        # Check vessel direction is now the direction of the docking port
        vessel_dir = self.vessel.direction(ref)
        self.assertAlmostEqual(0, dot(vessel_dir, root_dir), places=2)
        self.assertAlmostEqual(vessel_dir, port_dir, places=2)

        # Control from the root part
        self.parts.controlling = root

        # Check vessel direction is now the direction of the root part
        vessel_dir = self.vessel.direction(ref)
        self.assertAlmostEqual(vessel_dir, root_dir, places=2)
        self.assertAlmostEqual(0, dot(vessel_dir, port_dir), places=2)
Exemple #2
0
    def test_controlling_orientation(self):
        ref = self.vessel.orbit.body.reference_frame
        root = self.parts.root
        port = self.parts.with_title('Clamp-O-Tron Docking Port')[0]

        # Check vessel direction is in direction of root part
        # and perpendicular to the docking port
        vessel_dir = self.vessel.direction(ref)
        root_dir = root.direction(ref)
        port_dir = port.direction(ref)
        self.assertAlmostEqual(vessel_dir, root_dir, places=2)
        self.assertAlmostEqual(0, dot(vessel_dir, port_dir), places=2)

        # Control from the docking port
        self.parts.controlling = port

        # Check vessel direction is now the direction of the docking port
        vessel_dir = self.vessel.direction(ref)
        self.assertAlmostEqual(0, dot(vessel_dir, root_dir), places=2)
        self.assertAlmostEqual(vessel_dir, port_dir, places=2)

        # Control from the root part
        self.parts.controlling = root

        # Check vessel direction is now the direction of the root part
        vessel_dir = self.vessel.direction(ref)
        self.assertAlmostEqual(vessel_dir, root_dir, places=2)
        self.assertAlmostEqual(0, dot(vessel_dir, port_dir), places=2)
Exemple #3
0
    def test_velocity(self):
        for body in self.space_center.bodies.values():
            if body.orbit is None:
                continue

            # Check body velocity in body's reference frame
            v = body.velocity(body.reference_frame)
            self.assertAlmostEqual((0, 0, 0), v)

            # Check body velocity in parent body's non-rotating reference frame
            v = body.velocity(body.orbit.body.non_rotating_reference_frame)
            self.assertAlmostEqual(body.orbit.speed, norm(v), places=2)

            # Check body velocity in parent body's reference frame
            v = body.velocity(body.orbit.body.reference_frame)
            if body.orbit.inclination == 0:
                self.assertAlmostEqual(0, v[1])
            else:
                self.assertNotAlmostEqual(0, v[1])
            angular_velocity = body.orbit.body.angular_velocity(
                body.orbit.body.non_rotating_reference_frame)
            self.assertAlmostEqual(0, angular_velocity[0])
            self.assertAlmostEqual(0, angular_velocity[2])
            rotational_speed = dot((0, 1, 0), angular_velocity)
            position = list(body.position(body.orbit.body.reference_frame))
            position[1] = 0
            radius = norm(position)
            rotational_speed *= radius
            # TODO: large error
            self.assertAlmostEqual(abs(rotational_speed + body.orbit.speed),
                                   norm(v),
                                   delta=500)
Exemple #4
0
    def test_velocity(self):
        for body in self.space_center.bodies.values():
            if body.orbit is None:
                continue

            # Check body velocity in body's reference frame
            v = body.velocity(body.reference_frame)
            self.assertAlmostEqual((0, 0, 0), v)

            # Check body velocity in parent body's non-rotating reference frame
            v = body.velocity(body.orbit.body.non_rotating_reference_frame)
            self.assertAlmostEqual(body.orbit.speed, norm(v), places=3)

            # Check body velocity in parent body's reference frame
            v = body.velocity(body.orbit.body.reference_frame)
            if body.orbit.inclination == 0:
                self.assertAlmostEqual(0, v[1])
            else:
                self.assertNotAlmostEqual(0, v[1])
            angular_velocity = body.orbit.body.angular_velocity(
                body.orbit.body.non_rotating_reference_frame)
            self.assertAlmostEqual(0, angular_velocity[0])
            self.assertAlmostEqual(0, angular_velocity[2])
            rotational_speed = dot((0, 1, 0), angular_velocity)
            position = list(body.position(body.orbit.body.reference_frame))
            position[1] = 0
            radius = norm(position)
            rotational_speed *= radius
            #TODO: large error
            self.assertAlmostEqual(abs(rotational_speed + body.orbit.speed), norm(v), delta=500)
Exemple #5
0
    def check_directions(self, flight):
        """ Check flight.direction against flight.heading and flight.pitch """
        direction = vector(flight.direction)
        up_direction = (1, 0, 0)
        north_direction = (0, 1, 0)
        self.assertAlmostEqual(1, norm(direction))

        # Check vessel direction vector agrees with pitch angle
        pitch = 90 - rad2deg(math.acos(dot(up_direction, direction)))
        self.assertAlmostEqual(pitch, flight.pitch, delta=2)

        # Check vessel direction vector agrees with heading angle
        up_component = dot(direction, up_direction) * vector(up_direction)
        north_component = normalize(vector(direction) - up_component)
        self.assertDegreesAlmostEqual(
            rad2deg(math.acos(dot(north_component, north_direction))),
            flight.heading, delta=1)
Exemple #6
0
 def check_speeds(self, flight):
     """ Check flight.velocity agrees with flight.*_speed """
     up_direction = (0, 1, 0)
     velocity = vector(flight.velocity)
     vertical_speed = dot(velocity, up_direction)
     horizontal_speed = norm(velocity) - vertical_speed
     self.assertAlmostEqual(norm(velocity), flight.speed, delta=1)
     self.assertAlmostEqual(horizontal_speed, flight.horizontal_speed, delta=1)
     self.assertAlmostEqual(vertical_speed, flight.vertical_speed, delta=1)
Exemple #7
0
 def check_speeds(self, flight):
     """ Check flight.velocity agrees with flight.*_speed """
     up_direction = (0, 1, 0)
     velocity = vector(flight.velocity)
     vertical_speed = dot(velocity, up_direction)
     horizontal_speed = norm(velocity) - vertical_speed
     self.assertAlmostEqual(norm(velocity), flight.speed, delta=1)
     self.assertAlmostEqual(horizontal_speed,
                            flight.horizontal_speed, delta=1)
     self.assertAlmostEqual(vertical_speed,
                            flight.vertical_speed, delta=1)
Exemple #8
0
 def check_orbital_vectors(self, flight):
     """ Check orbital direction vectors """
     prograde = vector(flight.prograde)
     retrograde = vector(flight.retrograde)
     normal = vector(flight.normal)
     anti_normal = vector(flight.anti_normal)
     radial = vector(flight.radial)
     anti_radial = vector(flight.anti_radial)
     self.assertAlmostEqual(1, norm(prograde))
     self.assertAlmostEqual(1, norm(retrograde))
     self.assertAlmostEqual(1, norm(normal))
     self.assertAlmostEqual(1, norm(anti_normal))
     self.assertAlmostEqual(1, norm(radial))
     self.assertAlmostEqual(1, norm(anti_radial))
     self.assertAlmostEqual(tuple(prograde), [-x for x in retrograde], places=2)
     self.assertAlmostEqual(tuple(radial), [-x for x in anti_radial], places=2)
     self.assertAlmostEqual(tuple(normal), [-x for x in anti_normal], places=2)
     self.assertAlmostEqual(0, dot(prograde, radial), places=2)
     self.assertAlmostEqual(0, dot(prograde, normal), places=2)
     self.assertAlmostEqual(0, dot(radial, normal), places=2)
Exemple #9
0
    def check_speed(self, flight, ref):
        up = normalize(vector(self.vessel.position(ref))
                       - vector(self.vessel.orbit.body.position(ref)))
        v = self.vessel.velocity(ref)

        speed = norm(v)
        vertical_speed = dot(v, up)
        horizontal_speed = math.sqrt(speed*speed - vertical_speed*vertical_speed)

        self.assertAlmostEqual(speed, flight.speed, delta=0.5)
        self.assertAlmostEqual(vertical_speed, flight.vertical_speed, delta=0.5)
        self.assertAlmostEqual(horizontal_speed, flight.horizontal_speed, delta=0.5)
Exemple #10
0
 def check_orbital_vectors(self, flight):
     """ Check orbital direction vectors """
     prograde = vector(flight.prograde)
     retrograde = vector(flight.retrograde)
     normal = vector(flight.normal)
     anti_normal = vector(flight.anti_normal)
     radial = vector(flight.radial)
     anti_radial = vector(flight.anti_radial)
     self.assertAlmostEqual(1, norm(prograde))
     self.assertAlmostEqual(1, norm(retrograde))
     self.assertAlmostEqual(1, norm(normal))
     self.assertAlmostEqual(1, norm(anti_normal))
     self.assertAlmostEqual(1, norm(radial))
     self.assertAlmostEqual(1, norm(anti_radial))
     self.assertAlmostEqual(
         tuple(prograde), [-x for x in retrograde], places=2)
     self.assertAlmostEqual(
         tuple(radial), [-x for x in anti_radial], places=2)
     self.assertAlmostEqual(
         tuple(normal), [-x for x in anti_normal], places=2)
     self.assertAlmostEqual(0, dot(prograde, radial), places=2)
     self.assertAlmostEqual(0, dot(prograde, normal), places=2)
     self.assertAlmostEqual(0, dot(radial, normal), places=2)
Exemple #11
0
    def check_speed(self, flight, ref):
        up = normalize(vector(self.vessel.position(ref)) -
                       vector(self.vessel.orbit.body.position(ref)))
        v = self.vessel.velocity(ref)

        speed = norm(v)
        vertical_speed = dot(v, up)
        horizontal_speed = math.sqrt(
            speed*speed - vertical_speed*vertical_speed)

        self.assertAlmostEqual(speed, flight.speed, delta=0.5)
        self.assertAlmostEqual(vertical_speed,
                               flight.vertical_speed, delta=0.5)
        self.assertAlmostEqual(horizontal_speed,
                               flight.horizontal_speed, delta=0.5)
Exemple #12
0
 def check_object_surface_velocity(self, obj, ref):
     if obj.orbit is not None:
         # Check rotational component of velocity same as orbital speed
         v = self.space_center.transform_velocity((0, 0, 0), (0, 0, 0), ref,
                                                  obj.orbit.body.reference_frame)
         #if obj.orbit.inclination == 0:
         #    self.assertAlmostEqual(0, v[1])
         #else:
         #    self.assertNotAlmostEqual(0, v[1])
         angular_velocity = obj.orbit.body.angular_velocity(
             obj.orbit.body.non_rotating_reference_frame)
         self.assertAlmostEqual(0, angular_velocity[0])
         self.assertAlmostEqual(0, angular_velocity[2])
         rotational_speed = dot((0, 1, 0), angular_velocity)
         position = list(obj.position(obj.orbit.body.reference_frame))
         position[1] = 0
         radius = norm(position)
         rotational_speed *= radius
         #TODO: large error
         self.assertAlmostEqual(abs(rotational_speed + obj.orbit.speed), norm(v), delta=200)
Exemple #13
0
 def check_object_surface_velocity(self, obj, ref):
     if obj.orbit is not None:
         # Check rotational component of velocity same as orbital speed
         v = self.space_center.transform_velocity(
             (0, 0, 0), (0, 0, 0), ref, obj.orbit.body.reference_frame)
         # if obj.orbit.inclination == 0:
         #     self.assertAlmostEqual(0, v[1])
         # else:
         #     self.assertNotAlmostEqual(0, v[1])
         angular_velocity = obj.orbit.body.angular_velocity(
             obj.orbit.body.non_rotating_reference_frame)
         self.assertAlmostEqual(0, angular_velocity[0])
         self.assertAlmostEqual(0, angular_velocity[2])
         rotational_speed = dot((0, 1, 0), angular_velocity)
         position = list(obj.position(obj.orbit.body.reference_frame))
         position[1] = 0
         radius = norm(position)
         rotational_speed *= radius
         # TODO: large error
         self.assertAlmostEqual(abs(rotational_speed + obj.orbit.speed),
                                norm(v),
                                delta=200)
Exemple #14
0
 def test_dot(self):
     self.assertAlmostEqual(0, dot((1, 0, 0), (0, 1, 0)))
     self.assertAlmostEqual(1, dot((1, 0, 0), (1, 0, 0)))
Exemple #15
0
 def test_dot(self):
     self.assertAlmostEqual(0, dot((1, 0, 0), (0, 1, 0)))
     self.assertAlmostEqual(1, dot((1, 0, 0), (1, 0, 0)))