u/Alert_Strategy_8993

**Stable Direct Tangent Identities for SAS Triangles** – A faster and more numerically stable alternative to Law of Cosines (especially for robotics)

Hi r/robotics,

I created a small open-source library focused on **direct tangent identities** for solving Side-Angle-Side (SAS) triangles. The main motivation was to improve numerical stability in planar inverse kinematics, particularly near singularities (when robotic links are nearly straight).

### Why this matters:

- Traditional Law of Cosines can suffer from catastrophic cancellation when β ≈ 0° or 180°

- My method uses `atan2` + direct tangent formula → much more stable

- ~2.2x faster in benchmarks

- Clean PyTorch differentiable version included

### Features:

- Full symmetric set of direct tangent identities

- Robust 2-Link Planar IK (elbow up & down)

- Vectorized + PyTorch support

- Medical imaging utility (e.g. costophrenic angle in chest X-rays)

GitHub: https://github.com/mbewejoseph72-debug/stable-tangent-kinematics

Would love feedback from the community — especially on the IK implementation and possible extensions (3D, more DOF, etc.).

Examples, benchmarks, and performance plots are in the repo.

Looking forward to your thoughts!

reddit.com
u/Alert_Strategy_8993 — 3 days ago