This code is intended to plot a cone projection but the result is self-inconsistent (it…
- User
This code is intended to plot a cone projection but the result is self-inconsistent (it is a drawing of a cone but not a projection). Improve it to represent actual projection of a 3-dimensional cone with given parameters.
Define cone parameters
cone_top = SkyCoord('7h28m43s 69d11m24s', frame='icrs') # Cone top (apex) as SkyCoord cone_base_center = SkyCoord('7h28m38s 69d12m28s', frame='icrs') # Cone base center as SkyCoord cone_opening_angle = 20 * u.deg # Opening angle of the cone cone_orientation = 5 * u.deg # In-plane orientation angle cone_inclination = 30 * u.deg # Tilt relative to the plane of the sky
Load WCS for the image (assumed to be already defined)
wcs = WCS(HD(h_ha))
def rotate_coordinates(x, y, angle): """Rotate coordinates by a given angle in degrees.""" angle_rad = np.deg2rad(angle) x_rot = x * np.cos(angle_rad) - y * np.sin(angle_rad) y_rot = x * np.sin(angle_rad) + y * np.cos(angle_rad) return x_rot, y_rot
def cone_base_vertices(cone_base_center, radius, inclination, orientation, num_points=100): """ Generate vertices for the cone's base, projected onto the sky. Inclination and orientation are applied to the base's projection. """ angles = np.linspace(0, 2 * np.pi, num_points)
code# Initial circular base vertices before projection offsets_ra = radius * np.cos(angles) / np.cos(cone_base_center.dec.radian) offsets_dec = radius * np.sin(angles) # Apply inclination by scaling the DEC offsets (flattening the base ellipse) offsets_dec_inclined = offsets_dec * np.cos(inclination.to(u.radian)) # Rotate the base by the orientation angle offsets_ra_rot, offsets_dec_rot = rotate_coordinates(offsets_ra, offsets_dec_inclined, orientation) # Convert to SkyCoord object for the cone base vertices base_vertices = SkyCoord(ra=cone_base_center.ra + offsets_ra_rot * u.deg, dec=cone_base_center.dec + offsets_dec_rot * u.deg) return base_verticesCompute the base radius based on the cone's opening angle and distance from top to base
cone_base_radius = (np.tan(cone_opening_angle.to(u.radian)) * cone_base_center.separation(cone_top)).to(u.deg)
Generate the base vertices after applying the inclination and orientation
cone_base = cone_base_vertices(cone_base_center, cone_base_radius.deg, cone_inclination, cone_orientation)
- Assistant