转换代码如下:
import numpy as np
def rotate_z(angle):
"""Rotation matrix around z-axis by angle (in radians)."""
return np.array([
[np.cos(angle), -np.sin(angle), 0],
[np.sin(angle), np.cos(angle), 0],
[0, 0, 1]
])
def rotate_x(angle):
"""Rotation matrix around x-axis by angle (in radians)."""
return np.array([
[1, 0, 0],
[0, np.cos(angle), -np.sin(angle)],
[0, np.sin(angle), np.cos(angle)]
])
def orbital_to_inertial(r, nu, Omega, i, omega):
"""
Convert from perifocal (orbital) coordinates to inertial coordinates.
Parameters:
r - radial distance
nu - true anomaly (in radians)
Omega - right ascension of the ascending node (in radians)
i - inclination (in radians)
omega - argument of periapsis (in radians)
Returns:
(x, y, z) - inertial coordinates
"""
# Perifocal coordinates
x_prime = r * np.cos(nu)
y_prime = r * np.sin(nu)
z_prime = 0
# Rotation matrices
R_z_Omega = rotate_z(-Omega)
R_x_i = rotate_x(-i)
R_z_omega = rotate_z(-omega)
# Combined rotation matrix
R = R_z_Omega @ R_x_i @ R_z_omega
# Perifocal position vector
r_prime = np.array([x_prime, y_prime, z_prime])
# Inertial position vector
r_inertial = R @ r_prime
return r_inertial
# Example usage
r = 7000 # Example radial distance in km
nu = np.radians(45) # Example true anomaly in radians
Omega = np.radians(30) # Example RAAN in radians
i = np.radians(45) # Example inclination in radians
omega = np.radians(60) # Example argument of periapsis in radians
inertial_coords = orbital_to_inertial(r, nu, Omega, i, omega)
print(f"Inertial coordinates: x = {inertial_coords[0]:.2f} km, y = {inertial_coords[1]:.2f} km, z = {inertial_coords[2]:.2f} km")
通过六根数我们可以得到航天器在近心点下的坐标和速度,由近心点下的状态可 推导航天器在惯性系下的状态,由惯性系下的状态可得轨道六根数。
参考:轨道动力学知识点(二)----近焦点坐标系 - 哔哩哔哩 (bilibili.com)