def get_frame_rotation_at(self, time): angle = (time - self.epoch ) * self.body.orbit.get_mean_motion() + self.meridian_angle local = LQuaterniond() local.setFromAxisAngleRad(angle, LVector3d.unitZ()) rotation = local * self.get_frame_equatorial_orientation_at(time) return rotation
def __init__(self, position=None, right_asc=0.0, right_asc_unit=units.Deg, declination=0.0, declination_unit=units.Deg, distance=0.0, distance_unit=units.Ly, frame=None): Orbit.__init__(self, frame) if position is None: self.right_asc = right_asc * right_asc_unit self.declination = declination * declination_unit distance = distance * distance_unit else: self.right_asc = None self.declination = None if not isinstance(position, LPoint3d): position = LPoint3d(*position) if position is None: inclination = pi / 2 - self.declination ascending_node = self.right_asc + pi / 2 inclination_quat = LQuaterniond() inclination_quat.setFromAxisAngleRad(inclination, LVector3d.unitX()) ascending_node_quat = LQuaterniond() ascending_node_quat.setFromAxisAngleRad(ascending_node, LVector3d.unitZ()) self.orientation = inclination_quat * ascending_node_quat * J2000EquatorialReferenceFrame.orientation position = self.orientation.xform(LVector3d(0, 0, distance)) self.global_position = position self.position = LPoint3d() self.rotation = LQuaterniond()
def LQuaternionromAxisAngle(axis, angle, angle_units=units.Rad): if isinstance(axis, list): axis = LVector3d(*axis) axis.normalize() rot = LQuaterniond() rot.setFromAxisAngleRad(angle * angle_units, axis) return rot
def calc_orientation_from_incl_an(inclination, ascending_node, flipped=False): inclination_quat = LQuaterniond() if flipped: inclination += pi inclination_quat.setFromAxisAngleRad(inclination, LVector3d.unitX()) ascending_node_quat = LQuaterniond() ascending_node_quat.setFromAxisAngleRad(ascending_node, LVector3d.unitZ()) return inclination_quat * ascending_node_quat
def relative_rotation(rotation, axis, angle): axis.normalize() rel_axis = rotation.xform(axis) delta_quat = LQuaterniond() try: delta_quat.setFromAxisAngleRad(angle, rel_axis) except AssertionError: print("invalid axis", axis, axis.length(), rel_axis, rel_axis.length()) return rotation * delta_quat
def get_rotation_at(self, time): if self.sync: self.period, self.mean_motion = self.body.orbit.getPeriod() if self.period == 0: return LQuaterniond() angle = (time - self.epoch) * self.mean_motion + self.meridian_angle local = LQuaterniond() local.setFromAxisAngleRad(angle, LVector3d.unitZ()) rotation = local * self.get_equatorial_rotation_at(time) return rotation
def align_on_equatorial(self, duration=None): if duration is None: duration = settings.fast_move ecliptic_normal = self.ship._frame_rotation.conjugate().xform(J2000EquatorialReferenceFrame.orientation.xform(LVector3d.up())) angle = acos(ecliptic_normal.dot(LVector3d.right())) direction = ecliptic_normal.cross(LVector3d.right()).dot(LVector3d.forward()) if direction < 0: angle = 2 * pi - angle rot=LQuaterniond() rot.setFromAxisAngleRad(pi / 2 - angle, LVector3d.forward()) self.ship.step_turn(rot, absolute=False)
def do_drag(self, z_angle, x_angle, move=False, rotate=True): zRotation = LQuaterniond() zRotation.setFromAxisAngleRad(z_angle, self.dragZAxis) xRotation = LQuaterniond() xRotation.setFromAxisAngleRad(x_angle, self.dragXAxis) combined = xRotation * zRotation if move: delta = combined.xform(-self.dragDir) self.observer.set_frame_camera_pos(delta + self.dragCenter) self.observer.set_frame_camera_rot(self.dragOrientation * combined) else: self.observer.set_camera_rot(self.dragOrientation * combined)
def do_orbit(self, delta, axis, rate): target = self.ui.selected center = target.get_rel_position_to(self.ship._global_position) center = self.ship.get_rel_position_of(center) relative_pos = self.ship.get_frame_pos() - center rot=LQuaterniond() rot.setFromAxisAngleRad(rate * delta, axis) rot2 = self.ship._frame_rotation.conjugate() * rot * self.ship._frame_rotation rot2.normalize() new_pos = rot2.conjugate().xform(relative_pos) self.ship.set_frame_pos(new_pos + center) self.ship.turn(self.ship._frame_rotation * rot2, absolute=False)
def __init__(self, rotation=None, inclination=0.0, ascending_node=0.0, right_asc=None, right_asc_unit=units.Deg, declination=None, declination_unit=units.Deg, frame=None): Rotation.__init__(self, frame) if rotation is None: if right_asc is None: self.inclination = inclination * math.pi / 180 self.ascending_node = ascending_node * math.pi / 180 inclination_quat = LQuaterniond() inclination_quat.setFromAxisAngleRad(self.inclination, LVector3d.unitX()) ascending_node_quat = LQuaterniond() ascending_node_quat.setFromAxisAngleRad( self.ascending_node, LVector3d.unitZ()) rotation = inclination_quat * ascending_node_quat else: right_asc = right_asc * right_asc_unit declination = declination * declination_unit self.inclination = math.pi / 2 - declination self.ascending_node = right_asc + math.pi / 2 inclination_quat = LQuaterniond() inclination_quat.setFromAxisAngleRad(self.inclination, LVector3d.unitX()) ascending_node_quat = LQuaterniond() ascending_node_quat.setFromAxisAngleRad( self.ascending_node, LVector3d.unitZ()) rotation = inclination_quat * ascending_node_quat self.axis_rotation = rotation self.rotation = LQuaterniond()
def do_drag(self, z_angle, x_angle, move=False, rotate=True): zRotation = LQuaterniond() xRotation = LQuaterniond() try: zRotation.setFromAxisAngleRad(z_angle, self.dragZAxis) xRotation.setFromAxisAngleRad(x_angle, self.dragXAxis) except AssertionError as e: print("Wrong drag axis :", e) combined = xRotation * zRotation if move: delta = combined.xform(-self.dragDir) self.ship.set_frame_pos(delta + self.dragCenter) self.ship.set_frame_rot(self.dragOrientation * combined) else: self.ship.set_rot(self.dragOrientation * combined)
def __init__(self, right_asc=0.0, right_asc_unit=units.Deg, declination=0.0, declination_unit=units.Deg, frame=None): Orbit.__init__(self, frame) self.right_asc = right_asc * right_asc_unit self.declination = declination * declination_unit inclination = pi / 2 - self.declination ascending_node = self.right_asc + pi / 2 inclination_quat = LQuaterniond() inclination_quat.setFromAxisAngleRad(inclination, LVector3d.unitX()) ascending_node_quat = LQuaterniond() ascending_node_quat.setFromAxisAngleRad(ascending_node, LVector3d.unitZ()) self.orientation = inclination_quat * ascending_node_quat * J2000EquatorialReferenceFrame.orientation self.position = LPoint3d() self.rotation = LQuaterniond()
def __init__(self, body=None, right_asc=0.0, right_asc_unit=units.Deg, declination=0.0, declination_unit=units.Deg, longitude_at_node=0.0, longitude_at_nod_units=units.Deg): RelativeReferenceFrame.__init__(self, body) self.right_asc = right_asc * right_asc_unit self.declination = declination * declination_unit self.longitude_at_node = longitude_at_node * longitude_at_nod_units inclination = pi / 2 - self.declination ascending_node = self.right_asc + pi / 2 inclination_quat = LQuaterniond() inclination_quat.setFromAxisAngleRad(inclination, LVector3d.unitX()) ascending_node_quat = LQuaterniond() ascending_node_quat.setFromAxisAngleRad(ascending_node, LVector3d.unitZ()) longitude_quad = LQuaterniond() longitude_quad.setFromAxisAngleRad(self.longitude_at_node, LVector3d.unitZ()) self.orientation = longitude_quad * inclination_quat * ascending_node_quat * J2000EquatorialReferenceFrame.orientation
def update_rotation(self): inclination_quat = LQuaterniond() inclination_quat.setFromAxisAngleRad(self.inclination, LVector3d.unitX()) arg_of_periapsis_quat = LQuaterniond() arg_of_periapsis_quat.setFromAxisAngleRad(self.arg_of_periapsis, LVector3d.unitZ()) ascending_node_quat = LQuaterniond() ascending_node_quat.setFromAxisAngleRad(self.ascending_node, LVector3d.unitZ()) self.rotation = arg_of_periapsis_quat * inclination_quat * ascending_node_quat
def __init__(self, radius, radius_units=units.AU, radial_speed=None, period=None, period_units=units.JYear, inclination=0, ascending_node=0.0, arg_of_periapsis=None, long_of_pericenter=None, mean_anomaly=None, mean_longitude=0.0, epoch=units.J2000, frame=None): Orbit.__init__(self, frame) self.radius = radius * radius_units if radial_speed is None: if period is None: self.mean_motion = 0.0 self.period = 0.0 else: self.period = period * period_units self.mean_motion = 2 * pi / self.period else: self.mean_motion = radial_speed self.period = 2 * pi / self.mean_motion / period_units if arg_of_periapsis is None: if long_of_pericenter is None: arg_of_periapsis = 0.0 else: arg_of_periapsis = long_of_pericenter - ascending_node if inclination == 0.0: #Ascending node is undefined if there is no inclination ascending_node = 0.0 if mean_anomaly is None: mean_anomaly = mean_longitude - (arg_of_periapsis + ascending_node) self.inclination = inclination * pi / 180 self.ascending_node = ascending_node * pi / 180 self.arg_of_periapsis = arg_of_periapsis * pi / 180 self.mean_anomaly = mean_anomaly * pi / 180 self.epoch = epoch inclination_quat = LQuaterniond() inclination_quat.setFromAxisAngleRad(self.inclination, LVector3d.unitX()) arg_of_periapsis_quat = LQuaterniond() arg_of_periapsis_quat.setFromAxisAngleRad(self.arg_of_periapsis, LVector3d.unitZ()) ascending_node_quat = LQuaterniond() ascending_node_quat.setFromAxisAngleRad(self.ascending_node, LVector3d.unitZ()) #self.rotation = ascending_node_quat * inclination_quat * arg_of_periapsis_quat self.rotation = arg_of_periapsis_quat * inclination_quat * ascending_node_quat
def turn(self, angle): new_rotation = LQuaterniond() new_rotation.setFromAxisAngleRad(angle, LVector3d.up()) self.set_rot(new_rotation)
def turn(self, axis, angle): rot = LQuaterniond() rot.setFromAxisAngleRad(angle, axis) self.observer.step_turn_camera(rot, absolute=False)
def turn_relative(self, step): rotation = self.get_rot() delta = LQuaterniond() delta.setFromAxisAngleRad(step, LVector3d.up()) new_rotation = delta * rotation self.set_rot(new_rotation)
def do_rotate(self, delta, axis, rate): rot=LQuaterniond() rot.setFromAxisAngleRad(rate * delta, axis) self.ship.step_turn(rot, absolute=False)
def turn(self, axis, angle): rot=LQuaterniond() rot.setFromAxisAngleRad(angle, axis) self.ship.step_turn(rot, absolute=False)