def calculate_local_north_and_up_in_celestial_coords(self, force_update): current_time = self.get_time_in_millis() diff = math.fabs(current_time - self.celestial_coords_last_updated) if (not force_update) and diff < self.MINIMUM_TIME_BETWEEN_CELESTIAL_COORD_UPDATES_MILLIS: return self.celestial_coords_last_updated = current_time self.update_magnetic_correction() up_ra, up_dec = Geometry.calculate_RADec_of_zenith(self.get_time(), self.location) self.up_celestial = get_instance(up_ra, up_dec) z = self.AXIS_OF_EARTHS_ROTATION z_dotu = Geometry.scalar_product(self.up_celestial, z) self.true_north_celestial = \ Geometry.add_vectors(z, Geometry.scale_vector(self.up_celestial, -z_dotu)) self.true_north_celestial.normalize() self.true_east_celestial = Geometry.vector_product(self.true_north_celestial, \ self.up_celestial) # Apply magnetic correction. Rather than correct the phone's axes for # the magnetic declination, it's more efficient to rotate the # celestial axes by the same amount in the opposite direction. declination = self.magnetic_declination_calc.get_declination() rotation_matrix = Geometry.calculate_rotation_matrix(declination, self.up_celestial) magnetic_north_celestial = Geometry.matrix_vector_multiply(rotation_matrix, \ self.true_north_celestial) magnetic_east_celestial = Geometry.vector_product(magnetic_north_celestial, \ self.up_celestial) self.axes_magnetic_celestial_matrix = get_colmatrix_from_vectors(magnetic_north_celestial, \ self.up_celestial, \ magnetic_east_celestial)
def calculate_pointing(self): ''' update the direction that the phone is pointing and the up vector perpendicular to the phone (in celestial coords). ''' if not (self.auto_update_pointing): return transform = Geometry.matrix_multiply(self.axes_magnetic_celestial_matrix, \ self.axes_phone_inverse_matrix) view_in_space_space = \ Geometry.matrix_vector_multiply(transform, self.POINTING_DIR_IN_PHONE_COORDS) screen_up_in_space_space = \ Geometry.matrix_vector_multiply(transform, self.SCREEN_UP_IN_PHONE_COORDS) self.pointing.update_line_of_sight(view_in_space_space) self.pointing.update_perpendicular(screen_up_in_space_space)
def rotate(self, degrees): ''' rotate astronomers view (clockwise/anti-clockwise) ''' if not self.enabled: return pointing = self.model.pointing pointing_xyz = pointing.get_line_of_sight() top_xyz = pointing.get_perpendicular() rotation = Geometry.calculate_rotation_matrix(degrees, pointing_xyz) new_up_xyz = Geometry.matrix_vector_multiply(rotation, top_xyz) new_up_xyz.normalize() self.model.set_pointing(pointing_xyz, new_up_xyz)