Various common coordinate systems

Table of contents

1. Latitude and longitude coordinate system

2. Earth-centered and Earth-fixed coordinate system

Convert the coordinates in the longitude-latitude coordinate system to the coordinates in the earth-centered fixed coordinate system ECEF

3. The Earth's Inertial Coordinate System

4. Satellite position calculation

5. Northeast Celestial Coordinate System

J2000 to Northeast Day

The center of the earth is fixed to the northeast sky

6. Attitude angle solution 

7. Calculate the Julian day at a certain time


1. Latitude and longitude coordinate system

The latitude-longitude coordinate system is a geographic coordinate system used to describe the coordinates of any location on the Earth's surface. It is based on the rotation of the earth and the division of the equator.

Longitude represents the east-west position of a point on the Earth's surface relative to the Prime Meridian. Longitude is measured in degrees (°), ranging from 0° to 180°, with positive values ​​for east longitude and negative values ​​for west longitude. The prime meridian is located at the Royal Greenwich Observatory in London, England, and it is defined as longitude 0°.

Latitude represents the north-south position of a point on the Earth's surface relative to the equator. The unit of measure for latitude is also degrees (°), ranging from 0° to 90°, with positive values ​​for north latitude and negative values ​​for south latitude. The equator is at latitude 0°.

The latitude-longitude coordinate system uses a combination of longitude and latitude to identify a specific location on the Earth's surface. The latitude and longitude coordinates of a point are expressed as a combination of two values, for example: 40°N, 120°E means the position at 40° north latitude and 120° east longitude.

The latitude and longitude coordinate system is a global geographic coordinate system widely used in navigation, map making, geographic information system (GIS) and other fields.

2. Earth-centered and Earth-fixed coordinate system

Geocentric Cartesian Coordinate System (Geocentric Cartesian Coordinate System) is a coordinate system used to describe the position and orientation on the earth. It is a Cartesian coordinate system in which the center of the Earth is defined as the origin and three coordinate axes are fixed on the Earth and aligned with the Earth's axis of rotation.

In an earth-centered earth-fixed coordinate system, the three coordinate axes are usually defined as follows:

  1. X-axis: through the origin and the meridian at 0 degrees longitude (usually the prime meridian through London, UK).
  2. Y-axis: through the origin, the equator with a latitude of 0 degrees, perpendicular to the X-axis.
  3. Z axis: Aligned with the earth's rotation axis, pointing to the earth's north pole, perpendicular to the XY plane.

Using this coordinate system, the position of any point on Earth can be accurately described. For example, given a longitude, latitude, and altitude (relative to sea level), the three-dimensional coordinates of a point in an earth-centered, ground-fixed coordinate system can be determined. This is important for areas such as navigation, geographic information systems (GIS), map making, and astronomy.

It should be noted that the earth-centered earth-fixed coordinate system is a fixed coordinate system relative to the earth , not an inertial coordinate system relative to the sun or other celestial bodies. It is mainly used for measurement and positioning on the earth's surface, while in space, other coordinate systems are usually used, such as the celestial coordinate system defined by the International Astronomical Union.

Convert the coordinates in the longitude-latitude coordinate system to the coordinates in the earth-centered fixed coordinate system ECEF

(Calculations are performed using ellipsoid parameters and coordinate transformation formulas.)

import math

# 地球椭球体参数
a = 6378137.0  # 长半轴
f = 1 / 298.257223563  # 扁率

def deg2rad(deg):
    return deg * (math.pi / 180)

def geodetic_to_geocentric(latitude, longitude, altitude):
    # 将纬度、经度、高度转换为弧度
    lat_rad = deg2rad(latitude)
    lon_rad = deg2rad(longitude)

    # 计算地球椭球体上的参数
    b = a * (1 - f)  # 短半轴
    e_squared = 1 - (b**2) / (a**2)  # 第一偏心率的平方

    # 计算地球椭球体上的坐标
    N = a / math.sqrt(1 - e_squared * (math.sin(lat_rad)**2))
    X = (N + altitude) * math.cos(lat_rad) * math.cos(lon_rad)
    Y = (N + altitude) * math.cos(lat_rad) * math.sin(lon_rad)
    Z = (N * (1 - e_squared) + altitude) * math.sin(lat_rad)

    return X, Y, Z

