Search Results for

    Show / Hide Table of Contents

    Class MathUtil

    Various utility functions for mathematical and numerical operations.

    Inheritance
    object
    MathUtil
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: NetTopologySuite.Mathematics
    Assembly: NetTopologySuite.dll
    Syntax
    public class MathUtil

    Fields

    | Edit this page View Source

    PhiInv

    The inverse of the Golden Ratio phi.

    Declaration
    public static readonly double PhiInv
    Field Value
    Type Description
    double

    Methods

    | Edit this page View Source

    Average(double, double)

    Computes the average of two numbers.

    Declaration
    public static double Average(double x1, double x2)
    Parameters
    Type Name Description
    double x1

    A number

    double x2

    A number

    Returns
    Type Description
    double

    The average of the inputs

    | Edit this page View Source

    Ceiling(int, int)

    Computes the ceiling function of the dividend of two integers.

    Declaration
    public static int Ceiling(int num, int denom)
    Parameters
    Type Name Description
    int num

    The numerator

    int denom

    The denominator

    Returns
    Type Description
    int

    The ceiling of num / denom

    | Edit this page View Source

    Clamp(double, double, double)

    Clamps a double value to a given range.

    Declaration
    public static double Clamp(double x, double min, double max)
    Parameters
    Type Name Description
    double x

    The value to clamp

    double min

    The minimum value of the range

    double max

    The maximum value of the range

    Returns
    Type Description
    double

    The clamped value

    | Edit this page View Source

    Clamp(int, int, int)

    Clamps a int value to a given range.

    Declaration
    public static int Clamp(int x, int min, int max)
    Parameters
    Type Name Description
    int x

    The value to clamp

    int min

    The minimum value of the range

    int max

    The maximum value of the range

    Returns
    Type Description
    int

    The clamped value

    | Edit this page View Source

    ClampMax(int, int)

    Clamps an integer to a given maximum limit.

    Declaration
    public static int ClampMax(int x, int max)
    Parameters
    Type Name Description
    int x

    The value to clamp

    int max

    The maximum value of the range

    Returns
    Type Description
    int

    The clamped value

    | Edit this page View Source

    Log10(double)

    Computes the base-10 logarithm of a double value.

    • If the argument is NaN or less than zero, then the result is NaN.
    • If the argument is positive infinity, then the result is positive infinity.
    • If the argument is positive zero or negative zero, then the result is negative infinity.
    Declaration
    public static double Log10(double x)
    Parameters
    Type Name Description
    double x

    A positive number

    Returns
    Type Description
    double

    The value log a, the base-10 logarithm of the input value

    | Edit this page View Source

    Max(double, double, double)

    Computes the maximum fo three values

    Declaration
    public static double Max(double v1, double v2, double v3)
    Parameters
    Type Name Description
    double v1

    A number

    double v2

    A number

    double v3

    A number

    Returns
    Type Description
    double

    The maximum value of v1, v2 and v3

    | Edit this page View Source

    Max(double, double, double, double)

    Computes the maximum of four values

    Declaration
    public static double Max(double v1, double v2, double v3, double v4)
    Parameters
    Type Name Description
    double v1

    A number

    double v2

    A number

    double v3

    A number

    double v4

    A number

    Returns
    Type Description
    double

    The maximum value of v1, v2, v3 and v4

    | Edit this page View Source

    Min(double, double, double)

    Computes the minimum of four values

    Declaration
    public static double Min(double v1, double v2, double v3)
    Parameters
    Type Name Description
    double v1

    A number

    double v2

    A number

    double v3

    A number

    Returns
    Type Description
    double

    The minimum value of v1, v2 and v3

    | Edit this page View Source

    Min(double, double, double, double)

    Computes the minimum of four values

    Declaration
    public static double Min(double v1, double v2, double v3, double v4)
    Parameters
    Type Name Description
    double v1

    A number

    double v2

    A number

    double v3

    A number

    double v4

    A number

    Returns
    Type Description
    double

    The minimum value of v1, v2, v3 and v4

    | Edit this page View Source

    QuasiRandom(double)

    Generates a quasi-random sequence of numbers in the range [0,1]. They are produced by an additive recurrence with 1/φ as the constant. This produces a low-discrepancy sequence which is more evenly distribute than random numbers.

    See Wikipedia: Low-discrepancy Sequences - Additive Recurrence.

    The sequence is initialized by calling it with any positive fractional number; 0 works well for most uses.
    Declaration
    public static double QuasiRandom(double curr)
    Parameters
    Type Name Description
    double curr

    The current number in the sequence

    Returns
    Type Description
    double

    The next value in the sequence

    | Edit this page View Source

    QuasiRandom(double, double)

    Generates a quasi-random sequence of numbers in the range [0,1]. They are produced by an additive recurrence with constant α.

    R(α) :  tn = { t0 + nα },  n = 1,2,3,...

    When α is irrational this produces a Low discrepancy sequence which is more evenly distributed than random numbers.

    The sequence is initialized by calling it with any positive fractional number. 0 works well for most uses.
    Declaration
    public static double QuasiRandom(double curr, double alpha)
    Parameters
    Type Name Description
    double curr

    The current number in the sequence

    double alpha

    the sequence's additive constant

    Returns
    Type Description
    double

    The next value in the sequence

    | Edit this page View Source

    Shuffle(int)

    Generates a randomly-shuffled list of the integers from [0..n-1].

    One use is to randomize points inserted into a KdTree<T>.
    Declaration
    public static int[] Shuffle(int n)
    Parameters
    Type Name Description
    int n

    The number of integers to shuffle

    Returns
    Type Description
    int[]

    The shuffled array

    | Edit this page View Source

    Wrap(int, int)

    Computes an index which wraps around a given maximum value. For values >= 0, this is equals to val % max. For values < 0, this is equal to max - (-val) % max

    Declaration
    public static int Wrap(int index, int max)
    Parameters
    Type Name Description
    int index

    The index to wrap

    int max

    The maximum value (or modulus)

    Returns
    Type Description
    int

    The wrapped index

    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX