RhinoMath

public static class RhinoMath
Provides constants and static methods that are additional to Math.

Fields

DefaultAngleTolerance

#
public const double DefaultAngleTolerance = 0.017453292519943295
Represents the default angle tolerance, used when no other values are provided.

This is one degree, expressed in radians.

Remarks: This is equivalent to openNURBS ON_DEFAULT_ANGLE_TOLERANCE.

DefaultDistanceToleranceMillimeters

#
public const double DefaultDistanceToleranceMillimeters = 0.01
Get Rhino's default distance tolerance in millimeters.
Remarks: This is equivalent to openNURBS ON_DEFAULT_DISTANCE_TOLERANCE_MM.

Epsilon

#
public const double Epsilon = 2.220446049250313E-16
Gets the value of DBL_EPSILON, which is the smallest positive floating point number x such that 1 + x != 1. This is different than Double.Epsilon which is the smallest positive Double value that is greater than zero.
Remarks: This is equivalent to openNURBS ON_EPSILON.

HalfPI

#
public const double HalfPI = 1.5707963267948966
Quarter of a rotation. 90 degrees. 1.57...

InfiniteRadius

#Since v9.0
public const double InfiniteRadius = 1E+300
Value used to indicate a radius of curvature is infinite.

QuarterPI

#
public const double QuarterPI = 0.7853981633974483
One eigth of a rotation. 45 degrees. 0.78...

SqrtEpsilon

#
public const double SqrtEpsilon = 1.490116119385E-08
Represents a default value that is used when comparing square roots.

This value is several orders of magnitude larger than ZeroTolerance.

Remarks: This is equivalent to openNURBS ON_SQRT_EPSILON.

Tau

#
public const double Tau = 6.283185307179586
Ratio of circumference divided by radius. Full rotation. 360 degrees. 6.28...

TwoPI

#
public const double TwoPI = 6.283185307179586
Full rotation. 360 degrees. 6.28...

UnsetIntIndex

#
public const int UnsetIntIndex = -2147483647
When signed int values are used in a context where 0 and small negative values are valid indices and there needs to be a value that indicates the index is not set.
Remarks: This is equivalent to openNURBS ON_UNSET_INT_INDEX.

UnsetSingle

#
public const float UnsetSingle = -1.234321E+38
Gets the single precision floating point number that is considered 'unset' in Rhino.
Remarks: This is equivalent to openNURBS ON_UNSET_FLOAT.

UnsetValue

#
public const double UnsetValue = -1.23432101234321E+308
Gets the Rhino standard Unset value. Use this value rather than Double.NaN when a bogus floating point value is required.
Remarks: This is equivalent to openNURBS ON_UNSET_VALUE.

ZeroTolerance

#
public const double ZeroTolerance = 2.3283064365386963E-10
Gets Rhino's Zero Tolerance constant, which is 2^-32. In cases when an absolute "zero" tolerance is required to compare model space coordinates, ZeroTolerance is used. The value of ZeroTolerance should be no smaller than Epsilon and should be several orders of magnitude smaller than SqrtEpsilon.
Remarks: This is equivalent to openNURBS ON_ZERO_TOLERANCE.

Methods

Clamp

#Since v5.0
public static double Clamp(double value, double bound1, double bound2)
Limits a double to be specified within an interval of two numbers, by specifying a fixed minimum and maximum.
value (double)A number.
bound1 (double)A first bound.
bound2 (double)A second bound. This does not necessarily need to be larger or smaller than bound1.
The clamped value.

Clamp

#Since v5.0
public static int Clamp(int value, int bound1, int bound2)
Restricts a int to be specified within an interval of two integers.
value (int)An integer.
bound1 (int)A first bound.
bound2 (int)A second bound. This does not necessarily need to be larger or smaller than bound1.
The clamped value.

CRC32

