NWH Common
Search Results for

    Show / Hide Table of Contents

    Class GeomUtility

    Collection of geometric utility functions for 3D math operations. Includes vector math, mesh calculations, triangle operations, and spatial queries.

    Inheritance
    object
    GeomUtility
    Namespace: NWH.Common.Utility
    Assembly: NWH.Common.dll
    Syntax
    public static class GeomUtility

    Methods

    | Edit this page View Source

    AreaFromFourPoints(Vector3, Vector3, Vector3, Vector3)

    Calculates the area of a quadrilateral from four points.

    Declaration
    public static float AreaFromFourPoints(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4)
    Parameters
    Type Name Description
    Vector3 p1

    First point.

    Vector3 p2

    Second point.

    Vector3 p3

    Third point.

    Vector3 p4

    Fourth point.

    Returns
    Type Description
    float

    Area of the quadrilateral.

    | Edit this page View Source

    AreaFromThreePoints(Vector3, Vector3, Vector3)

    Calculates the area of a triangle from three points.

    Declaration
    public static float AreaFromThreePoints(Vector3 p1, Vector3 p2, Vector3 p3)
    Parameters
    Type Name Description
    Vector3 p1

    First point.

    Vector3 p2

    Second point.

    Vector3 p3

    Third point.

    Returns
    Type Description
    float

    Area of the triangle.

    | Edit this page View Source

    ChangeLayersRecursively(Transform, string)

    Changes the layer of a transform and all its children recursively.

    Declaration
    public static void ChangeLayersRecursively(this Transform trans, string name)
    Parameters
    Type Name Description
    Transform trans

    Root transform.

    string name

    Layer name.

    | Edit this page View Source

    ChangeObjectAlpha(GameObject, float)

    Changes the alpha value of a GameObject's material color.

    Declaration
    public static void ChangeObjectAlpha(GameObject gameObject, float alpha)
    Parameters
    Type Name Description
    GameObject gameObject

    GameObject to modify.

    float alpha

    New alpha value (0-1).

    | Edit this page View Source

    ChangeObjectColor(GameObject, Color)

    Changes the color of a GameObject's material.

    Declaration
    public static void ChangeObjectColor(GameObject gameObject, Color color)
    Parameters
    Type Name Description
    GameObject gameObject

    GameObject to modify.

    Color color

    New color.

    | Edit this page View Source

    ClampMagnitude(Vector3, float, float)

    Clamps the magnitude of a vector between minimum and maximum values.

    Declaration
    public static Vector3 ClampMagnitude(this Vector3 v, float min, float max)
    Parameters
    Type Name Description
    Vector3 v

    Vector to clamp.

    float min

    Minimum magnitude.

    float max

    Maximum magnitude.

    Returns
    Type Description
    Vector3

    Vector with clamped magnitude.

    | Edit this page View Source

    CopySign(float, float)

    Copies the sign from one float to the magnitude of another.

    Declaration
    public static float CopySign(float mag, float sgn)
    Parameters
    Type Name Description
    float mag

    Magnitude value.

    float sgn

    Sign donor value.

    Returns
    Type Description
    float

    Magnitude with the sign of sgn.

    | Edit this page View Source

    DistanceAlongNormal(Vector3, Vector3, Vector3)

    Calculates the distance between two points projected along a normal vector.

    Declaration
    public static float DistanceAlongNormal(Vector3 a, Vector3 b, Vector3 normal)
    Parameters
    Type Name Description
    Vector3 a

    First point.

    Vector3 b

    Second point.

    Vector3 normal

    Normal vector to project along.

    Returns
    Type Description
    float

    Distance along normal.

    | Edit this page View Source

    Equal(Quaternion, Quaternion)

    Checks if two Quaternion values are approximately equal.

    Declaration
    public static bool Equal(this Quaternion a, Quaternion b)
    Parameters
    Type Name Description
    Quaternion a

    First quaternion.

    Quaternion b

    Second quaternion.

    Returns
    Type Description
    bool

    True if angle between quaternions is less than 0.1 degrees.

    | Edit this page View Source

    FindArea(Vector3, Vector3, Vector3, Vector3)

    Calculates the area of a quadrilateral defined by four points.

    Declaration
    public static float FindArea(Vector3 A, Vector3 B, Vector3 C, Vector3 D)
    Parameters
    Type Name Description
    Vector3 A

    First corner.

    Vector3 B

    Second corner.

    Vector3 C

    Third corner.

    Vector3 D

    Fourth corner.

    Returns
    Type Description
    float

    Area of the quad.

    | Edit this page View Source

    FindCenter(Vector3, Vector3, Vector3, Vector3)

    Finds the center point of a quad or triangle defined by 3 or 4 points.

    Declaration
    public static Vector3 FindCenter(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
    Parameters
    Type Name Description
    Vector3 a

    First corner.

    Vector3 b

    Second corner.

    Vector3 c

    Third corner.

    Vector3 d

    Fourth corner (can equal first corner for triangle).

    Returns
    Type Description
    Vector3

    Center point.

    | Edit this page View Source

    FindChordLine(Vector3, Vector3, Vector3, Vector3, float)

    Finds a point along the chord line of a quad at the specified percentage.

    Declaration
    public static Vector3 FindChordLine(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float chordPercent)
    Parameters
    Type Name Description
    Vector3 a

    First corner.

    Vector3 b

    Second corner.

    Vector3 c

    Third corner.

    Vector3 d

    Fourth corner.

    float chordPercent

    Position along chord (0-1).

    Returns
    Type Description
    Vector3

    Point on chord line.

    | Edit this page View Source

    FindDistanceToSegment(Vector3, Vector3, Vector3)

    Calculates the distance between a point and a line segment.

    Declaration
    public static float FindDistanceToSegment(Vector3 pt, Vector3 p1, Vector3 p2)
    Parameters
    Type Name Description
    Vector3 pt

    Point to measure from.

    Vector3 p1

    First endpoint of segment.

    Vector3 p2

    Second endpoint of segment.

    Returns
    Type Description
    float

    Distance to the segment.

    | Edit this page View Source

    FindMeshCenter(Mesh)

    Find mesh center by averaging. Returns local center.

    Declaration
    public static Vector3 FindMeshCenter(Mesh mesh)
    Parameters
    Type Name Description
    Mesh mesh
    Returns
    Type Description
    Vector3
    | Edit this page View Source

    FindSpanLine(Vector3, Vector3, Vector3, Vector3, float)

    Finds a point along the span line of a quad at the specified percentage.

    Declaration
    public static Vector3 FindSpanLine(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float spanPercent)
    Parameters
    Type Name Description
    Vector3 a

    First corner.

    Vector3 b

    Second corner.

    Vector3 c

    Third corner.

    Vector3 d

    Fourth corner.

    float spanPercent

    Position along span (0-1).

    Returns
    Type Description
    Vector3

    Point on span line.

    | Edit this page View Source

    InverseTransformPointUnscaled(Transform, Vector3)

    Transforms a point from world to local space without applying scale.

    Declaration
    public static Vector3 InverseTransformPointUnscaled(this Transform transform, Vector3 position)
    Parameters
    Type Name Description
    Transform transform

    Transform to use.

    Vector3 position

    World position.

    Returns
    Type Description
    Vector3

    Local position without scale.

    | Edit this page View Source

    LinePlaneIntersection(Vector3, Vector3, Vector3, Vector3)

    Finds the intersection point between a line and a plane.

    Declaration
    public static Vector3 LinePlaneIntersection(Vector3 planePoint, Vector3 planeNormal, Vector3 linePoint, Vector3 lineDirection)
    Parameters
    Type Name Description
    Vector3 planePoint

    Point on the plane.

    Vector3 planeNormal

    Normal vector of the plane.

    Vector3 linePoint

    Point on the line.

    Vector3 lineDirection

    Direction of the line.

    Returns
    Type Description
    Vector3

    Intersection point, or Vector3.zero if parallel.

    | Edit this page View Source

    MeshArea(Mesh)

    Calculates area of a complete mesh.

    Declaration
    public static float MeshArea(Mesh mesh)
    Parameters
    Type Name Description
    Mesh mesh
    Returns
    Type Description
    float
    | Edit this page View Source

    NearEqual(Vector3, Vector3, float)

    Checks if two Vector3 values are approximately equal within a threshold. Uses squared magnitude for performance.

    Declaration
    public static bool NearEqual(this Vector3 a, Vector3 b, float threshold = 0.01)
    Parameters
    Type Name Description
    Vector3 a

    First vector.

    Vector3 b

    Second vector.

    float threshold

    Maximum squared distance to consider equal.

    Returns
    Type Description
    bool

    True if vectors are within threshold distance.

    | Edit this page View Source

    NearestPointOnLine(Vector3, Vector3, Vector3)

    Finds the nearest point on an infinite line to a given point.

    Declaration
    public static Vector3 NearestPointOnLine(Vector3 linePnt, Vector3 lineDir, Vector3 pnt)
    Parameters
    Type Name Description
    Vector3 linePnt

    Point on the line.

    Vector3 lineDir

    Direction of the line.

    Vector3 pnt

    Point to find nearest point from.

    Returns
    Type Description
    Vector3

    Nearest point on the line.

    | Edit this page View Source

    NearlyEqual(float, float, double)

    Checks if two float values are nearly equal within an epsilon threshold.

    Declaration
    public static bool NearlyEqual(this float a, float b, double epsilon)
    Parameters
    Type Name Description
    float a

    First value.

    float b

    Second value.

    double epsilon

    Maximum difference to consider equal.

    Returns
    Type Description
    bool

    True if values are within epsilon.

    | Edit this page View Source

    Perpendicular(Vector3)

    Calculates a perpendicular vector to the given vector.

    Declaration
    public static Vector3 Perpendicular(this Vector3 v)
    Parameters
    Type Name Description
    Vector3 v

    Input vector.

    Returns
    Type Description
    Vector3

    Perpendicular vector.

    | Edit this page View Source

    PointInTriangle(Vector3, Vector3, Vector3, Vector3, float)

    Checks if a point lies inside a triangle.

    Declaration
    public static bool PointInTriangle(Vector3 A, Vector3 B, Vector3 C, Vector3 P, float dotThreshold = 0.001)
    Parameters
    Type Name Description
    Vector3 A

    First triangle vertex.

    Vector3 B

    Second triangle vertex.

    Vector3 C

    Third triangle vertex.

    Vector3 P

    Point to test.

    float dotThreshold

    Tolerance for point-on-plane test.

    Returns
    Type Description
    bool

    True if point is inside triangle.

    | Edit this page View Source

    PointIsInsideRect(Vector2)

    Checks if a 2D point is inside the screen rectangle.

    Declaration
    public static bool PointIsInsideRect(Vector2 point)
    Parameters
    Type Name Description
    Vector2 point

    Point to check.

    Returns
    Type Description
    bool

    True if point is inside screen bounds.

    | Edit this page View Source

    ProjectedMeshArea(Mesh, Vector3)

    Calculates area of a mesh as viewed from the direction vector.

    Declaration
    public static float ProjectedMeshArea(Mesh mesh, Vector3 direction)
    Parameters
    Type Name Description
    Mesh mesh
    Vector3 direction
    Returns
    Type Description
    float
    | Edit this page View Source

    QuadLerp(Vector3, Vector3, Vector3, Vector3, float, float)

    Performs bilinear interpolation on a quad defined by four points.

    Declaration
    public static Vector3 QuadLerp(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float u, float v)
    Parameters
    Type Name Description
    Vector3 a

    First corner.

    Vector3 b

    Second corner.

    Vector3 c

    Third corner.

    Vector3 d

    Fourth corner.

    float u

    U parameter (0-1).

    float v

    V parameter (0-1).

    Returns
    Type Description
    Vector3

    Interpolated point.

    | Edit this page View Source

    QuaternionMagnitude(Quaternion)

    Calculates the magnitude of a quaternion.

    Declaration
    public static float QuaternionMagnitude(Quaternion q)
    Parameters
    Type Name Description
    Quaternion q

    Quaternion.

    Returns
    Type Description
    float

    Magnitude.

    | Edit this page View Source

    RectArea(Vector3, Vector3, Vector3, Vector3)

    Calculates the area of a rectangle from four corner points.

    Declaration
    public static float RectArea(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4)
    Parameters
    Type Name Description
    Vector3 p1

    First corner.

    Vector3 p2

    Second corner.

    Vector3 p3

    Third corner.

    Vector3 p4

    Fourth corner.

    Returns
    Type Description
    float

    Area of the rectangle.

    | Edit this page View Source

    RotatePointAroundPivot(Vector3, Vector3, Vector3)

    Rotates a point around a pivot by the specified angles.

    Declaration
    public static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)
    Parameters
    Type Name Description
    Vector3 point

    Point to rotate.

    Vector3 pivot

    Pivot point.

    Vector3 angles

    Euler angles for rotation.

    Returns
    Type Description
    Vector3

    Rotated point.

    | Edit this page View Source

    RoundToStep(int, int)

    Rounds a value to the nearest multiple of step.

    Declaration
    public static float RoundToStep(int value, int step)
    Parameters
    Type Name Description
    int value

    Value to round.

    int step

    Step size.

    Returns
    Type Description
    float

    Rounded value.

    | Edit this page View Source

    RoundToStep(float, float)

    Rounds a value to the nearest multiple of step.

    Declaration
    public static float RoundToStep(float value, float step)
    Parameters
    Type Name Description
    float value

    Value to round.

    float step

    Step size.

    Returns
    Type Description
    float

    Rounded value.

    | Edit this page View Source

    RoundedMax(Vector3)

    Returns a vector with only the largest component preserved (rounded to 1 or -1), others set to 0.

    Declaration
    public static Vector3 RoundedMax(this Vector3 v)
    Parameters
    Type Name Description
    Vector3 v

    Input vector.

    Returns
    Type Description
    Vector3

    Vector with dominant axis isolated.

    | Edit this page View Source

    SignedVolumeOfTriangle(Vector3, Vector3, Vector3)

    Calculates the signed volume contribution of a triangle relative to the origin.

    Declaration
    public static float SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3)
    Parameters
    Type Name Description
    Vector3 p1

    First vertex.

    Vector3 p2

    Second vertex.

    Vector3 p3

    Third vertex.

    Returns
    Type Description
    float

    Signed volume.

    | Edit this page View Source

    SquareDistance(Vector3, Vector3)

    Calculates squared distance between two points. Faster than regular distance.

    Declaration
    public static float SquareDistance(Vector3 a, Vector3 b)
    Parameters
    Type Name Description
    Vector3 a

    First point.

    Vector3 b

    Second point.

    Returns
    Type Description
    float

    Squared distance.

    | Edit this page View Source

    TransformPointUnscaled(Transform, Vector3)

    Transforms a point from local to world space without applying scale.

    Declaration
    public static Vector3 TransformPointUnscaled(this Transform transform, Vector3 position)
    Parameters
    Type Name Description
    Transform transform

    Transform to use.

    Vector3 position

    Local position.

    Returns
    Type Description
    Vector3

    World position without scale.

    | Edit this page View Source

    TriArea(Vector3, Vector3, Vector3)

    Calculates area of a single triangle from it's three points.

    Declaration
    public static float TriArea(Vector3 p1, Vector3 p2, Vector3 p3)
    Parameters
    Type Name Description
    Vector3 p1
    Vector3 p2
    Vector3 p3
    Returns
    Type Description
    float
    | Edit this page View Source

    TriArea(Vector3, Vector3, Vector3, Vector3)

    Declaration
    public static float TriArea(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 view)
    Parameters
    Type Name Description
    Vector3 p1
    Vector3 p2
    Vector3 p3
    Vector3 view
    Returns
    Type Description
    float
    | Edit this page View Source

    Vector3Abs(Vector3)

    Returns a vector with absolute values of all components.

    Declaration
    public static Vector3 Vector3Abs(Vector3 v)
    Parameters
    Type Name Description
    Vector3 v

    Input vector.

    Returns
    Type Description
    Vector3

    Vector with absolute values.

    | Edit this page View Source

    Vector3Lerp(Vector3, Vector3, float)

    Linear interpolation between two vectors with value clamping.

    Declaration
    public static Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float value)
    Parameters
    Type Name Description
    Vector3 v1

    Start vector.

    Vector3 v2

    End vector.

    float value

    Interpolation value (0-1).

    Returns
    Type Description
    Vector3

    Interpolated vector.

    | Edit this page View Source

    Vector3OneOver(Vector3)

    Returns a vector with reciprocal values (1/x, 1/y, 1/z).

    Declaration
    public static Vector3 Vector3OneOver(Vector3 v)
    Parameters
    Type Name Description
    Vector3 v

    Input vector.

    Returns
    Type Description
    Vector3

    Vector with reciprocal values.

    | Edit this page View Source

    Vector3RoundToInt(Vector3)

    Rounds all components of a vector to nearest integer.

    Declaration
    public static Vector3 Vector3RoundToInt(Vector3 v)
    Parameters
    Type Name Description
    Vector3 v

    Input vector.

    Returns
    Type Description
    Vector3

    Rounded vector.

    | Edit this page View Source

    VolumeOfMesh(Mesh)

    Calculates the volume enclosed by a mesh.

    Declaration
    public static float VolumeOfMesh(Mesh mesh)
    Parameters
    Type Name Description
    Mesh mesh

    Mesh to calculate volume for.

    Returns
    Type Description
    float

    Volume of the mesh.

    • Edit this page
    • View Source
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics