Skip to content

feat: add angular separation, reciprocal bearing, coordinate bearing_to, and generalized vector/point rotations - #129

Open
vamshidharre wants to merge 1 commit into
helsing-ai:mainfrom
vamshidharre:feat/kinematic-rotations-bearings
Open

vamshidharre wants to merge 1 commit into
helsing-ai:mainfrom
vamshidharre:feat/kinematic-rotations-bearings

Conversation

@vamshidharre

Copy link
Copy Markdown

Summary

This PR introduces essential spatial math primitives for relative targeting, angular separation, and generalized rotations across Bearing, Vector, and Coordinate:

  1. Relative Targeting / Look Angles (Coordinate::bearing_to):

    • Added Coordinate::bearing_to(&self, other: &Self) -> Option<Bearing<In>> for directly computing the line-of-sight bearing between two coordinates in BearingDefined systems.
    • Returns None when points are identical (where azimuth is ill-defined).
  2. Generalized Vector Rotations (Vector::rotate):

    • Relaxed the type restriction on Vector::rotate from rotation_axis: &Self to rotation_axis: &Vector<In, AxisTime>, enabling rotations of VelocityVector or AccelerationVector around a LengthVector (e.g. an aircraft pitch/yaw/roll axis or shaft) without unit-type mismatch compiler errors.
    • Added Vector::rotate_around_bearing(&self, axis: Bearing<In>, angle: Angle) -> Self for direct rotations around a line-of-sight direction.
  3. Coordinate Rotations:

    • Added Coordinate::rotate_around_axis(&self, axis, angle) -> Self for rotating a point around an axis passing through the origin.
    • Added Coordinate::rotate_around_point(&self, center, axis, angle) -> Self for rotating a point around an axis passing through an arbitrary center point.
    • Added Coordinate::rotate_around_bearing and Coordinate::rotate_around_point_bearing.
  4. Angular Separation (angle_between):

    • Added Vector::angle_between<OtherTime>(&self, other: &Vector<In, OtherTime>) -> Angle: computes the angle between two vectors across $[0, \pi]$ using FloatMath::atan2(cross.norm(), dot) (numerically stable down to subnormals, immune to acos precision degradation near $0^\circ$ and $180^\circ$).
    • Supports cross-unit angle calculation (e.g. fuselage heading vector vs flight velocity vector for angle of attack / sideslip).
    • Added Vector::angle_to_bearing(&self, bearing: Bearing<In>) -> Angle.
    • Added Bearing::angle_between(&self, other: &Self) -> Angle for computing the great-circle angular separation between two lines of sight.
  5. Reciprocal Directions & Scaling (Bearing):

    • Added Bearing::opposite(&self) -> Self and impl Neg for Bearing<In>, returning the exact antipodal direction on the sphere.
    • Added Mul implementations between Bearing<In> and physical quantities (Length, Velocity, Acceleration), allowing natural expressions like bearing * speed -> VelocityVector and bearing * range -> LengthVector.

Motivation

In sensor tracking, radar/vision targeting, and aerospace multi-body kinematics, calculating the relative bearing to a target, rotating velocity vectors around body-fixed axes, and finding the angular separation between lines of sight are fundamental operations. Previously in sguaba:

  • Computing relative bearings between coordinates required cumbersome manual vector subtraction and origin coercion.
  • Rotating velocity vectors around body axes failed compilation because Vector::rotate required the rotation axis to share the exact same Time unit as the rotated vector.
  • Finding the angular separation between lines of sight or reciprocal bearings required manual trigonometry.

Verification

All checks pass cleanly:

  • cargo test --all-targets: 249 passed, 0 failed.
  • cargo test --doc: 51 doctests passed.
  • cargo clippy --all-features: 0 warnings.
  • cargo check --no-default-features --features libm: 0 warnings (#![no_std] verified).
  • cargo fmt -- --check: verified clean formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant