Class MathRoutines
- Namespace
- LightningChartLib.WinForms.Charting
- Assembly
- LightningChart.WinForms.Charting.NET4.dll
Chart tools provides versatile static methods
public class MathRoutines
- Inheritance
-
MathRoutines
- Inherited Members
Constructors
MathRoutines()
public MathRoutines()
Methods
AngleDegInFirstFullCircle(double)
Retrieve the input angle value as positive angle of the first full rotation in degrees.
Note that the range contains 0, but not the "full angle" of 360 degrees.
public static double AngleDegInFirstFullCircle(double value)
Parameters
valuedoubleAngle to find the equivalent angle in degrees.
Returns
- double
Angle matching the input in first full positive round as degrees.
AngleDiffDeg(double, double)
Solve smallest absolute difference between two angles in degrees. This takes in account the periodic nature of the values, meaning that full circles do not affect the difference.
Useful in comparing the difference of angles, e.g. on testing if angles are the same.
Note that the type of angle unit affects the result. Use AngleDiffRad(double, double) for radians.
public static double AngleDiffDeg(double angleDeg1, double angleDeg2)
Parameters
angleDeg1doubleOne of the angles to calculate the difference between in degrees. Order of parameter does not matter.
angleDeg2doubleOne of the angles to calculate the difference between in degrees. Order of parameter does not matter.
Returns
- double
Difference of provided angles in degrees. Always positive.
Remarks
Examples
350 to 10 = 20 degrees
10 to 350 = 20 degrees
-360 to 350 = 10 degrees
AngleDiffRad(double, double)
Solve smallest absolute difference between two angles in radians. This takes in account the periodic nature of the values, meaning that full circles do not affect the difference.
Useful in comparing the difference of angles, e.g. on testing if angles are the same.
Note that the type of angle unit affects the result. Use AngleDiffDeg(double, double) for degrees and examples.
public static double AngleDiffRad(double angleRad1, double angleRad2)
Parameters
angleRad1doubleOne of the angles to calculate the difference between in radians. Order of parameter does not matter.
angleRad2doubleOne of the angles to calculate the difference between in radians. Order of parameter does not matter.
Returns
- double
Difference of provided angles in radians. Always positive.
AngleRadInFirstFullCircle(double)
Retrieve the input angle value as positive angle of the first full rotation in radians.
Note that the range contains 0, but not the "full angle" of PI radians.
public static double AngleRadInFirstFullCircle(double value)
Parameters
valuedoubleAngle to find the equivalent angle in radians.
Returns
- double
Angle matching the input in first full positive round as radians.
CalcAngleOfLineVectorDouble(PointFloat, PointFloat)
Calculates angle of line going from pointFrom to pointTo
public static double CalcAngleOfLineVectorDouble(PointFloat pointFrom, PointFloat pointTo)
Parameters
pointFromPointFloatFrom point
pointToPointFloatTo point
Returns
- double
RotateAngle in radians, in range 0...2*Pi
CalcAngleOfLineVectorFloat(float, float, float, float)
Calculates angle of line going from pointFrom to pointTo
public static float CalcAngleOfLineVectorFloat(float x1, float y1, float x2, float y2)
Parameters
Returns
- float
RotateAngle in radians, in range 0...2*Pi
CalcTwoLinesIntersection(PointDouble2D, PointDouble2D, PointDouble2D, PointDouble2D, out PointDouble2D)
Calculates intersection point of two lines. Line 1: goes through A1 and A2 Line 2: goes through B1 and B2
public static bool CalcTwoLinesIntersection(PointDouble2D a1, PointDouble2D a2, PointDouble2D b1, PointDouble2D b2, out PointDouble2D intersection)
Parameters
a1PointDouble2DLine A point 1
a2PointDouble2DLine A point 2
b1PointDouble2DLine B point 1
b2PointDouble2DLine B point 2
intersectionPointDouble2Dintersection point output
Returns
- bool
Success status. Returns false if could not solve the intersection
CalcTwoLinesIntersection(PointFloat, PointFloat, PointFloat, PointFloat, out PointFloat)
Calculates intersection point of two lines. Line 1: goes through A1 and A2 Line 2: goes through B1 and B2
public static bool CalcTwoLinesIntersection(PointFloat a1, PointFloat a2, PointFloat b1, PointFloat b2, out PointFloat intersection)
Parameters
a1PointFloatLine A point 1
a2PointFloatLine A point 2
b1PointFloatLine B point 1
b2PointFloatLine B point 2
intersectionPointFloatintersection point output
Returns
- bool
Success status. Returns false if could not solve the intersection
DegreesAsRadians(double)
Convert degrees to radians.
public static double DegreesAsRadians(double value)
Parameters
valuedoubleDegrees value.
Returns
- double
Radians value.
DistanceOfPoints(PointFloat, PointFloat)
Calculates distance between two points.
public static float DistanceOfPoints(PointFloat point1, PointFloat point2)
Parameters
point1PointFloatPoint 1.
point2PointFloatPoint 2.
Returns
- float
Distance between two points.
Gaussian(double, double, double)
Gaussian function
public static double Gaussian(double input, double mean, double std)
Parameters
Returns
- double
returns M:LightningChartLib.WinForms.Charting.MathRoutines.Gaussian(System.Double,System.Double,System.Double)
Exceptions
GradsAsRadians(double)
Convert gradians to radians.
public static double GradsAsRadians(double value)
Parameters
valuedoubleRadians value.
Returns
- double
Gradians value.
Hypotrochoid(int, double, double[,], double, double, double, double, int)
Hyptrochoid
public static void Hypotrochoid(int counter, double iStep, double[,] points, double _xMax, double _yMax, double _yMin, double _xMin, int _iDeliveredPoints)
Parameters
counterintparam counter M:LightningChartLib.WinForms.Charting.MathRoutines.Hypotrochoid(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) iStepdoubleparam iStep M:LightningChartLib.WinForms.Charting.MathRoutines.Hypotrochoid(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) pointsdouble[,]param points M:LightningChartLib.WinForms.Charting.MathRoutines.Hypotrochoid(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _xMaxdoubleparam _xMax M:LightningChartLib.WinForms.Charting.MathRoutines.Hypotrochoid(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _yMaxdoubleparam _yMax M:LightningChartLib.WinForms.Charting.MathRoutines.Hypotrochoid(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _yMindoubleparam _yMin M:LightningChartLib.WinForms.Charting.MathRoutines.Hypotrochoid(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _xMindoubleparam _xMin M:LightningChartLib.WinForms.Charting.MathRoutines.Hypotrochoid(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _iDeliveredPointsintparam _iDeliveredPoints M:LightningChartLib.WinForms.Charting.MathRoutines.Hypotrochoid(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32)
LineIntersection(PointDouble2D, PointDouble2D, PointDouble2D, PointDouble2D, out PointDouble2D)
Calculates intersection point of two lines. Line 1: goes through A1 and A2. Line 2: goes through B1 and B2. Algorithm copied from http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
public static bool LineIntersection(PointDouble2D a1, PointDouble2D a2, PointDouble2D b1, PointDouble2D b2, out PointDouble2D intersection)
Parameters
a1PointDouble2DLine A point 1.
a2PointDouble2DLine A point 2.
b1PointDouble2DLine B point 1.
b2PointDouble2DLine B point 2.
intersectionPointDouble2DIntersection point output
Returns
- bool
Success status. Returns false if could not solve the intersection.
LineIntersection(PointFloat, PointFloat, PointFloat, PointFloat, out PointFloat)
Calculates intersection point of two lines. Line 1: goes through A1 and A2. Line 2: goes through B1 and B2. Algorithm copied from http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
public static bool LineIntersection(PointFloat a1, PointFloat a2, PointFloat b1, PointFloat b2, out PointFloat intersection)
Parameters
a1PointFloatLine A point 1.
a2PointFloatLine A point 2.
b1PointFloatLine B point 1.
b2PointFloatLine B point 2.
intersectionPointFloatIntersection point output
Returns
- bool
Success status. Returns false if could not solve the intersection.
LinearFitSolveFactors(double[], double[], out double, out double)
Calculate linear fit from given points. Makes best fit with Least Square regression method. A line equation is y = k*x + b, that is, y = gradient * x + coefficient
public static bool LinearFitSolveFactors(double[] x, double[] y, out double gradient, out double coefficient)
Parameters
xdouble[]X values
ydouble[]Y values
gradientdoubleLine gradient
coefficientdoubleCoefficient, Y value of intersection where X = 0
Returns
- bool
True if success
Remarks
X values array length must be equal to Y values array length
LinearRegression(double[], double[], double[])
Calculate linear line fit for given points
public static double[] LinearRegression(double[] xInFactorization, double[] yInFactorization, double[] xValuesToFit)
Parameters
xInFactorizationdouble[]X values that are used to calculate the factors. This is the point set where the regression line is fitted to.
yInFactorizationdouble[]Y values that are used to calculate the factors. Length must be equal to xInFactorization length.
xValuesToFitdouble[]X values whose Y values are to be solved, using the factors
Returns
- double[]
Fitted Y values, the length equals to xValuesToFit length. Returns null if failed.
MysteryCurve(int, double, double[,], double, double, double, double, int)
Mystery curve
public static void MysteryCurve(int counter, double iStep, double[,] points, double _xMax, double _yMax, double _yMin, double _xMin, int _iDeliveredPoints)
Parameters
counterintparam counter M:LightningChartLib.WinForms.Charting.MathRoutines.MysteryCurve(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) iStepdoubleparam iStep M:LightningChartLib.WinForms.Charting.MathRoutines.MysteryCurve(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) pointsdouble[,]param points M:LightningChartLib.WinForms.Charting.MathRoutines.MysteryCurve(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _xMaxdoubleparam _xMax M:LightningChartLib.WinForms.Charting.MathRoutines.MysteryCurve(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _yMaxdoubleparam _yMax M:LightningChartLib.WinForms.Charting.MathRoutines.MysteryCurve(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _yMindoubleparam _yMin M:LightningChartLib.WinForms.Charting.MathRoutines.MysteryCurve(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _xMindoubleparam _xMin M:LightningChartLib.WinForms.Charting.MathRoutines.MysteryCurve(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32) _iDeliveredPointsintparam _iDeliveredPoints M:LightningChartLib.WinForms.Charting.MathRoutines.MysteryCurve(System.Int32,System.Double,System.Double[0:,0:],System.Double,System.Double,System.Double,System.Double,System.Int32)
PointDistanceFromLine(PointFloat, PointFloat, PointFloat)
Calculates distance from line to point.
public static float PointDistanceFromLine(PointFloat p1, PointFloat p2, PointFloat p0)
Parameters
p1PointFloatLine point 1.
p2PointFloatLine point 2.
p0PointFloatPoint.
Returns
- float
Distance from line to point.
PointDistanceFromLine(PointFloat, PointFloat, PointFloat, out PointFloat, out float)
Calculates distance from line to point.
public static float PointDistanceFromLine(PointFloat p1, PointFloat p2, PointFloat p3, out PointFloat linePoint, out float coeff)
Parameters
p1PointFloatLine point 1.
p2PointFloatLine point 2.
p3PointFloatPoint.
linePointPointFloatPoint at line, which is nearest to of reference point.
coefffloatNormalized distance from p1 to linePoint.
Returns
- float
Distance from line to point.
PointDistanceFromLineSegment(PointFloat, PointFloat, PointFloat)
Calculates distance from line segment to point.
public static float PointDistanceFromLineSegment(PointFloat p1, PointFloat p2, PointFloat p0)
Parameters
p1PointFloatLine point 1.
p2PointFloatLine point 2.
p0PointFloatPoint.
Returns
- float
Distance from line segment to point.
PointInsidePolygon(PointFloat, PointFloat[])
Check whether point is inside polygon. Algorithm from: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html Copyright (c) 1970-2003, Wm. Randolph Franklin. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
- Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution.
- The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
public static bool PointInsidePolygon(PointFloat point, PointFloat[] polygon)
Parameters
pointPointFloatPoint.
polygonPointFloat[]Polygon points.
Returns
- bool
True, if point is inside polygon, false otherwise.
PolynomialRegression(double[], double[], double[], int)
Calculate polymial line fit. Calculates polynomial factors, and uses these factors to solve Y values based on given X value array.
public static double[] PolynomialRegression(double[] xInFactorization, double[] yInFactorization, double[] xValuesToFit, int order)
Parameters
xInFactorizationdouble[]X values that are used to calculate the factors. This is the point set where the regression line is fitted to.
yInFactorizationdouble[]Y values that are used to calculate the factors. Length must be equal to xInFactorization length.
xValuesToFitdouble[]X values whose Y values are to be solved, using the factors
orderintOrder of polynomial. Usually more than 3 shouldn't be used
Returns
- double[]
Fitted Y values, the length equals to xValuesToFit length. Returns null if failed.
PolynomialRegression(double[], double[], double[], int, out double[])
Calculate polymial line fit. Calculates polynomial factors, and uses these factors to solve Y values based on given X value array.
public static double[] PolynomialRegression(double[] xInFactorization, double[] yInFactorization, double[] xValuesToFit, int order, out double[] factors)
Parameters
xInFactorizationdouble[]X values that are used to calculate the factors. This is the point set where the regression line is fitted to.
yInFactorizationdouble[]Y values that are used to calculate the factors. Length must be equal to xInFactorization length.
xValuesToFitdouble[]X values whose Y values are to be solved, using the factors
orderintOrder of polynomial. Usually more than 3 shouldn't be used
factorsdouble[]Polynomial result factors, length = order+1. For example, when having order 2, you can plot line with equation: Y = factors[0] + factors[1]*X + factors[2]*X^2
Returns
- double[]
Fitted Y values, the length equals to xValuesToFit length. Returns null if failed.
RadiansAsDegrees(double)
Convert radians to degrees.
public static double RadiansAsDegrees(double value)
Parameters
valuedoubleRadians value.
Returns
- double
Degrees value.
RadiansAsDegreesString(double)
Make radians as degrees string.
public static string RadiansAsDegreesString(double value)
Parameters
valuedoubleRadians value.
Returns
- string
Radians as degrees string.
RadiansAsGrads(double)
Convert radians to gradians.
public static double RadiansAsGrads(double value)
Parameters
valuedoubleRadians value.
Returns
- double
Gradians value.
RadiansAsGradsString(double)
Make radians as gradians string.
public static string RadiansAsGradsString(double value)
Parameters
valuedoubleRadians value.
Returns
- string
Radians as gradians string.
RadiansAsString(double)
Make radians as string.
public static string RadiansAsString(double value)
Parameters
valuedoubleRadians value.
Returns
- string
Radians as string.
RelativeDistanceOfPoints(PointFloat, PointFloat)
Calculates relative distance between two points.
public static float RelativeDistanceOfPoints(PointFloat point1, PointFloat point2)
Parameters
point1PointFloatPoint 1.
point2PointFloatPoint 2.
Returns
- float
Relative distance between two points.
ReplaceNaNs(double[], double)
Replace NaN numbers with given value
public static void ReplaceNaNs(double[] array, double value)
Parameters
ReplaceNaNs(float[], float)
Replace NaN numbers with given value
public static void ReplaceNaNs(float[] array, float value)
Parameters
Rotate(PointFloat, double)
Rotate point.
public static PointFloat Rotate(PointFloat point, double angleRad)
Parameters
pointPointFloatPoint (in math coordinate system).
angleRaddoubleAngle in radians.
Returns
- PointFloat
Point in pixel coordinate system.
RoundToInt(double)
Convert double value to nearest integer. The fast way.
public static int RoundToInt(double x)
Parameters
xdoubleValue to convert
Returns
- int
Nearest integer
RoundToInt(float)
Convert float value to nearest integer. The fast way.
public static int RoundToInt(float x)
Parameters
xfloatValue to convert
Returns
- int
Nearest integer
StandardDeviation(double[])
Calculate standard deviation of values
public static double StandardDeviation(double[] values)
Parameters
valuesdouble[]values
Returns
- double
Stardard deviation