magnetic
cosmic_warp.physics.magnetic
Magnetic environment and torque models for spacecraft simulation.
Models Earth's magnetic field as a centered dipole aligned with the ECI Z-axis (no tilt) and fixed in the inertial frame (no Earth rotation). The ~11.3° tilt and Earth's rotation are not modeled yet (see the roadmap).
Magnetic torque
τ_mag = m × B
where
m – spacecraft residual magnetic dipole moment [A·m²] (body frame) B – Earth's magnetic field at spacecraft position [T] (body frame)
earth_magnetic_field
Compute Earth's magnetic field at a position (aligned, non-rotating dipole).
The dipole field is
B = B0 * (RE/r)^3 * [3(m̂·r̂)r̂ - m̂]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
vec3d
|
Spacecraft position in ECI frame [m] |
required |
Returns:
| Type | Description |
|---|---|
vec3d
|
Magnetic field vector in ECI frame [T] |
Source code in cosmic_warp/physics/magnetic.py
magnetic_torque
magnetic_torque(
state: State, vehicle: VehicleConfig
) -> vec3d
Compute magnetic torque on spacecraft.
The torque is computed in the body frame
τ = m_body × B_body
where B_body is the Earth field rotated from ECI to body frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
Spacecraft state (position + attitude quaternion) |
required |
vehicle
|
VehicleConfig
|
Vehicle config (contains magnetic_dipole in body frame [A·m²]) |
required |
Returns:
| Type | Description |
|---|---|
vec3d
|
Magnetic torque vector in body frame [N·m] |