Show / Hide Table of Contents

Class M

Provides standard mathematical functions and helpers for different types.

Inheritance
System.Object
M
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Fusee.Math.Core
Assembly: Fusee.Math.Core.dll
Syntax
public static class M

Fields

E

Defines the value of E as a System.Single.

Declaration
public const float E = 2.71828175F
Field Value
Type Description
System.Single

EpsilonDouble

Defines the value which represents the machine epsilon for System.Double in C#.

Declaration
public const double EpsilonDouble = 1.11022302462516E-16
Field Value
Type Description
System.Double

EpsilonFloat

Defines the value which represents the machine epsilon for System.Single in C#.

Declaration
public const float EpsilonFloat = 1.192093E-07F
Field Value
Type Description
System.Single

Log10E

Defines the base-10 logarithm of E.

Declaration
public const float Log10E = 0.4342945F
Field Value
Type Description
System.Single

Log2E

Defines the base-2 logarithm of E.

Declaration
public const float Log2E = 1.442695F
Field Value
Type Description
System.Single

Pi

Defines the value of Pi as a System.Single.

Declaration
public const float Pi = 3.14159274F
Field Value
Type Description
System.Single

PiOver2

Defines the value of Pi divided by two as a System.Single.

Declaration
public const float PiOver2 = 1.57079637F
Field Value
Type Description
System.Single

PiOver3

Defines the value of Pi divided by three as a System.Single.

Declaration
public const float PiOver3 = 1.04719758F
Field Value
Type Description
System.Single

PiOver4

Defines the value of Pi divided by four as a System.Single.

Declaration
public const float PiOver4 = 0.7853982F
Field Value
Type Description
System.Single

PiOver6

Defines the value of Pi divided by six as a System.Single.

Declaration
public const float PiOver6 = 0.5235988F
Field Value
Type Description
System.Single

ThreePiOver2

Defines the value of Pi multiplied by 3 and divided by two as a System.Single.

Declaration
public const float ThreePiOver2 = 4.712389F
Field Value
Type Description
System.Single

TwoPi

Defines the value of Pi multiplied by two as a System.Single.

Declaration
public const float TwoPi = 6.28318548F
Field Value
Type Description
System.Single

Methods

BinomialCoefficient(Int32, Int32)

Calculates the binomial coefficient n above k.

Declaration
public static long BinomialCoefficient(int n, int k)
Parameters
Type Name Description
System.Int32 n

The n.

System.Int32 k

The k.

Returns
Type Description
System.Int64

n! / (k! * (n - k)!)

CalculateCentroid(IEnumerable<double3>)

Calculates the centroid point (mean) from given vertices in double precision.

Declaration
public static double3 CalculateCentroid(IEnumerable<double3> vertices)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<double3> vertices
Returns
Type Description
double3

CalculateCentroid(IEnumerable<float3>)

Calculates the centroid point (mean) from given vertices in single precision.

Declaration
public static float3 CalculateCentroid(IEnumerable<float3> vertices)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<float3> vertices
Returns
Type Description
float3

Clamp(Double, Double, Double)

Clamp a value to the given minimum and maximum vectors.

Declaration
public static double Clamp(double val, double min, double max)
Parameters
Type Name Description
System.Double val

Input value

System.Double min

Minimum value

System.Double max

Maximum value

Returns
Type Description
System.Double

The clamped value.

Clamp(Single, Single, Single)

Clamp a value to the given minimum and maximum vectors.

Declaration
public static float Clamp(float val, float min, float max)
Parameters
Type Name Description
System.Single val

Input value.

System.Single min

Minimum value.

System.Single max

Maximum value.

Returns
Type Description
System.Single

The clamped value.

Cos(Single)

Returns the Cos of the given value as float.

Declaration
public static float Cos(float val)
Parameters
Type Name Description
System.Single val

The value.

Returns
Type Description
System.Single

CreateCovarianceMatrix(double3, IEnumerable<double3>)

Generates a covariance matrix from given centroid and vertices in double precision.

Declaration
public static double4x4 CreateCovarianceMatrix(double3 centroid, IEnumerable<double3> vertices)
Parameters
Type Name Description
double3 centroid

