Mathfs Documentation

repository·master·Indexed 25 days ago

https://github.com/freyaholmer/mathfs

An expanded math library for Unity (version 1.0.0) providing advanced geometric, trajectory, and spline functionality. Features include 2D intersection tests, Bézier and NURBS curves, trajectory math, triangle and polygon utilities, and vector helpers. Requires Unity 2021.2 or later and uses radians for all angle functions.

Tokens
629
Snippets
1
Records
4
Agent score
33%

What's inside Mathfs

  1. Overview of Mathfs features

    master

    Mathfs provides a wide range of mathematical utilities for Unity developers, including:

    • 2D Intersection Tests: Between Rays, LineSegments, Lines, and Circles.
    • Curves & Splines: Bézier (Quadratic, Cubic, Generalized), Hermite, Catmull-Rom, B-Spline, NURBS, and Trajectory curves.
    • Trajectory Math: Functions for displacement, launch speed, launch angles, max range, and height potential.
    • Triangle & Polygon Math: Area/SignedArea, containment checks, Incenter/Centroid, Incircle/Circumcircle, and winding numbers.
    • Circle Math: Creating circles from two or three points, and conversions between radius, area, and circumference.
    • Vector & Angle Helpers: 2D angle conversions (AngToDir, DirToAng), vector rotations, and expanded vector operations (Clamp, Round, Abs, etc.).
    • General Utilities: Quadratic/Linear root finders, remap functions, smoothing functions, and mathematical constants (Tau, Pi, Golden Ratio, e, sqrt2).
  2. Install Mathfs into Unity

    master

    Mathfs can be installed into your Unity project using one of three methods. Note that a minimum Unity version of 2021.2 is required due to the use of modern C# features.

    Plain Install

    Clone or download the repository and place the folder anywhere within your project's Assets folder.

    Unity Package Manager (UPM)

    Add one of the following lines to your Packages/manifest.json file:

    • Specific version (Recommended): "com.acegikmo.mathfs": "https://github.com/FreyaHolmer/Mathfs.git#0.1.0"
    • Latest commit (Unstable): "com.acegikmo.mathfs": "https://github.com/FreyaHolmer/Mathfs.git"

    OpenUPM

    If you have openupm-cli installed, run: openupm add com.acegikmo.mathfs

    openupm add com.acegikmo.mathfs
  3. Mathfs API behavior and differences from Unity Mathf

    master

    Mathfs provides expanded math functionality but deviates from Unity's standard Mathf in several key ways. Be aware of these changes when migrating or writing new logic:

    • Angles: All functions use radians. No methods use degrees.
    • Lerp and InverseLerp:
      • These are unclamped by default.
      • Use LerpClamped and InverseLerpClamped for clamped behavior.
      • Uses more numerically stable evaluation methods.
    • Smoothstep: The standard Smoothstep is removed. Use LerpSmooth or InverseLerpSmooth instead.
    • Min/Max: Functions accepting arbitrary inputs or arrays will throw an error if the input is empty, rather than returning 0.