An old exercise.
Any two parameters are calculated based on the remaining parameters, vertical and horizontal distance.
PlaneTrajMath implements a geometric trajectory solver in 2D space.
The code models a trajectory as a sequence of three motion segments, where each segment consists of:
- a linear displacement
L - a curvature radius
R - an orientation angle
Φ
The solver reconstructs unknown trajectory parameters from two global constraints:
- TVD — total vertical displacement
- Disp — total horizontal displacement
The system solves various combinations of unknowns:
- lengths
L - radii
R - heading angles
Φ
using:
- linear algebra
- trigonometric identities
- nonlinear equation reduction
Each trajectory cell contains:
| Variable | Meaning |
|---|---|
L |
Linear motion along direction Φ |
R |
Turning radius / curved contribution |
Φ |
Heading angle |
The trajectory consists of three consecutive elements:
m_c[0], m_c[1], m_c[2]
The trajectory accumulates displacement from:
- straight motion
- circular turning motion
The contribution of a straight segment is standard projection:
The curved contribution comes from integrating arc motion between two headings.
The entire solver is built around two global equations.
Interpretation:
- linear segments contribute via
cos(Φ) - curved segments contribute via sine differences
Interpretation:
- linear segments project onto X using
sin(Φ) - arc segments contribute via cosine differences
For circular motion:
These expressions are exact integrals of motion along an arc.
That is why every curved component appears as a difference of trigonometric functions.
The functions:
TurnRotateUpRotateDown
perform symmetry transformations of the trajectory.
These are used to:
- reduce duplicated solving logic
- reuse the same solver for multiple geometric cases
- normalize equations before solving
Applies coordinate transformations and precomputes:
sin0 = sin(Phi0)
cos0 = cos(Phi0)etc.
This reduces repeated trigonometric evaluations.
Restores the original coordinate ordering after solving.
Two validation functions verify the reconstructed trajectory.
Solutions are accepted only if errors are sufficiently small.
Solves:
using determinant inversion.
If:
the system is treated as singular.
Several nonlinear systems are reduced to the canonical form:
Using the identity:
where:
the equation becomes:
Thus:
This is exactly what FindAngle() computes.
Solves systems of the form:
Solves the coupled nonlinear system:
Trigonometric systems naturally have multiple solutions:
The code carefully evaluates:
- both candidate angles
- trajectory consistency
- displacement errors
- positivity constraints
before selecting a solution.
This is the most sophisticated solver.
It solves simultaneously for:
Φ0Φ1
The algorithm introduces:
This transforms the original coupled nonlinear system into a solvable form.
The implementation contains several safeguards:
| Check | Purpose |
|---|---|
fabs(det) < 1e-10 |
Singular matrix rejection |
fabs(arg) > 1 |
Invalid asin domain |
| angle normalization | Keep angles in [-π, π] |
| residual checks | Reject unstable solutions |
The class provides specialized solvers for different unknown combinations:
| Function | Solves For |
|---|---|
CalcLwhereR |
L0, R0 |
CalcLltR |
L0, R1 |
CalcLL |
L0, L1 |
CalcRR |
R0, R1 |
CalcLwherePhi |
L0, Φ0 |
CalcLltPhi |
L0, Φ1 |
CalcRwherePhi |
R0, Φ0 |
CalcRgtPhi |
R1, Φ0 |
CalcPhiPhi |
Φ0, Φ1 |
PlaneTrajMath is a compact analytical trajectory reconstruction engine based on:
- exact geometric equations
- symbolic trigonometric reduction
- determinant-based linear solving
- nonlinear angle recovery
The implementation avoids iterative optimization and instead derives closed-form or semi-closed-form analytical solutions wherever possible.