# 示例坐标:纬度为40.7128度,经度为-74.0060度,海拔高度为0米(纽约市)
latitude = 40.7128
longitude = -74.0060
altitude = 0

x, y, z = geodetic_to_geocentric(latitude, longitude, altitude)

print("X坐标:", x)
print("Y坐标:", y)
print("Z坐标:", z)

3. The Earth's Inertial Coordinate System

The Earth's inertial coordinate system is a reference coordinate system used to describe the Earth's motion in the universe. It is a coordinate system with the earth's center of mass as its origin , and its coordinate axes are related to the earth's rotation axis and revolution axis.

In the Earth's inertial coordinate system, the Earth's axis of rotation is defined as the Z-axis of the coordinate system, which corresponds to the direction of the Earth's North Pole. The X-axis is tangent to the direction of the vernal equinox and points to a fixed point in Earth's orbit. The Y-axis is perpendicular to the X-axis and Z-axis, forming a right-handed coordinate system with them.

The Earth's inertial coordinate system is a non-rotating coordinate system that remains fixed as the Earth rotates and revolves. Therefore, using the earth's inertial coordinate system can conveniently describe physical and astronomical phenomena on the earth, as well as applications related to the earth such as navigation, positioning, and remote sensing.

It should be noted that the earth's inertial coordinate system does not take into account the movement of the earth's crust, changes in the earth's rotation, and other geodynamic effects. It is mainly used to study the macroscopic motion of the earth and phenomena related to earth motion.

The J2000 coordinate system is an inertial coordinate system defined at 12 o'clock on January 1, 2000 (Greenwich Mean Time). The coordinate axes of the J2000 coordinate system are related to the earth's rotation axis and revolution axis, similar to the earth's inertial coordinate system. Its X axis points in the direction of the vernal equinox, its Z axis corresponds to the Earth's rotation axis, and its Y axis is perpendicular to the X and Z axes . The J2000 coordinate system is widely used in the fields of astronomy and aerospace.

The earth inertial coordinate system can be regarded as a special case of the J2000 coordinate system, which is an inertial coordinate system centered on the earth. In the Earth's inertial coordinate system, the Earth's axis of rotation is defined as the Z axis, which corresponds to the direction of the Earth's North Pole. The X-axis is tangent to the direction of the equinoxes and points to a fixed point in Earth's orbit. The Y axis is perpendicular to the X and Z axes, forming a right-handed coordinate system.

import math

# 输入地心固定坐标系下的点坐标
geocentric_x = 1333998.456149258
geocentric_y = -4654044.842733645
geocentric_z = 4138300.2386952764

# 输入当前时间(以儒略日表示)
current_jd = 2459345.0

# 计算格林尼治恒星时角(以弧度表示)
def calculate_greenwich_sidereal_time(jd):
    # 计算儒略世纪数
    T = (jd - 2451545.0) / 36525.0

    # 计算格林尼治恒星时角(以弧度表示)
    GST = (100.46061837 + 36000.770053608 * T + 0.000387933 * T**2 - (T**3 / 38710000.0)) * (math.pi / 180.0)

    # 将格林尼治恒星时角限制在0到2π之间
    GST = GST % (2 * math.pi)

    return GST

# 将地心固定坐标系下的点坐标转换为J2000坐标系下的坐标
def convert_to_j2000_coordinates(x, y, z, gst):
    # 定义J2000坐标系的旋转矩阵
    rotation_matrix = [
        [math.cos(gst), -math.sin(gst), 0],
        [math.sin(gst), math.cos(gst), 0],
        [0, 0, 1]
    ]

    # 进行矩阵乘法,得到J2000坐标系下的坐标
    j2000_x = rotation_matrix[0][0] * x + rotation_matrix[0][1] * y + rotation_matrix[0][2] * z
    j2000_y = rotation_matrix[1][0] * x + rotation_matrix[1][1] * y + rotation_matrix[1][2] * z
    j2000_z = rotation_matrix[2][0] * x + rotation_matrix[2][1] * y + rotation_matrix[2][2] * z

    return j2000_x, j2000_y, j2000_z

# 计算格林尼治恒星时角
gst = calculate_greenwich_sidereal_time(current_jd)

# 将地心固定坐标系下的点坐标转换为J2000坐标系下的坐标
j2000_x, j2000_y, j2000_z = convert_to_j2000_coordinates(geocentric_x, geocentric_y, geocentric_z, gst)

