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)
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)
def test_set_magnitude(self): node = self.control.add_node(self.space_center.ut, 1, -2, 3) magnitude = 128 node.delta_v = magnitude delta_v = vector(normalize((1, -2, 3))) * magnitude self.check(node, delta_v) node.remove()
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)
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)
def test_flight_orbit_body_non_rotating_reference_frame(self): ref = self.vessel.orbit.body.non_rotating_reference_frame flight = self.vessel.flight(ref) self.check_properties_not_affected_by_reference_frame(flight) speed = 2245.75 self.assertAlmostEqual(speed, norm(flight.velocity), delta=0.5) position = self.vessel.position(ref) direction = vector(cross(normalize(position), (0, 1, 0))) velocity = direction * speed self.assertAlmostEqual(tuple(velocity), flight.velocity, delta=2) self.assertAlmostEqual(speed, flight.speed, delta=0.5) self.assertAlmostEqual(speed, flight.horizontal_speed, delta=0.5) self.assertAlmostEqual(0, flight.vertical_speed, delta=0.5) self.check_speeds(flight) self.check_orbital_vectors(flight)
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)
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)