Example #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.assertClose(vessel_dir, root_dir)
        self.assertClose(0, dot(vessel_dir, port_dir))

        # 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.assertClose(0, dot(vessel_dir, root_dir))
        self.assertClose(vessel_dir, port_dir)

        # 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.assertClose(vessel_dir, root_dir)
        self.assertClose(0, dot(vessel_dir, port_dir))
Example #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.assertClose(vessel_dir, root_dir)
        self.assertClose(0, dot(vessel_dir, port_dir))

        # 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.assertClose(0, dot(vessel_dir, root_dir))
        self.assertClose(vessel_dir, port_dir)

        # 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.assertClose(vessel_dir, root_dir)
        self.assertClose(0, dot(vessel_dir, port_dir))
Example #3
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.assertClose(1, norm(direction))

        # Check vessel direction vector agrees with pitch angle
        pitch = 90 - rad2deg(math.acos(dot(up_direction, direction)))
        self.assertClose(flight.pitch, pitch, error=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.assertCloseDegrees(flight.heading, rad2deg(math.acos(dot(north_component, north_direction))), error=1)
Example #4
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.assertClose(1, norm(direction))

        # Check vessel direction vector agrees with pitch angle
        pitch = 90 - rad2deg(math.acos(dot(up_direction, direction)))
        self.assertClose(flight.pitch, pitch, error=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.assertCloseDegrees(flight.heading, rad2deg(math.acos(dot(north_component, north_direction))), error=1)
Example #5
0
    def test_velocity(self):
        for body in self.conn.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.assertClose((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)
            if body.orbit.inclination == 0:
                self.assertClose(0, v[1])
            else:
                self.assertNotClose(0, v[1])
            self.assertClose(body.orbit.speed, norm(v))

            # Check body velocity in parent body's reference frame
            v = body.velocity(body.orbit.body.reference_frame)
            if body.orbit.inclination == 0:
                self.assertClose(0, v[1])
            else:
                self.assertNotClose(0, v[1])
            angular_velocity = body.orbit.body.angular_velocity(body.orbit.body.non_rotating_reference_frame)
            self.assertClose(0, angular_velocity[0])
            self.assertClose(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.assertClose(abs(rotational_speed + body.orbit.speed), norm(v), error=200)
Example #6
0
    def test_velocity(self):
        for body in self.conn.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.assertClose((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.assertClose(body.orbit.speed, norm(v))

            # Check body velocity in parent body's reference frame
            v = body.velocity(body.orbit.body.reference_frame)
            if body.orbit.inclination == 0:
                self.assertClose(0, v[1])
            else:
                self.assertNotClose(0, v[1])
            angular_velocity = body.orbit.body.angular_velocity(
                body.orbit.body.non_rotating_reference_frame)
            self.assertClose(0, angular_velocity[0])
            self.assertClose(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.assertClose(abs(rotational_speed + body.orbit.speed),
                             norm(v),
                             error=200)
Example #7
0
    def shadow(self, n):
        '''Retorna as coordenadas da sombra na direção n dada.
        Assume n normalizado.'''

        p0 = dot(self.pos, n)
        r = self.radius
        return (p0 - r, p0 + r)
Example #8
0
    def shadow(self, n):
        '''Retorna as coordenadas da sombra na direção n dada.
        Assume n normalizado.'''

        p0 = dot(self.pos, n)
        r = self.radius
        return (p0 - r, p0 + r)
Example #9
0
 def check_speeds(self, flight):
     up_direction = vector(flight.up_direction)
     velocity = vector(flight.velocity)
     vertical_speed = dot(velocity, up_direction)
     horizontal_speed = norm(velocity) - vertical_speed
     self.assertClose(norm(velocity), flight.speed, error=1)
     self.assertClose(horizontal_speed, flight.horizontal_speed, error=1)
     self.assertClose(vertical_speed, flight.vertical_speed, error=1)
Example #10
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.assertClose(norm(velocity), flight.speed, error=1)
     self.assertClose(horizontal_speed, flight.horizontal_speed, error=1)
     self.assertClose(vertical_speed, flight.vertical_speed, error=1)
Example #11
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.assertClose(norm(velocity), flight.speed, error=1)
     self.assertClose(horizontal_speed, flight.horizontal_speed, error=1)
     self.assertClose(vertical_speed, flight.vertical_speed, error=1)
Example #12
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 = speed - abs(vertical_speed)

        self.assertClose(speed, flight.speed, error=0.5)
        self.assertClose(vertical_speed, flight.vertical_speed, error=0.5)
        self.assertClose(horizontal_speed, flight.horizontal_speed, error=0.5)
Example #13
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.assertClose(1, norm(prograde))
     self.assertClose(1, norm(retrograde))
     self.assertClose(1, norm(normal))
     self.assertClose(1, norm(anti_normal))
     self.assertClose(1, norm(radial))
     self.assertClose(1, norm(anti_radial))
     self.assertClose(prograde, [-x for x in retrograde], error=0.01)
     self.assertClose(radial, [-x for x in anti_radial], error=0.01)
     self.assertClose(normal, [-x for x in anti_normal], error=0.01)
     self.assertClose(0, dot(prograde, radial), error=0.01)
     self.assertClose(0, dot(prograde, normal), error=0.01)
     self.assertClose(0, dot(radial, normal), error=0.01)
Example #14
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.assertClose(speed, flight.speed, error=0.5)
        self.assertClose(vertical_speed, flight.vertical_speed, error=0.5)
        self.assertClose(horizontal_speed, flight.horizontal_speed, error=0.5)
Example #15
0
 def check_orbital_vectors(self, flight):
     # Check orbital direction vectors
     prograde    = vector(flight.prograde)
     retrograde  = vector(flight.retrograde)
     normal      = vector(flight.normal)
     normal_neg  = vector(flight.normal_neg)
     radial      = vector(flight.radial)
     radial_neg  = vector(flight.radial_neg)
     self.assertClose(1, norm(prograde))
     self.assertClose(1, norm(retrograde))
     self.assertClose(1, norm(normal))
     self.assertClose(1, norm(normal_neg))
     self.assertClose(1, norm(radial))
     self.assertClose(1, norm(radial_neg))
     self.assertClose(prograde, [-x for x in retrograde], error=0.01)
     self.assertClose(radial, [-x for x in radial_neg], error=0.01)
     self.assertClose(normal, [-x for x in normal_neg], error=0.01)
     self.assertClose(0, dot(prograde, radial), error=0.01)
     self.assertClose(0, dot(prograde, normal), error=0.01)
     self.assertClose(0, dot(radial, normal), error=0.01)
Example #16
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.assertClose(1, norm(prograde))
     self.assertClose(1, norm(retrograde))
     self.assertClose(1, norm(normal))
     self.assertClose(1, norm(anti_normal))
     self.assertClose(1, norm(radial))
     self.assertClose(1, norm(anti_radial))
     self.assertClose(prograde, [-x for x in retrograde], error=0.01)
     self.assertClose(radial, [-x for x in anti_radial], error=0.01)
     self.assertClose(normal, [-x for x in anti_normal], error=0.01)
     self.assertClose(0, dot(prograde, radial), error=0.01)
     self.assertClose(0, dot(prograde, normal), error=0.01)
     self.assertClose(0, dot(radial, normal), error=0.01)
Example #17
0
    def check_directions(self, flight, check_against_orbital=True):
        direction       = vector(flight.direction)
        up_direction    = vector(flight.up_direction)
        north_direction = vector(flight.north_direction)
        self.assertClose(1, norm(direction))
        self.assertClose(1, norm(up_direction))
        self.assertClose(1, norm(north_direction))
        self.assertClose(0, dot(up_direction, north_direction))

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

        # Check vessel direction vector agrees with heading angle
        up_component = dot(direction, up_direction) * vector(up_direction)
        north_component = vector(direction) - up_component
        north_component = north_component / norm(north_component)
        self.assertClose(flight.heading, rad2deg(math.acos(dot(north_component, north_direction))), error=1)

        if check_against_orbital == True:
            # Check vessel directions agree with orbital directions
            # (we are in a 0 degree inclined orbit, so they should do)
            self.assertClose(1, dot(up_direction, vector(flight.radial)))
            self.assertClose(1, dot(north_direction, vector(flight.normal)))
Example #18
0
 def shadow(self, n):
     if abs(dot(self.tangent(), n)) < 1e-6:
         p = dot(self.p1, n)
         return p, p
     else:
         return [-Inf, Inf]
Example #19
0
    def shadow(self, n):
        """Retorna as coordenadas da sombra na direção n dada.
        Assume n normalizado."""

        points = [dot(n, p) for p in self.vertices]
        return min(points), max(points)
Example #20
0
    def shadow(self, n):
        '''Retorna as coordenadas da sombra na direção n dada.
        Assume n normalizado.'''

        points = [dot(n, p) for p in self.vertices]
        return min(points), max(points)