RhinoMath

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

Fields

DefaultAngleTolerance

#
Represents the default angle tolerance, used when no other values are provided.

This is one degree, expressed in radians.

public const double DefaultAngleTolerance = 0.017453292519943295
Remarks: This is equivalent to openNURBS ON_DEFAULT_ANGLE_TOLERANCE.

DefaultDistanceToleranceMillimeters

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

Epsilon

#
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.
public const double Epsilon = 2.220446049250313E-16
Remarks: This is equivalent to openNURBS ON_EPSILON.

HalfPI

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

InfiniteRadius

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

QuarterPI

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

SqrtEpsilon

#
Represents a default value that is used when comparing square roots.

This value is several orders of magnitude larger than ZeroTolerance.

public const double SqrtEpsilon = 1.490116119385E-08
Remarks: This is equivalent to openNURBS ON_SQRT_EPSILON.

Tau

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

TwoPI

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

UnsetIntIndex

#
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.
public const int UnsetIntIndex = -2147483647
Remarks: This is equivalent to openNURBS ON_UNSET_INT_INDEX.

UnsetSingle

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

UnsetValue

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

ZeroTolerance

#
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.
public const double ZeroTolerance = 2.3283064365386963E-10
Remarks: This is equivalent to openNURBS ON_ZERO_TOLERANCE.

Methods

Clamp

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

Clamp

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

CRC32

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

CRC32

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

CRC32

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

EpsilonEquals

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

EpsilonEquals

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

EvaluateNormal

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

EvaluateNormalPartials

#Since v7.0
Expert tool to evaluate partial derivatives of surface unit normal.
public static bool EvaluateNormalPartials(
ds,
First partial derivative.
dt,
First partial derivative.
dss,
Second partial derivative.
dst,
Second partial derivative.
dtt,
Second partial derivative.
ns,
First partial derivative of unit normal. If the Jacobian is degenerate, ns is set to zero.
nt
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
Expert tool to evaluate sectional curvature from surface derivatives and section plane normal.
public static bool EvaluateSectionalCurvature(
ds,
First partial derivative.
dt,
First partial derivative.
dss,
Second partial derivative.
dst,
Second partial derivative.
dtt,
Second partial derivative.
planeNormal,
Unit normal to section plane.
k
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(
integrandFunction,
context,
limits1,
limits2,
relativeTolerance,
absoluteTolerance,
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.
out double
errorBound
)

Integrate

#
public static double Integrate(
integrandFunction,
context,
limits1,
limits2,
relativeTolerance,
absoluteTolerance,
out double
errorBound
)

Integrate

#Since v9.0
public static double Integrate(
integrandFunction,
context,
surface,
relativeTolerance,
absoluteTolerance,
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.
out double
errorBound
)

Integrate

#
public static double Integrate(
integrandFunction,
context,
surface,
relativeTolerance,
absoluteTolerance,
out double
errorBound
)

Integrate

#Since v9.0
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.
public static double Integrate(
integrandFunction,
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,
First parameter passed into the integrand function.
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,
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,
Desired absolute tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= absolute_tolerance.
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.
out double
errorBound
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

#
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.
public static double Integrate(
integrandFunction,
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,
First parameter passed into the integrand function.
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,
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,
Desired absolute tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= absolute_tolerance.
out double
errorBound
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
Calculates the definite integral of a smooth (C-infinity) function using a Rhomberg integration technique. The calculation can be canceled through the cancellation token.
public static double Integrate(
integrandFunction,
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,
Anything you want to be passed to and used by the integrandFunction
limits,
Limits of integration. The integrand must be C-infinity on each interval (limits[0],limits[1]).
relativeTolerance,
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,
Desired absolute tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= absolute_tolerance.
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.
out double
errorBound
upper bound on the error in the calculation
)
If the calulation succeeds, then the numerical integral is returned. Otherwise double.NaN is returned.

Integrate

#
Calculates the definite integral of a smooth (C-infinity) function using a Rhomberg integration technique.
public static double Integrate(
integrandFunction,
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,
Anything you want to be passed to and used by the integrandFunction
limits,
Limits of integration. The integrand must be C-infinity on each interval (limits[0],limits[1]).
relativeTolerance,
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,
Desired absolute tolerance. If I = mathematical value and N = numerical integration value, then the algorithm will terminate when |I - N| <= absolute_tolerance.
out double
errorBound
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
Portrays an int index in text.
public static string IntIndexToString(
index
int number express as string.
)
The text representation of the int index.

IsValidDouble

#Since v5.0
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

public static bool IsValidDouble(
x
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
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

public static bool IsValidSingle(
x
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
Return number of meters per one unit of a given unit system
public static double MetersPerUnit()

ParseNumber

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

ToDegrees

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

ToRadians

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

TryParseNumber

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

UnitScale

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

UnitScale

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

Wrap

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