#Since v5.0
[CLSCompliant(false)] public static uint CRC32(uint currentRemainder, byte[] buffer)
Advances the cyclic redundancy check value remainder given a byte array. http://en.wikipedia.org/wiki/Cyclic_redundancy_check.
currentRemainder (uint)The remainder from which to start.
buffer (byte[])The value to add to the current remainder.
The new current remainder.

CRC32

#ExampleSince v5.0
[CLSCompliant(false)] public static uint CRC32(uint currentRemainder, double value)
Advances the cyclic redundancy check value remainder given a double. http://en.wikipedia.org/wiki/Cyclic_redundancy_check.
currentRemainder (uint)The remainder from which to start.
value (double)The value to add to the current remainder.
The new current remainder.

CRC32

#Since v5.0
[CLSCompliant(false)] public static uint CRC32(uint currentRemainder, int value)
Advances the cyclic redundancy check value remainder given a int. http://en.wikipedia.org/wiki/Cyclic_redundancy_check.
currentRemainder (uint)The remainder from which to start.
value (int)The value to add to the current remainder.
The new current remainder.

EpsilonEquals

#Since v5.4
public static bool EpsilonEquals(double x, double y, double epsilon)
Compare two doubles for equality within some "epsilon" range
x (double)
y (double)
epsilon (double)

EpsilonEquals

#Since v5.4
public static bool EpsilonEquals(float x, float y, float epsilon)
Compare to floats for equality within some "epsilon" range
x (float)
y (float)
epsilon (float)

EvaluateNormal

#Since v7.0
public static bool EvaluateNormal(int limitDirection, Vector3d ds, Vector3d dt, Vector3d dss, Vector3d dst, Vector3d dtt, out Vector3d n)
Expert tool to evaluate surface unit normal.
limitDirection (int)Determines which direction is used to compute the limit, where: 0 = default, 1 = from quadrant I, 2 = from quadrant II, etc.
ds (Vector3d)First partial derivative.
dt (Vector3d)First partial derivative.
dss (Vector3d)Second partial derivative.
dst (Vector3d)Second partial derivative.
dtt (Vector3d)Second partial derivative.
n (out Vector3d)Unit normal.
True if successful, false otherwise.

EvaluateNormalPartials

#Since v7.0
public static bool EvaluateNormalPartials(Vector3d ds, Vector3d dt, Vector3d dss, Vector3d dst, Vector3d dtt, out Vector3d ns, out Vector3d nt)
Expert tool to evaluate partial derivatives of surface unit normal.
ds (Vector3d)First partial derivative.
dt (Vector3d)First partial derivative.
dss (Vector3d)Second partial derivative.
dst (Vector3d)Second partial derivative.
dtt (Vector3d)Second partial derivative.
ns (out Vector3d)First partial derivative of unit normal. If the Jacobian is degenerate, ns is set to zero.
nt (out Vector3d)First partial derivative of unit normal. If the Jacobian is degenerate, nt is set to zero.
true if Jacobian is non-degenerate, false if Jacobian is degenerate.

EvaluateSectionalCurvature

#Since v8.16
public static bool EvaluateSectionalCurvature(Vector3d ds, Vector3d dt, Vector3d dss, Vector3d dst, Vector3d dtt, Vector3d planeNormal, out Vector3d k)
Expert tool to evaluate sectional curvature from surface derivatives and section plane normal.
ds (Vector3d)First partial derivative.
dt (Vector3d)First partial derivative.
dss (Vector3d)Second partial derivative.
dst (Vector3d)Second partial derivative.
dtt (Vector3d)Second partial derivative.
planeNormal (Vector3d)Unit normal to section plane.
k (out Vector3d)Sectional curvature. Curvature of the intersection curve of the surface and plane through the surface point where the partial derivatives were evaluated.
True if successful. False if first partials are not linearly independent, in which case the k is set to zero.

Integrate

