State Vector ↔ Orbital Elements Debugging

When the orbit is wrong but the equations are right. This interactive debugging lab shows how angle units, orbital-element conventions, and singular cases can produce a completely different spacecraft state.

Why this matters

Even perfect control fails if your state is wrong

A spacecraft orbit can be represented by classical orbital elements or by a Cartesian state vector. Both are correct, but the conversion is fragile. A degree/radian mistake, a swapped angle, or a singular element near circular/equatorial conditions can make the simulation look physically wrong.

correct equations + wrong interpretation → wrong orbit
wrong orbit + perfect controller → wrong correction
Core message: A small mistake in angle convention, units, or orbital-element interpretation can produce a completely different orbit.
Problem roadmap

Debug the representation before blaming the solver

A · Correct COE → state conversion
Convert orbital elements into perifocal position/velocity, then rotate into ECI.
B · Degrees vs radians
Show how one unit mistake can create a new orbital plane and large state error.
C · Argument of perigee vs true anomaly
Separate ellipse orientation from spacecraft position along the ellipse.
D · RAAN vs argument of perigee
Distinguish rotating the orbital plane from rotating the ellipse inside the plane.
E · Circular orbit singularity
When e ≈ 0, argument of perigee loses physical meaning.
F · Equatorial ambiguity
When i ≈ 0, RAAN becomes undefined and can jump numerically.
Orbital elements refresher

Six numbers, but not six independent visual ideas

a
Semi-major axis: orbit size.
e
Eccentricity: orbit shape.
i
Inclination: tilt of orbital plane.
Ω
RAAN: rotation of orbital plane around Earth.
ω
Argument of perigee: ellipse orientation inside the plane.
ν
True anomaly: spacecraft position measured from perigee.
Important warning: Ω, ω, and ν are all angles, but they rotate different things. Mixing them changes the orbit geometry.
Interactive debugging lab

Build the correct orbit, then introduce a controlled bug

Adjust the orbital elements and choose a bug mode. The plots compare the correct state against the bugged state. The diagnostic cards estimate whether the issue is a plane error, position error, unit error, or singularity.

Position error
Velocity error
Plane error
Likely bug
Energy error
Angular momentum error
Expected inclination
Recovered inclination
Interpretation: Run the lab to classify the state representation error.
Section A — Correct COE → State Vector Conversion

The orbit begins in the perifocal plane

Classical orbital elements are first converted into position and velocity in the perifocal frame. The orbit is then rotated into the inertial frame using Ω, i, and ω.

\[p = a(1-e^2)\]
\[\mathbf r_{pqw} = \left[\frac{p\cos\nu}{1+e\cos\nu},\frac{p\sin\nu}{1+e\cos\nu},0\right]\]
\[\mathbf v_{pqw}=\sqrt{\frac{\mu}{p}}[-\sin\nu, e+\cos\nu,0]\]
\[\mathbf r_{eci}=R_3(\Omega)R_1(i)R_3(\omega)\mathbf r_{pqw}\]
Debug idea: If the perifocal orbit looks correct but the 3D orbit is wrong, the bug is probably in Ω, i, ω, or the rotation sequence.
Section B — Degrees vs Radians Bug

A unit bug can create a different orbit

If code expects radians but receives degrees, an angle like 45° may be interpreted as 45 radians. This does not produce a small perturbation; it can rotate the orbital plane dramatically.

expected: i = 45°
bugged: i = 45 rad
Key teaching line: A unit bug does not create a small error. For angles, it can create a new orbit.
Section C — Argument of Perigee vs True Anomaly

ω rotates the ellipse; ν moves the spacecraft

Argument of perigee ω
Controls where perigee lies inside the orbital plane.
True anomaly ν
Controls where the spacecraft is along the ellipse, measured from perigee.
Diagnostic pattern: Small plane error + large position error + small energy error usually means the orbit geometry is similar, but the spacecraft is at the wrong point along the orbit.
Section D — RAAN vs Argument of Perigee Swap

Ω rotates the plane; ω rotates the ellipse inside the plane

Swapping RAAN and argument of perigee is a classic representation bug. The numbers may look reasonable, but the orbital plane, line of nodes, and perigee direction can all move.

Ω → orbital plane orientation
ω → ellipse orientation within that plane
Visual clue: If the line of nodes and perigee marker move together in strange ways, check whether Ω and ω were swapped.
Sections E/F — Circular and Equatorial Singularities

Sometimes the element is not physically meaningful

Circular orbit: e ≈ 0
There is no unique perigee, so argument of perigee becomes undefined. Use argument of latitude:
u = ω + ν
Equatorial orbit: i ≈ 0
There is no clear line of nodes, so RAAN becomes undefined. Use longitude of perigee or true longitude.
Longitude of perigee
ϖ = Ω + ω
True longitude
l = Ω + ω + ν
Debug warning: Near e = 0 or i = 0, recovered Ω or ω may jump even though the physical orbit is fine.
Debugging logic

Use error patterns to identify the bug

Large position error + small energy error
Likely angle interpretation problem.
Large plane error
Likely RAAN or inclination issue.
Small plane error + large along-track error
Likely true anomaly or epoch issue.
RAAN unstable near i = 0
Equatorial singularity.
ω unstable near e = 0
Circular orbit singularity.
Very large errors everywhere
Likely degree/radian or unit bug.
Python / MATLAB snippets

Code patterns for conversion and diagnostics

These snippets show the core operations used in the interactive page: perifocal conversion, rotation to ECI, and diagnostic checks.

% COE to perifocal position and velocity
mu = 398600.4418;
p = a*(1 - e^2);

r_pqw = [p*cos(nu)/(1 + e*cos(nu));
         p*sin(nu)/(1 + e*cos(nu));
         0];

v_pqw = sqrt(mu/p)*[-sin(nu);
                    e + cos(nu);
                    0];
Engineering takeaway

Before trusting propagation or control, validate the state

1 · Check angle units
Degrees and radians are one of the fastest ways to create a false orbit.
2 · Separate Ω, ω, and ν
They rotate different geometry and should not be interchanged.
3 · Watch singular cases
Circular and equatorial orbits make some classical elements undefined.
4 · Validate invariants
Use energy, angular momentum, and plane-normal checks.
5 · Interpret error patterns
Different bugs produce different diagnostic signatures.
6 · GNC link
A controller can only act on the state representation it receives.
Final insight: An orbit is not defined only by equations. It is defined by equations, units, frames, time, and conventions. Before blaming the controller, solver, or propagator, debug the state.