def tip_axis(coord: UnitSphericalRepresentation, axis_lon: Angle, rot_angle: Angle) -> UnitSphericalRepresentation: """Perform a rotation about an axis perpendicular to the Z-axis. The purpose of this rotation is to move the pole of the coordinate system from one place to another. For example, transforming from a coordinate system where the pole is aligned with the physical pole of a mount to a topocentric coordinate system where the pole is aligned with zenith. Note that this is a true rotation, and the same rotation is applied to all coordinates in the originating coordinate system equally. It is not equivalent to using SkyCoord directional_offset_by() with a fixed position angle and separation since the direction and magnitude of the offset depend on the value of coord. Args: coord: Coordinate to be transformed. axis_lon: Longitude angle of the axis of rotation. rot_angle: Angle of rotation. Returns: Coordinate after transformation. """ rot = rotation_matrix(rot_angle, axis=SkyCoord(axis_lon, 0 * u.deg).represent_as('cartesian').xyz) coord_cart = coord.represent_as(CartesianRepresentation) coord_rot_cart = coord_cart.transform(rot) return coord_rot_cart.represent_as(UnitSphericalRepresentation)
def ang2vec(theta, phi, lonlat=False): """Drop-in replacement for healpy `~healpy.pixelfunc.ang2vec`.""" lon, lat = _healpy_to_lonlat(theta, phi, lonlat=lonlat) rep_sph = UnitSphericalRepresentation(lon, lat) rep_car = rep_sph.represent_as(CartesianRepresentation) return rep_car.xyz.value
# [-khat.y, khat.x, 0]]) # create 3x3 rotational matrix R using Rodrigues' rotation formula Iden = np.identity(3) K2 = np.matmul(K, K) # right hand rule R = Iden + sintheta*K + (1-np.cos(theta))*K2 # left hand rule testing # R = Iden + np.sin(-theta)*K + (1-np.cos(-theta))*K2 # print('The rotational matrix to rotate cartesian vector A to B is') # print(R) return R J2000R1 = UnitSphericalRepresentation(0*u.deg, 90*u.deg) carJ1 = J2000R1.represent_as(CartesianRepresentation) J2000R2 = UnitSphericalRepresentation(10*u.deg, 90*u.deg) carJ2 = J2000R2.represent_as(CartesianRepresentation) # Note that J2000R1 and J2000R2 give the same (x,y,z) : obviously! # photo op event time used: 2084-11-10T07:53:35 Tref = 2451545 # reference JD for '2000-01-01T12:00:00' Tevent = 2482539.828877315 # photo op event time used: 2084-11-10T07:53:35 MarsRRA = (317.681 - 0.106*(Tevent-Tref)/36525) MarsRDEC = (52.887 - 0.061*(Tevent-Tref)/36525) MarsR = UnitSphericalRepresentation(MarsRRA*u.deg, MarsRDEC*u.deg) carM = MarsR.represent_as(CartesianRepresentation)