#Since v9.0
public static double Integrate(Func<object, int, double, double, double> integrandFunction, object context, Interval limits1, Interval limits2, double relativeTolerance, double absoluteTolerance, CancellationToken cancellationToken, out double errorBound)
integrandFunction (Func<object, int, double, double, double>)
context (object)
limits1 (Interval)
limits2 (Interval)
relativeTolerance (double)
absoluteTolerance (double)
cancellationToken (CancellationToken)Token used to cancel the calculation. Cancellation is cooperative: it is checked each time the integrand is evaluated, and a canceled calculation returns double.NaN.
errorBound (out double)

Integrate

#
public static double Integrate(Func<object, int, double, double, double> integrandFunction, object context, Interval limits1, Interval limits2, double relativeTolerance, double absoluteTolerance, out double errorBound)
integrandFunction (Func<object, int, double, double, double>)
context (object)
limits1 (Interval)
limits2 (Interval)
relativeTolerance (double)
absoluteTolerance (double)
errorBound (out double)

Integrate

#Since v9.0
public static double Integrate(Func<object, int, double, double, double> integrandFunction, object context, Surface surface, double relativeTolerance, double absoluteTolerance, CancellationToken cancellationToken, out double errorBound)
integrandFunction (Func<object, int, double, double, double>)
context (object)
surface (Surface)
relativeTolerance (double)
absoluteTolerance (double)
cancellationToken (CancellationToken)Token used to cancel the calculation. Cancellation is cooperative: it is checked each time the integrand is evaluated, and a canceled calculation returns double.NaN.
errorBound (out double)

Integrate

#
public static double Integrate(Func<object, int, double, double, double> integrandFunction, object context, Surface surface, double relativeTolerance, double absoluteTolerance, out double errorBound)
integrandFunction (Func<object, int, double, double, double>)
context (object)
surface (Surface)
relativeTolerance (double)
absoluteTolerance (double)
errorBound (out double)

Integrate