# 输出J2000坐标系下的坐标
print("J2000 X:", j2000_x)
print("J2000 Y:", j2000_y)
print("J2000 Z:", j2000_z)
import datetime

# 获取当前日期和时间
current_date_time = datetime.datetime.now()

# 计算儒略日的函数
def calculate_julian_day(year, month, day, hour, minute, second):
    if month <= 2:
        year -= 1
        month += 12

    a = year // 100
    b = a // 4
    c = 2 - a + b
    e = 365.25 * (year + 4716)
    f = 30.6001 * (month + 1)

    jd = c + day + e + f - 1524.5 + (hour + minute / 60.0 + second / 3600.0) / 24.0

    return jd

# 提取当前日期和时间的年、月、日、时、分、秒
year = current_date_time.year
month = current_date_time.month
day = current_date_time.day
hour = current_date_time.hour
minute = current_date_time.minute
second = current_date_time.second

# 计算当前时间的儒略日
current_jd = calculate_julian_day(year, month, day, hour, minute, second)

# 输出当前时间的儒略日
print("Current Julian Day:", current_jd)

4. Satellite position calculation

import datetime
import math

# 常数定义
MU = 3.986005e14  # 地球引力常数
OMEGA_E_DOT = 7.2921151467e-5  # 地球自转角速度(rad/s)

# 将角度转换为弧度
def deg2rad(deg):
    return deg * math.pi / 180.0

# 将弧度转换为角度
def rad2deg(rad):
    return rad * 180.0 / math.pi

# 计算矢量点积
def dot(a, b):
    return sum([a[i] * b[i] for i in range(3)])

# 计算矢量差
def diff(a, b):
    return [a[i] - b[i] for i in range(3)]

# 计算矢量叉积
def cross(a, b):
    return [
        a[1] * b[2] - a[2] * b[1],
        a[2] * b[0] - a[0] * b[2],
        a[0] * b[1] - a[1] * b[0]
    ]

# 计算向量模长
def norm(a):
    return math.sqrt(dot(a, a))

# 计算轨道的其他参数
def compute_orbital_params(a, e, i, RAAN, arg_per, M, t, t0):
    # 计算平均角速度
    n = math.sqrt(MU / a ** 3)

    # 计算时间差
    dt = (t - t0).total_seconds()

    # 计算平近点角
    M = M + n * dt

    # 利用Kepler方程求解偏近点角
    E = M
    for _ in range(10):
        E = M + e * math.sin(E)

    # 计算真近点角
    v = 2 * math.atan(math.sqrt((1 + e) / (1 - e)) * math.tan(E / 2))

    # 计算升交点赤经
    RAAN = RAAN + (OMEGA_E_DOT * dt)

    # 计算卫星位置矢量
    r = a * (1 - e * math.cos(E))
    x = r * 1000.0 * (math.cos(RAAN) * math.cos(v + arg_per) - math.sin(RAAN) * math.sin(v + arg_per) * math.cos(i))
    y = r * 1000.0 * (math.sin(RAAN) * math.cos(v + arg_per) + math.cos(RAAN) * math.sin(v + arg_per) * math.cos(i))
    z = r * 1000.0 * (math.sin(i) * math.sin(v + arg_per))

    # 返回卫星位置矢量
    return x, y, z

# 初始时间和初始轨道六根数
t0 = datetime.datetime(2023, 5, 1, 0, 0, 0)  # 初始时间
a = 7000.0
e = 0.01  # 偏心率
i = deg2rad(60.0)  # 轨道倾角
RAAN = deg2rad(30.0)  # 升交点赤经
arg_per = deg2rad(45.0)  # 近地点幅角
M = deg2rad(0.0)  # 平近点角

# 当前时间
current_time = datetime.datetime.now()

# 计算当前时刻的卫星位置
satellite_position = compute_orbital_params(a, e, i, RAAN, arg_per, M, current_time, t0)

# 输出卫星位置
print("Satellite Position (X, Y, Z):", satellite_position)
# 单位是m

5. Northeast Celestial Coordinate System

J2000 to Northeast Day

import math

# 输入地理坐标
latitude = 40.7128
longitude = -74.0060
altitude = 0.0  # 海拔高度,此处假设为0

# 输入参考点的地理坐标
reference_latitude = 40.0
reference_longitude = -75.0
reference_altitude = 0.0

# 输入当前时间(UTC)
current_time = 1620795600  # 时间戳,表示2021年5月12日00:00:00

# 定义地球半径(单位:米)
earth_radius = 6371000

# 将角度转换为弧度
def degrees_to_radians(degrees):
    return degrees * (math.pi / 180.0)

# 将弧度转换为角度
def radians_to_degrees(radians):
    return radians * (180.0 / math.pi)

# 计算地球自转角速度
def calculate_earth_rotation_rate():
    return 2 * math.pi / 86400  # 地球自转周期约为86400秒

# 计算当前时间与J2000时刻的时间差(单位:秒)
def calculate_time_difference(current_time):
    j2000_time = 946727935  # J2000时刻的时间戳,表示2000年1月1日12:00:00
    return current_time - j2000_time

# 计算地球自转角(单位:弧度)
def calculate_earth_rotation_angle(current_time):
    time_difference = calculate_time_difference(current_time)
    rotation_rate = calculate_earth_rotation_rate()
    return rotation_rate * time_difference

# 将地理坐标转换为地心坐标系下的直角坐标(以米为单位)
def convert_geographic_to_geocentric(latitude, longitude, altitude):
    latitude_rad = degrees_to_radians(latitude)
    longitude_rad = degrees_to_radians(longitude)

    x = (earth_radius + altitude) * math.cos(latitude_rad) * math.cos(longitude_rad)
    y = (earth_radius + altitude) * math.cos(latitude_rad) * math.sin(longitude_rad)
    z = (earth_radius + altitude) * math.sin(latitude_rad)

    return x, y, z

# 将地心坐标系下的直角坐标转换为东北天坐标系下的坐标
def convert_geocentric_to_topocentric(x, y, z, reference_latitude, reference_longitude):
    reference_latitude_rad = degrees_to_radians(reference_latitude)
    reference_longitude_rad = degrees_to_radians(reference_longitude)

    rotation_angle = reference_longitude_rad

    topocentric_x = -math.sin(reference_latitude_rad) * math.cos(reference_longitude_rad) * x - math.sin(reference_latitude_rad) * math.sin(reference_longitude_rad) * y
    + math.cos(reference_latitude_rad) * math.cos(reference_longitude_rad) * z
    topocentric_y = -math.sin(reference_longitude_rad) * x + math.cos(reference_longitude_rad) * y
    topocentric_z = math.cos(reference_latitude_rad) * math.cos(reference_longitude_rad) * x + math.cos(reference_latitude_rad) * math.sin(reference_longitude_rad) * y + math.sin(reference_latitude_rad) * z

    return topocentric_x, topocentric_y, topocentric_z

# 计算地球自转角(单位:弧度)
earth_rotation_angle = calculate_earth_rotation_angle(current_time)

# 将地理坐标转换为地心坐标系下的直角坐标
geocentric_x, geocentric_y, geocentric_z = convert_geographic_to_geocentric(latitude, longitude, altitude)

# 将参考点的地理坐标转换为地心坐标系下的直角坐标
reference_geocentric_x, reference_geocentric_y, reference_geocentric_z = convert_geographic_to_geocentric(reference_latitude, reference_longitude, reference_altitude)

# 计算参考点的地球自转角(单位:弧度)
reference_earth_rotation_angle = calculate_earth_rotation_angle(current_time)

# 将地心坐标系下的直角坐标转换为东北天坐标系下的坐标
topocentric_x, topocentric_y, topocentric_z = convert_geocentric_to_topocentric(
    geocentric_x - reference_geocentric_x,
    geocentric_y - reference_geocentric_y,
    geocentric_z - reference_geocentric_z,
    reference_latitude,
    reference_longitude
)

# 输出东北天坐标系下的坐标
print("东向(x):", topocentric_x)
print("北向(y):", topocentric_y)
print("天向(z):", topocentric_z)

The center of the earth is fixed to the northeast sky

import math

# 输入地心地固坐标系下的坐标
x = 1333998.456149258
y = -4654044.842733645
z = 4138300.2386952764

# 输入参考点的地心地固坐标系下的坐标
reference_x = 6378137.0
reference_y = 0.0
reference_z = 0.0

# 定义地球自转角速度(单位:弧度/秒)
rotation_rate = 7.2921159e-5

# 将地心地固坐标系下的坐标转换为东北天坐标系下的坐标
def convert_geocentric_to_topocentric(x, y, z, reference_x, reference_y, reference_z):
    dx = x - reference_x
    dy = y - reference_y
    dz = z - reference_z

    rotation_angle = rotation_rate * 0  # 这里假设时间差为0

    topocentric_x = -math.sin(rotation_angle) * dx - math.cos(rotation_angle) * dy
    topocentric_y = math.cos(rotation_angle) * dx - math.sin(rotation_angle) * dy
    topocentric_z = dz

    return topocentric_x, topocentric_y, topocentric_z

# 将地心地固坐标系下的坐标转换为东北天坐标系下的坐标
topocentric_x, topocentric_y, topocentric_z = convert_geocentric_to_topocentric(x, y, z, reference_x, reference_y, reference_z)

# 输出东北天坐标系下的坐标
print("东向(x):", topocentric_x)
print("北向(y):", topocentric_y)
print("天向(z):", topocentric_z)

6. Attitude angle solution 

import math

# 输入卫星的J2000坐标系下的坐标
satellite_x = 1000.0
satellite_y = 2000.0
satellite_z = 3000.0

# 输入目标点的J2000坐标系下的坐标
target_x = 500.0
target_y = 1000.0
target_z = 1500.0

# 计算卫星相对于目标点的俯仰角
def calculate_elevation_angle(satellite_x, satellite_y, satellite_z, target_x, target_y, target_z):
    dx = target_x - satellite_x
    dy = target_y - satellite_y
    dz = target_z - satellite_z

    distance = math.sqrt(dx**2 + dy**2 + dz**2)
    elevation_angle = math.asin(dz / distance)

    return elevation_angle

# 计算卫星相对于目标点的侧摆角
def calculate_azimuth_angle(satellite_x, satellite_y, satellite_z, target_x, target_y, target_z):
    dx = target_x - satellite_x
    dy = target_y - satellite_y

    azimuth_angle = math.atan2(dy, dx)

    return azimuth_angle

# 计算卫星相对于目标点的偏航角
def calculate_yaw_angle():
    # 这里假设偏航角为0
    return 0.0

# 计算卫星相对于目标点的俯仰角、侧摆角和偏航角
elevation_angle = calculate_elevation_angle(satellite_x, satellite_y, satellite_z, target_x, target_y, target_z)
azimuth_angle = calculate_azimuth_angle(satellite_x, satellite_y, satellite_z, target_x, target_y, target_z)
yaw_angle = calculate_yaw_angle()

# 将弧度转换为角度
elevation_angle_deg = math.degrees(elevation_angle)
azimuth_angle_deg = math.degrees(azimuth_angle)
yaw_angle_deg = math.degrees(yaw_angle)

# 输出卫星相对于目标点的俯仰角、侧摆角和偏航角
print("俯仰角(Elevation Angle):", elevation_angle_deg)
print("侧摆角(Azimuth Angle):", azimuth_angle_deg)
print("偏航角(Yaw Angle):", yaw_angle_deg)

7. Calculate the Julian day at a certain time

def calculate_julian_date(year, month, day):
    if month <= 2:
        year -= 1
        month += 12

    A = year // 100
    B = A // 4
    C = 2 - A + B

    julian_day = (
        int(365.25 * (year + 4716)) +
        int(30.6001 * (month + 1)) +
        day + C - 1524.5
    )

    return julian_day

# 示例用法
year = 2023
month = 5
day = 12

julian_date = calculate_julian_date(year, month, day)
print("儒略日:", julian_date)

In the above example, calculate_julian_datethe function receives the year, month, and day as parameters and returns the calculated Julian day.

Calculations in functions follow the formulas and rules for Julian day calculations, including handling of leap years. First, correct by the value of the month, treating January and February as the thirteenth and fourteenth months of the previous year. Then, calculate according to the formula, including the conversion of the year, the adjustment of the month and the calculation of some constants.

In the example usage, we define a date (May 12, 2023), then call calculate_julian_datethe function to calculate the Julian day, and print the result.

Note that this example is a simplified implementation that does not take into account some special cases (such as dates in BC) and other correction factors. In practical applications, it may be necessary to use more complex algorithms and rules to calculate Julian days to obtain more accurate results.

Guess you like

Origin blog.csdn.net/weixin_57399429/article/details/130649463