Skip to content

philip-luk-tangent-anim/Mathfs

 
 

Repository files navigation

Mathfs

Expanded Math Functionality for Unity

Features

  • Line & Line Segment Intersection
  • 2D Angle helpers (AngToDir, DirToAng...)
  • 2D Vector extension methods (Rotate90CCW/CW, Rotate, RotateAround...)
  • Trajectory Math helpers (GetLaunchSpeed, GetMaxRange, TryGetLaunchAngles...)
  • Quadratic & Linear Root finders
  • Remap functions
  • Added Tau and the Golden Ratio
  • Vector extension methods (WithMagnitude, ClampMagnitude(min,max)...)
  • Expanded basic math operations to vectors (Clamp, Round, Abs...)
  • Color extensions (WithAlpha, MultiplyRGB...)
  • Smoothing functions (Smooth01, SmoothCos01...)
  • Triangle Math helpers (SignedArea, Circumcenter, Incircle...)
  • Circle Math helpers (Area, Circumference...)
  • All functions use radians
  • And more!

Changes

Mathfs.cs does not fully match Unity's Mathf.cs, I've made a few changes:

  • All angles are in radians, no methods use degrees
  • Lerp and InverseLerp:
    • Unclamped by default
    • LerpClamped/InverseLerpClamped are now the special case functions/exceptions
    • Uses the more numerically stable evaluation
  • Smoothstep is removed in favor of the more explicit:
    • LerpSmooth (which is how it was implemented) and
    • InverseLerpSmooth (which is how it is implemented everywhere but Unity's Mathf.cs)
  • Min/Max functions with arbitrary inputs/array input will throw on empty instead of returning 0

About

Expanded Math Functionality for Unity

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%