Kerbal Space Program  1.12.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
UtilMath Class Reference

Static Public Member Functions

static double ACosh (double x)
 
static double ACoth (double x)
 
static double ACsch (double x)
 
static double AngleBetween (Vector3d v, Vector3d w)
 Get the angle between two vectors minimizing errors due to rounding. Note that the "sign" of the angle is lost (ie, 0..pi) More...
 
static bool Approximately (double a, double b, double epsilon=Double.Epsilon)
 
static double ASech (double x)
 
static double ASinh (double x)
 
static double ATanh (double x)
 
static int BSPSolver (ref double v0, double dv, Func< double, double > solveFor, double vMin, double vMax, double epsilon, int maxIterations)
 Runs a root-finding algorithm looking for an input parameter which best fits the given problem More...
 
static int BSPSolver (ref float v0, float dv, Func< float, float > solveFor, float vMin, float vMax, float epsilon, int maxIterations)
 Runs a root-finding algorithm looking for an input parameter which best fits the given problem More...
 
static double Clamp (double value, double min, double max)
 
static double Clamp01 (double value)
 
static double ClampDegrees180 (double angle)
 
static double ClampDegrees360 (double angle)
 
static double ClampRadians (double angle)
 
static double ClampRadiansPI (double angle)
 
static double ClampRadiansTwoPI (double angle)
 
static double Coth (double x)
 
static double Csch (double x)
 
static double DegreesToRadians (double degrees)
 
static double Flatten (double z, double midPoint, double easing)
 
static double InverseLerp (double a, double b, double t)
 
static bool IsDivisible (int n, int byN)
 
static bool IsPowerOfTwo (int x)
 
static double Lerp (double a, double b, double t)
 
static double LerpUnclamped (double a, double b, double t)
 
static double Max (params double[] values)
 
static T MaxFrom< T > (Func< T, double > getValue, params T[] values)
 
static T MaxFrom< T > (Func< T, double > getValue, out double max, params T[] values)
 
static T MaxFrom< T > (Func< T, float > getValue, params T[] values)
 
static T MaxFrom< T > (Func< T, float > getValue, out float max, params T[] values)
 
static double Min (params double[] values)
 
static T MinFrom< T > (Func< T, double > getValue, params T[] values)
 
static T MinFrom< T > (Func< T, double > getValue, out double min, params T[] values)
 
static T MinFrom< T > (Func< T, float > getValue, params T[] values)
 
static T MinFrom< T > (Func< T, float > getValue, out float min, params T[] values)
 
static double RadiansToDegrees (double radians)
 
static float RoundToPlaces (float value, int decimalPlaces)
 
static double RoundToPlaces (double value, int decimalPlaces)
 
static double Sech (double x)
 
static bool SphereIntersection (double radius, Vector3d position, Vector3d velocity, out double time, bool later)
 Find the intersection time of a ray starting at position with the given velocity with a sphere with the given radius centered on the origin. More...
 
static bool SphereIntersection (double radius, Vector3d position, Vector3d velocity, out Vector3d impact, bool later)
 Find the intersection of a ray starting at position with the given velocity with a sphere with the given radius centered on the origin. More...
 
static void SwapValues (ref double a, ref double b)
 
static float WrapAround (float value, float min, float max)
 
static double WrapAround (double value, double min, double max)
 
static int WrapAround (int value, int min, int max)
 

Public Attributes

const double Deg2Rad = 0.017453292519943296d
 
const double Rad2Deg = 57.295779513082321d
 

Static Public Attributes

static double HalfPI = 1.5707963267948966192313216916398
 
static float HalfPIf = 1.5707963267948966192313216916398f
 
static float RadPerSec2RPM = 60f / TwoPIf
 
static float RPM2RadPerSec = TwoPIf / 60f
 
static double TwoPI = 6.283185307179586476925286766559
 
static float TwoPIf = 6.283185307179586476925286766559f
 

Member Function Documentation

static double UtilMath.ACosh ( double  x)
inlinestatic
static double UtilMath.ACoth ( double  x)
inlinestatic
static double UtilMath.ACsch ( double  x)
inlinestatic
static double UtilMath.AngleBetween ( Vector3d  v,
Vector3d  w 
)
inlinestatic

Get the angle between two vectors minimizing errors due to rounding. Note that the "sign" of the angle is lost (ie, 0..pi)

static bool UtilMath.Approximately ( double  a,
double  b,
double  epsilon = Double.Epsilon 
)
inlinestatic
static double UtilMath.ASech ( double  x)
inlinestatic
static double UtilMath.ASinh ( double  x)
inlinestatic
static double UtilMath.ATanh ( double  x)
inlinestatic
static int UtilMath.BSPSolver ( ref double  v0,
double  dv,
Func< double, double >  solveFor,
double  vMin,
double  vMax,
double  epsilon,
int  maxIterations 
)
inlinestatic

Runs a root-finding algorithm looking for an input parameter which best fits the given problem

Parameters
v0In: initial guess, Out: converged result
dvinitial test range
solveForThe problem to solve. Ideal solution must be == 0
vMinA clamp on low end inputs
vMaxA clamp on high end inputs
epsilonThe minimum precision to solve for
maxIterationsLimit on how many iterations may be run
Returns
The number of iterations run by the solver

< Binary Space Partitioning Solver

< don't allow v0 to go into beyond limits by forcing such samples to be impossibly useless.

static int UtilMath.BSPSolver ( ref float  v0,
float  dv,
Func< float, float >  solveFor,
float  vMin,
float  vMax,
float  epsilon,
int  maxIterations 
)
inlinestatic