#Since v9.0
public static double Integrate(Func<object, int, double, double> integrandFunction, object context, Curve curve, double relativeTolerance, double absoluteTolerance, CancellationToken cancellationToken, out double errorBound)
Calculates the definite integral of a smooth (C-infinity) function of one variable using a Rhomberg integration technique and returns returns Integral(f(t)*|curve'(t)|*dt). The C-infinity requirement is used by the Rhomberg algorithm when estimating error bounds and convergence. If you choose to pass a C2 function, you are likely to converge while getting less accurate results and incorrect error bound estimates. Using a C0 or C1 fucntion will often return nonsense. The calculation can be canceled through the cancellation token.
integrandFunction (Func<object, int, double, double>)The integrand function is double f(ON__UINT_PTR context, int limit_direction, double t) and returns the value of the integrand at t. The limit_direction parameter will be -1, 0, or +1 and specifies which limit direction should be used in the evaluation. If limit_direction = 1, then the integrand may not be C-infinity at t and should be evaluated using the limit from above. If limit_direction = -1, then the integrand may not be C-infinity at t and should be evaluated using the limit from below. If limit_direction = 0, then the integrand is C-infinity at t and may and evaluation from above and below will return the same answer.
context (object)First parameter passed into the integrand function.
curve (Curve)The integration is performed over the C-infinity spans of the curve and |curve'(t)| is automatically included in the integrand. The integrand must be C-infinity on the intesection each curve span with the interval (limits[0],limits[1]). The curve may have any dimension.
relativeTolerance (double)Desired relative tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= relative_tolerance*|I|. For example, if you want to know the answer with 5 digits of accuracy, then pass 1e-5.
absoluteTolerance (double)Desired absolute tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= absolute_tolerance.
cancellationToken (CancellationToken)Token used to cancel the calculation. Cancellation is cooperative: it is checked each time the integrand is evaluated, and a canceled calculation returns double.NaN.
errorBound (out double)If error_bound is not nullptr, then the returned value is upper bound on the error in the calculation. If I = mathematical value and N = returned value, then |I - N| <= *error_bound;
If the calulation succeeds, then the numerical integral is returned. Otherwise ON_DBL_QNAN is returned.

Integrate

#
public static double Integrate(Func<object, int, double, double> integrandFunction, object context, Curve curve, double relativeTolerance, double absoluteTolerance, out double errorBound)
Calculates the definite integral of a smooth (C-infinity) function of one variable using a Rhomberg integration technique and returns returns Integral(f(t)*|curve'(t)|*dt). The C-infinity requirement is used by the Rhomberg algorithm when estimating error bounds and convergence. If you choose to pass a C2 function, you are likely to converge while getting less accurate results and incorrect error bound estimates. Using a C0 or C1 fucntion will often return nonsense.
integrandFunction (Func<object, int, double, double>)The integrand function is double f(ON__UINT_PTR context, int limit_direction, double t) and returns the value of the integrand at t. The limit_direction parameter will be -1, 0, or +1 and specifies which limit direction should be used in the evaluation. If limit_direction = 1, then the integrand may not be C-infinity at t and should be evaluated using the limit from above. If limit_direction = -1, then the integrand may not be C-infinity at t and should be evaluated using the limit from below. If limit_direction = 0, then the integrand is C-infinity at t and may and evaluation from above and below will return the same answer.
context (object)First parameter passed into the integrand function.
curve (Curve)The integration is performed over the C-infinity spans of the curve and |curve'(t)| is automatically included in the integrand. The integrand must be C-infinity on the intesection each curve span with the interval (limits[0],limits[1]). The curve may have any dimension.
relativeTolerance (double)Desired relative tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= relative_tolerance*|I|. For example, if you want to know the answer with 5 digits of accuracy, then pass 1e-5.
absoluteTolerance (double)Desired absolute tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= absolute_tolerance.
errorBound (out double)If error_bound is not nullptr, then the returned value is upper bound on the error in the calculation. If I = mathematical value and N = returned value, then |I - N| <= *error_bound;
If the calulation succeeds, then the numerical integral is returned. Otherwise ON_DBL_QNAN is returned.

Integrate

#Since v9.0
public static double Integrate(Func<object, int, double, double> integrandFunction, object context, Interval limits, double relativeTolerance, double absoluteTolerance, CancellationToken cancellationToken, out double errorBound)
Calculates the definite integral of a smooth (C-infinity) function using a Rhomberg integration technique. The calculation can be canceled through the cancellation token.
integrandFunction (Func<object, int, double, double>)The integrand function is double f(object context, int limit_direction, double t) and returns the value of the integrand at t. The limit_direction parameter will be -1, 0, or +1 and specifies which limit direction should be used in the evaluation. If limit_direction = 1, then the integrand may not be C-infinity at t and should be evaluated using the limit from above. If limit_direction = -1, then the integrand may not be C-infinity at t and should be evaluated using the limit from below. If limit_direction = 0, then the integrand is C-infinity at t and may and evaluation from above and below will return the same answer.
context (object)Anything you want to be passed to and used by the integrandFunction
limits (Interval)Limits of integration. The integrand must be C-infinity on each interval (limits[0],limits[1]).
relativeTolerance (double)Desired relative tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= relative_tolerance*|I|. For example, if you want to know the answer with 5 digits of accuracy, then pass 1e-5.
absoluteTolerance (double)Desired absolute tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= absolute_tolerance.
cancellationToken (CancellationToken)Token used to cancel the calculation. Cancellation is cooperative: it is checked each time the integrand is evaluated, and a canceled calculation returns double.NaN.
errorBound (out double)upper bound on the error in the calculation
If the calulation succeeds, then the numerical integral is returned. Otherwise double.NaN is returned.

Integrate

#
public static double Integrate(Func<object, int, double, double> integrandFunction, object context, Interval limits, double relativeTolerance, double absoluteTolerance, out double errorBound)
Calculates the definite integral of a smooth (C-infinity) function using a Rhomberg integration technique.
integrandFunction (Func<object, int, double, double>)The integrand function is double f(object context, int limit_direction, double t) and returns the value of the integrand at t. The limit_direction parameter will be -1, 0, or +1 and specifies which limit direction should be used in the evaluation. If limit_direction = 1, then the integrand may not be C-infinity at t and should be evaluated using the limit from above. If limit_direction = -1, then the integrand may not be C-infinity at t and should be evaluated using the limit from below. If limit_direction = 0, then the integrand is C-infinity at t and may and evaluation from above and below will return the same answer.
context (object)Anything you want to be passed to and used by the integrandFunction
limits (Interval)Limits of integration. The integrand must be C-infinity on each interval (limits[0],limits[1]).
relativeTolerance (double)Desired relative tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= relative_tolerance*|I|. For example, if you want to know the answer with 5 digits of accuracy, then pass 1e-5.
absoluteTolerance (double)Desired absolute tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= absolute_tolerance.
errorBound (out double)upper bound on the error in the calculation
If the calulation succeeds, then the numerical integral is returned. Otherwise double.NaN is returned.

IntIndexToString

#Since v6.0
public static string IntIndexToString(int index)
Portrays an int index in text.
index (int)int number express as string.
The text representation of the int index.

IsValidDouble

#Since v5.0
public static bool IsValidDouble(double x)
Determines whether a double value is valid within the RhinoCommon context.

Rhino does not use Double.NaN by convention, so this test evaluates to true if:

x is not equal to RhinoMath.UnsetValue

System.Double.IsNaN(x) evaluates to false

System.Double.IsInfinity(x) evaluates to false

x (double)double number to test for validity.
true if the number if valid, false if the number is NaN, Infinity or Unset.

IsValidSingle

#Since v5.0
public static bool IsValidSingle(float x)
Determines whether a float value is valid within the RhinoCommon context.

Rhino does not use Single.NaN by convention, so this test evaluates to true if:

x is not equal to RhinoMath.UnsetValue,

System.Single.IsNaN(x) evaluates to false

System.Single.IsInfinity(x) evaluates to false

x (float)float number to test for validity.
true if the number if valid, false if the number is NaN, Infinity or Unset.

MetersPerUnit

#Since v7.1
public static double MetersPerUnit(UnitSystem units)
Return number of meters per one unit of a given unit system
units (UnitSystem)

ParseNumber

#Since v6.0
public static double ParseNumber(string expression)
Evaluates command line math expression.
expression (string)
result
ArgumentNullExceptionexpression is null.
FormatExceptionexpression cannot be parsed.

ToDegrees

#Since v5.0
public static double ToDegrees(double radians)
Convert an angle from radians to degrees.
radians (double)Radians to convert (180 degrees equals pi radians).

ToRadians

#Since v5.0
public static double ToRadians(double degrees)
Convert an angle from degrees to radians.
degrees (double)Degrees to convert (180 degrees equals pi radians).

TryParseNumber

#Since v6.0
public static bool TryParseNumber(string expression, out double result)
Evaluates command line math expression.
expression (string)
result (out double)
true if successful otherwise false

UnitScale

#Since v8.0
public static double UnitScale(UnitSystem from, double fromMetersPerUnit, UnitSystem to, double toMetersPerUnit)
Computes the scale factor for changing the measurements unit systems.
from (UnitSystem)The system to convert from.
fromMetersPerUnit (double)For custom units, specify the meters per unit.
to (UnitSystem)The system to convert measurements into.
toMetersPerUnit (double)For custom units, specify the meters per unit.
A scale multiplier.

UnitScale

#Since v5.0
public static double UnitScale(UnitSystem from, UnitSystem to)
Computes the scale factor for changing the measurements unit systems.
from (UnitSystem)The system to convert from.
to (UnitSystem)The system to convert measurements into.
A scale multiplier.

Wrap

#Since v7.1
public static double Wrap(double value, double bound1, double bound2)
Limits a double to be specified within an interval of two numbers by repeating the available interval cyclically.
value (double)A number.
bound1 (double)A first bound.
bound2 (double)A second bound. This does not necessarily need to be larger or smaller than bound1.