The centroid of the current mesh or point cloud.

System.Collections.Generic.IEnumerable<double3> vertices

The vertex data.

Returns
Type Description
double4x4

CreateCovarianceMatrix(float3, IEnumerable<float3>)

Generates a covariance matrix from given centroid and vertices in single precision.

Declaration
public static float4x4 CreateCovarianceMatrix(float3 centroid, IEnumerable<float3> vertices)
Parameters
Type Name Description
float3 centroid

The centroid of the current mesh or point cloud.

System.Collections.Generic.IEnumerable<float3> vertices

The vertex data.

Returns
Type Description
float4x4

DegreesToRadians(Single)

Convert degrees to radians

Declaration
public static float DegreesToRadians(float degrees)
Parameters
Type Name Description
System.Single degrees

An angle in degrees

Returns
Type Description
System.Single

The angle expressed in radians

DegreesToRadiansD(Double)

Convert degrees to radians

Declaration
public static double DegreesToRadiansD(double degrees)
Parameters
Type Name Description
System.Double degrees

An angle in degrees

Returns
Type Description
System.Double

The angle expressed in radians

Equals(Double, Double)

Compares two double values for equality.

Declaration
public static bool Equals(double a, double b)
Parameters
Type Name Description
System.Double a

The first value.

System.Double b

The second value.

Returns
Type Description
System.Boolean

True if the numbers are equal.

Equals(Single, Single)

Compares two float values for equality.

Declaration
public static bool Equals(float a, float b)
Parameters
Type Name Description
System.Single a

The first value.

System.Single b

The second value.

Returns
Type Description
System.Boolean

True if the numbers are equal.

Factorial(Int32)

Calculates the factorial of a given natural number.

Declaration
public static long Factorial(int n)
Parameters
Type Name Description
System.Int32 n

The number.

Returns
Type Description
System.Int64

n!

Float4ToABGR(float4)

Converts a float4 to an ABGR value (Int64).

Declaration
public static uint Float4ToABGR(float4 value)
Parameters
Type Name Description
float4 value

The float4 to convert.

Returns
Type Description
System.UInt32

The ABGR value.

InverseSqrtFast(Double)

Returns an approximation of the inverse square root of left number.

Declaration
public static double InverseSqrtFast(double x)
Parameters
Type Name Description
System.Double x

A number.

Returns
Type Description
System.Double

An approximation of the inverse square root of the specified number, with an upper error bound of 0.001

Remarks

This is an improved implementation of the the method known as Carmack's inverse square root which is found in the Quake III source code. This implementation comes from http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see http://www.beyond3d.com/content/articles/8/

InverseSqrtFast(Single)

Returns an approximation of the inverse square root of left number.

Declaration
public static float InverseSqrtFast(float x)
Parameters
Type Name Description
System.Single x

A number.

Returns
Type Description
System.Single

An approximation of the inverse square root of the specified number, with an upper error bound of 0.001

Remarks

This is an improved implementation of the the method known as Carmack's inverse square root which is found in the Quake III source code. This implementation comes from http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see http://www.beyond3d.com/content/articles/8/

IsPowerOfTwo(Int32)

Determines whether the specified value is a power of two.

Declaration
public static bool IsPowerOfTwo(int val)
Parameters
Type Name Description
System.Int32 val

The value.

Returns
Type Description
System.Boolean

Lerp(Single, Single, Single)

Returns a new float value that is the linear blend of the 2 given floats

Declaration
public static float Lerp(float a, float b, float blend)
Parameters
Type Name Description
System.Single a

First input float

System.Single b

Second input float

System.Single blend

The blend factor. a when blend=0, b when blend=1.

Returns
Type Description
System.Single

a when blend=0, b when blend=1, and a linear combination otherwise

Max(Double, Double)

Calculates the maximum of a and b.

Declaration
public static double Max(double a, double b)
Parameters
Type Name Description
System.Double a

a.

System.Double b

b.

Returns
Type Description
System.Double

The maximum of a and b.

Max(Int16, Int16)

Calculates the maximum of a and b.

Declaration
public static short Max(short a, short b)
Parameters
Type Name Description
System.Int16 a

a.

System.Int16 b

b.

Returns
Type Description
System.Int16

The maximum of a and b.

Max(Int32, Int32)

Calculates the maximum of a and b.

Declaration
public static int Max(int a, int b)
Parameters
Type Name Description
System.Int32 a

a.

System.Int32 b

b.

Returns
Type Description
System.Int32

The maximum of a and b.

Max(Single, Single)

Calculates the maximum of a and b.

Declaration
public static float Max(float a, float b)
Parameters
Type Name Description
System.Single a

a.

System.Single b

b.

Returns
Type Description
System.Single

The maximum of a and b.

Max(UInt16, UInt16)

Calculates the maximum of a and b.

Declaration
public static ushort Max(ushort a, ushort b)
Parameters
Type Name Description
System.UInt16 a

a.

System.UInt16 b

b.

Returns
Type Description
System.UInt16

The maximum of a and b.

Max(UInt32, UInt32)

Calculates the maximum of a and b.

Declaration
public static uint Max(uint a, uint b)
Parameters
Type Name Description
System.UInt32 a

a.

System.UInt32 b

b.

Returns
Type Description
System.UInt32

The maximum of a and b.

Min(Double, Double)

Calculates the minimum of a and b.

Declaration
public static double Min(double a, double b)
Parameters
Type Name Description
System.Double a

a.

System.Double b

b.

Returns
Type Description
System.Double

The minimum of a and b.

Min(Int16, Int16)

Calculates the minimum of a and b.

Declaration
public static short Min(short a, short b)
Parameters
Type Name Description
System.Int16 a

a.

System.Int16 b

b.

Returns
Type Description
System.Int16

The minimum of a and b.

Min(Int32, Int32)

Calculates the minimum of a and b.

Declaration
public static int Min(int a, int b)
Parameters
Type Name Description
System.Int32 a

a.

System.Int32 b

b.

Returns
Type Description
System.Int32

The minimum of a and b.

Min(Single, Single)

Calculates the minimum of a and b.

Declaration
public static float Min(float a, float b)
Parameters
Type Name Description
System.Single a

a.

System.Single b

b.

Returns
Type Description
System.Single

The minimum of a and b.

Min(UInt16, UInt16)

Calculates the minimum of a and b.

Declaration
public static ushort Min(ushort a, ushort b)
Parameters
Type Name Description
System.UInt16 a

a.

System.UInt16 b

b.

Returns
Type Description
System.UInt16

The minimum of a and b.

Min(UInt32, UInt32)

Calculates the minimum of a and b.

Declaration
public static uint Min(uint a, uint b)
Parameters
Type Name Description
System.UInt32 a

a.

System.UInt32 b

b.

Returns
Type Description
System.UInt32

The minimum of a and b.

MinAngle(Double)

Wrap-around to keep angle in the interval of (-PI , +PI]

Declaration
public static double MinAngle(double angle)
Parameters
Type Name Description
System.Double angle

The angle to minimize.

Returns
Type Description
System.Double

The angle limited to a maximum magnitude of PI.

MinAngle(Single)

Wrap-around to keep angle in the interval of (-PI , +PI]

Declaration
public static float MinAngle(float angle)
Parameters
Type Name Description
System.Single angle

The angle to minimize.

Returns
Type Description
System.Single

The angle limited to a maximum magnitude of PI.

NextPowerOfTwo(Double)

Returns the next power of two that is larger than the specified number.

Declaration
public static double NextPowerOfTwo(double n)
Parameters
Type Name Description
System.Double n

The specified number.

Returns
Type Description
System.Double

The next power of two.

NextPowerOfTwo(Int32)

Returns the next power of two that is larger than the specified number.

Declaration
public static int NextPowerOfTwo(int n)
Parameters
Type Name Description
System.Int32 n

The specified number.

Returns
Type Description
System.Int32

The next power of two.

NextPowerOfTwo(Int64)

Returns the next power of two that is larger than the specified number.

Declaration
public static long NextPowerOfTwo(long n)
Parameters
Type Name Description
System.Int64 n

The specified number.

Returns
Type Description
System.Int64

The next power of two.

NextPowerOfTwo(Single)

Returns the next power of two that is larger than the specified number.

Declaration
public static float NextPowerOfTwo(float n)
Parameters
Type Name Description
System.Single n

The specified number.

Returns
Type Description
System.Single

The next power of two.

RadiansToDegrees(Single)

Convert radians to degrees

Declaration
public static float RadiansToDegrees(float radians)
Parameters
Type Name Description
System.Single radians

An angle in radians

Returns
Type Description
System.Single

The angle expressed in degrees

RadiansToDegreesD(Double)

Convert radians to degrees

Declaration
public static double RadiansToDegreesD(double radians)
Parameters
Type Name Description
System.Double radians

An angle in radians

Returns
Type Description
System.Double

The angle expressed in degrees

ScreenPointToWorld(float2, Single, float4x4, float4x4, float4x4, float4x4, Int32, Int32)

Calculates a world position from given screen point (e. g. mouse coordinates in window space coordinates) at any desired z coordinate specified by zPosition

Declaration
public static float3 ScreenPointToWorld(float2 windowCoordIn, float zPosition, float4x4 Projection, float4x4 View, float4x4 InvProjection, float4x4 InvView, int windowWidth, int windowHeight)
Parameters
Type Name Description
float2 windowCoordIn

Position in window space coordinates

System.Single zPosition

Desired z coordinate in clip space

float4x4 Projection

Projection matrix

float4x4 View

View matrix

float4x4 InvProjection

Inverse Projection matrix

float4x4 InvView

Inverse View matrix

System.Int32 windowWidth

Width of window

System.Int32 windowHeight

Height of window

Returns
Type Description
float3

Sin(Single)

Returns the Sin of the given value as float.

Declaration
public static float Sin(float val)
Parameters
Type Name Description
System.Single val

The value.

Returns
Type Description
System.Single

SineStep(Single)

Smoothes out the interpolation t when approaching 0.0 and 1.0, using the sinestep function.

Declaration
public static float SineStep(float t)
Parameters
Type Name Description
System.Single t

t will be clamped between 0.0 and 1.0.

Returns
Type Description
System.Single

Returns a value between 0.0 and 1.0, corresponding to t.

SmootherStep(Single)

Smoothes out the interpolation t when approaching 0.0 and 1.0, using the smootherstep function.

Declaration
public static float SmootherStep(float t)
Parameters
Type Name Description
System.Single t

t will be clamped between 0.0 and 1.0.

Returns
Type Description
System.Single

Returns a value between 0.0 and 1.0, corresponding to t.

SmoothStep(Single)

Smoothes out the interpolation t when approaching 0.0 and 1.0, using the smoothstep function.

Declaration
public static float SmoothStep(float t)
Parameters
Type Name Description
System.Single t

t will be clamped between 0.0 and 1.0.

Returns
Type Description
System.Single

Returns a value between 0.0 and 1.0, corresponding to t.

Step(Double, Double)

Generates a step function by comparing "val" to "edge". 0.0 is returned if "val" is smaller than "edge" and 1.0 is returned otherwise.

Declaration
public static double Step(double edge, double val)
Parameters
Type Name Description
System.Double edge

Specifies the location of the edge of the step function.

System.Double val

Specifies the value to be used to generate the step function.

Returns
Type Description
System.Double

Step(Single, Single)

Generates a step function by comparing "val" to "edge". 0.0 is returned if "val" is smaller than "edge" and 1.0 is returned otherwise.

Declaration
public static float Step(float edge, float val)
Parameters
Type Name Description
System.Single edge

Specifies the location of the edge of the step function.

System.Single val

Specifies the value to be used to generate the step function.

Returns
Type Description
System.Single

Swap(ref Double, ref Double)

Swaps two double values.

Declaration
public static void Swap(ref double a, ref double b)
Parameters
Type Name Description
System.Double a

The first value.

System.Double b

The second value.

Swap(ref Single, ref Single)

Swaps two float values.

Declaration
public static void Swap(ref float a, ref float b)
Parameters
Type Name Description
System.Single a

The first value.

System.Single b

The second value.

Generated by DocFX
GitHub Repo
Back to top