Runs a root-finding algorithm looking for an input parameter which best fits the given problem

Parameters
v0In: initial guess, Out: converged result
dvinitial test range
solveForThe problem to solve. Ideal solution must be == 0
vMinA clamp on low end inputs
vMaxA clamp on high end inputs
epsilonThe minimum precision to solve for
maxIterationsLimit on how many iterations may be run
Returns
The number of iterations run by the solver<returns>

< Binary Space Partitioning Solver

< don't allow v0 to go into beyond limits by forcing such samples to be impossibly useless.

static double UtilMath.Clamp ( double  value,
double  min,
double  max 
)
inlinestatic
static double UtilMath.Clamp01 ( double  value)
inlinestatic
static double UtilMath.ClampDegrees180 ( double  angle)
inlinestatic
static double UtilMath.ClampDegrees360 ( double  angle)
inlinestatic
static double UtilMath.ClampRadians ( double  angle)
inlinestatic
static double UtilMath.ClampRadiansPI ( double  angle)
inlinestatic
static double UtilMath.ClampRadiansTwoPI ( double  angle)
inlinestatic
static double UtilMath.Coth ( double  x)
inlinestatic
static double UtilMath.Csch ( double  x)
inlinestatic
static double UtilMath.DegreesToRadians ( double  degrees)
inlinestatic
static double UtilMath.Flatten ( double  z,
double  midPoint,
double  easing 
)
inlinestatic

'Flattens' a boundless value 0-x-Inf into 0-1 space, approaching 1 as x approaches infinity

see "http://graph.tk/?1/1-(1/((1/4x)^2+1))"

Parameters
zThe source value
midPointthe point at which z return 0.5
easingan easing in value. values greater than one cause x to accelerate towards the midpoint
Returns
static double UtilMath.InverseLerp ( double  a,
double  b,
double  t 
)
inlinestatic
static bool UtilMath.IsDivisible ( int  n,
int  byN 
)
inlinestatic
static bool UtilMath.IsPowerOfTwo ( int  x)
inlinestatic
static double UtilMath.Lerp ( double  a,
double  b,
double  t 
)
inlinestatic
static double UtilMath.LerpUnclamped ( double  a,
double  b,
double  t 
)
inlinestatic
static double UtilMath.Max ( params double[]  values)
inlinestatic
static T UtilMath.MaxFrom< T > ( Func< T, double >  getValue,
params T[]  values 
)
inlinestatic
static T UtilMath.MaxFrom< T > ( Func< T, double >  getValue,
out double  max,
params T[]  values 
)
inlinestatic
static T UtilMath.MaxFrom< T > ( Func< T, float >  getValue,
params T[]  values 
)
inlinestatic
static T UtilMath.MaxFrom< T > ( Func< T, float >  getValue,
out float  max,
params T[]  values 
)
inlinestatic
static double UtilMath.Min ( params double[]  values)
inlinestatic
static T UtilMath.MinFrom< T > ( Func< T, double >  getValue,
params T[]  values 
)
inlinestatic
static T UtilMath.MinFrom< T > ( Func< T, double >  getValue,
out double  min,
params T[]  values 
)
inlinestatic
static T UtilMath.MinFrom< T > ( Func< T, float >  getValue,
params T[]  values 
)
inlinestatic
static T UtilMath.MinFrom< T > ( Func< T, float >  getValue,
out float  min,
params T[]  values 
)
inlinestatic
static double UtilMath.RadiansToDegrees ( double  radians)
inlinestatic
static float UtilMath.RoundToPlaces ( float  value,
int  decimalPlaces 
)
inlinestatic
static double UtilMath.RoundToPlaces ( double  value,
int  decimalPlaces 
)
inlinestatic
static double UtilMath.Sech ( double  x)
inlinestatic
static bool UtilMath.SphereIntersection ( double  radius,
Vector3d  position,
Vector3d  velocity,
out double  time,
bool  later 
)
inlinestatic

Find the intersection time of a ray starting at position with the given velocity with a sphere with the given radius centered on the origin.

Returns
true if the ray hit the sphere, in which case time is the chosen impact time, or false if there is no impact (time will be 0).
static bool UtilMath.SphereIntersection ( double  radius,
Vector3d  position,
Vector3d  velocity,
out Vector3d  impact,
bool  later 
)
inlinestatic

Find the intersection of a ray starting at position with the given velocity with a sphere with the given radius centered on the origin.

Returns
true if the ray hit the sphere, in which case impact is the point of the chosen impact time, or false if there is no impact.
static void UtilMath.SwapValues ( ref double  a,
ref double  b 
)
inlinestatic
static float UtilMath.WrapAround ( float  value,
float  min,
float  max 
)
inlinestatic
static double UtilMath.WrapAround ( double  value,
double  min,
double  max 
)
inlinestatic
static int UtilMath.WrapAround ( int  value,
int  min,
int  max 
)
inlinestatic

Member Data Documentation

const double UtilMath.Deg2Rad = 0.017453292519943296d
double UtilMath.HalfPI = 1.5707963267948966192313216916398
static
float UtilMath.HalfPIf = 1.5707963267948966192313216916398f
static
const double UtilMath.Rad2Deg = 57.295779513082321d
float UtilMath.RadPerSec2RPM = 60f / TwoPIf
static
float UtilMath.RPM2RadPerSec = TwoPIf / 60f
static
double UtilMath.TwoPI = 6.283185307179586476925286766559
static
float UtilMath.TwoPIf = 6.283185307179586476925286766559f
static

The documentation for this class was generated from the following file: