private static double incidenceLineCircle(CartesianCoordinate point1, CartesianCoordinate point2, double radius)
        {
            double determinant = point1.CrossProduct(point2);
            double lineLength  = AlgebraLibrary.SRSS((point2.X - point1.X), (point2.Y - point1.Y));

            return(incidenceLineCircle(radius, lineLength, determinant));
        }
 /// <summary>
 /// Converts to Polar coordinates.
 /// </summary>
 /// <returns>PolarCoordinate.</returns>
 public static PolarCoordinate ToPolar(CartesianCoordinate coordinate)
 {
     return(new PolarCoordinate(
                radius: AlgebraLibrary.SRSS(coordinate.X, coordinate.Y),
                azimuth: Angle.AsRadians(coordinate.X, coordinate.Y),
                tolerance: coordinate.Tolerance));
 }
        /// <summary>
        /// Converts to spherical coordinates.
        /// </summary>
        /// <returns>SphericalCoordinate.</returns>
        public static SphericalCoordinate ToSpherical(CartesianCoordinate3D coordinate)
        {
            double radialDistance   = AlgebraLibrary.SRSS(coordinate.X, coordinate.Y.Squared(), coordinate.Z.Squared());
            double angleAzimuth     = NMath.Atan(coordinate.Y / coordinate.X);
            double angleInclination = NMath.Acos(coordinate.Z / radialDistance);

            return(new SphericalCoordinate(radialDistance, angleInclination, angleAzimuth, coordinate.Tolerance));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the magnitude from parametric vector components.
        /// </summary>
        /// <param name="xComponent">The x component.</param>
        /// <param name="yComponent">The y component.</param>
        /// <param name="zComponent">The z component.</param>
        /// <param name="tolerance">The tolerance.</param>
        /// <returns>System.Double.</returns>
        /// <exception cref="Exception">Ill-formed vector. Vector magnitude cannot be zero.</exception>
        public static double Magnitude3D(
            double xComponent, double yComponent, double zComponent,
            double tolerance = Numbers.ZeroTolerance)
        {
            double magnitude = AlgebraLibrary.SRSS(xComponent, yComponent, zComponent);

            return(validatedMagnitude(magnitude, tolerance));
        }
        /// <summary>
        /// Converts to spherical coordinates.
        /// </summary>
        /// <returns>SphericalCoordinate.</returns>
        public static SphericalCoordinate ToSpherical(CylindricalCoordinate coordinate)
        {
            double radius      = AlgebraLibrary.SRSS(coordinate.Radius, coordinate.Height);
            double azimuth     = coordinate.Azimuth.Radians;
            double inclination = NMath.Atan(coordinate.Radius / coordinate.Height);

            return(new SphericalCoordinate(radius, inclination, azimuth, coordinate.Tolerance));
        }
Ejemplo n.º 6
0
        public static void InterpolationLinear2D_Height_0_Throws_ArgumentException()
        {
            CartesianCoordinate pO = new CartesianCoordinate(2.2, 3.3);
            CartesianCoordinate ii = new CartesianCoordinate(1.1, 2.2);
            CartesianCoordinate jj = new CartesianCoordinate(4.4, 2.2);

            Assert.Throws <ArgumentException>(() => { AlgebraLibrary.InterpolationLinear2D(pO, ii, jj, 1, 1, 1, 1); });
        }
Ejemplo n.º 7
0
        public static void InterpolationLinear2D_OutOfBounds_Throws_ArgumentOutOfRangeException()
        {
            CartesianCoordinate pO = new CartesianCoordinate(1, 2);
            CartesianCoordinate ii = new CartesianCoordinate(1.1, 2.2);
            CartesianCoordinate jj = new CartesianCoordinate(4.4, 6.6);

            Assert.Throws <ArgumentOutOfRangeException>(() => { AlgebraLibrary.InterpolationLinear2D(pO, ii, jj, 1, 1, 1, 1); });
        }
Ejemplo n.º 8
0
        public static void InterpolationLinear_Between_Two_Coordinates_Throws_Exception_if_Weight_Outside_Bounds(
            double x1, double y1,
            double x2, double y2, double point2Weight)
        {
            CartesianCoordinate coordinate1 = new CartesianCoordinate(x1, y1);
            CartesianCoordinate coordinate2 = new CartesianCoordinate(x2, y2);

            Assert.Throws <ArgumentOutOfRangeException>(() => { AlgebraLibrary.InterpolationLinear(coordinate1, coordinate2, point2Weight); });
        }
        /// <summary>
        /// The y-coordinates of a line intersecting a circle centered at 0,0.
        /// </summary>
        /// <param name="point1">First point forming the line.</param>
        /// <param name="point2">Second point forming the line.</param>
        /// <param name="radius">Radius of the circle centered at 0,0.</param>
        public static double[] CircleLineIntersectY(CartesianCoordinate point1, CartesianCoordinate point2, double radius)
        {
            CartesianOffset delta       = new CartesianOffset(point1, point2);
            double          determinant = point1.CrossProduct(point2);
            double          lineLength  = AlgebraLibrary.SRSS(delta.X(), delta.Y());
            double          incidence   = incidenceLineCircle(radius, lineLength, determinant);

            return(CircleLineIntersectY(radius, lineLength, incidence, determinant, delta));
        }
Ejemplo n.º 10
0
        public static void InterpolationLinear_Between_Two_Coordinates(double x1, double y1, double x2, double y2, double point2Weight, double expectedX, double expectedY)
        {
            CartesianCoordinate coordinate1 = new CartesianCoordinate(x1, y1);
            CartesianCoordinate coordinate2 = new CartesianCoordinate(x2, y2);

            CartesianCoordinate interpolatedCoordinate = AlgebraLibrary.InterpolationLinear(coordinate1, coordinate2, point2Weight);

            Assert.AreEqual(expectedX, interpolatedCoordinate.X);
            Assert.AreEqual(expectedY, interpolatedCoordinate.Y);
        }
Ejemplo n.º 11
0
        public static void CubicCurveRoots(double a, double b, double c, double d, double expectedRoot1, double expectedRoot2, double expectedRoot3)
        {
            double[] result = AlgebraLibrary.CubicCurveRoots(a, b, c, d);

            double result1 = result[0];
            double result2 = result.Length > 1 ? result[1] : result[0];  // Returns lowest root if only one is returned
            double result3 = result.Length > 2 ? result[2] : result[0];  // Returns lowest root if only one is returned

            Assert.AreEqual(expectedRoot1, result1, 0.001);
            Assert.AreEqual(expectedRoot2, result2, 0.001);
            Assert.AreEqual(expectedRoot3, result3, 0.001);
        }
Ejemplo n.º 12
0
        [TestCase(2.2, 3.3, 1.1, 2.2, 4.4, 6.6, 1.1, 2.2, 3.3, 4.4, 2.016667)] // All corners have different value, point not centered
        public static void InterpolationLinear2D(
            double col0, double row0,
            double iiCol, double iiRow,
            double jjCol, double jjRow,
            double iiValue, double ijValue, double jiValue, double jjValue,
            double expectedValue)
        {
            CartesianCoordinate pO = new CartesianCoordinate(col0, row0);
            CartesianCoordinate ii = new CartesianCoordinate(iiCol, iiRow);
            CartesianCoordinate jj = new CartesianCoordinate(jjCol, jjRow);

            double value = AlgebraLibrary.InterpolationLinear2D(pO, ii, jj, iiValue, ijValue, jiValue, jjValue);

            Assert.AreEqual(expectedValue, value, Tolerance);
        }
Ejemplo n.º 13
0
            /// <summary>
            /// Initializes a new instance of the <see cref="IntersectionProperties"/> class.
            /// </summary>
            /// <param name="linearCurve">The linear curve.</param>
            /// <param name="circularCurve">The circular curve.</param>
            public IntersectionProperties(LinearCurve linearCurve, CircularCurve circularCurve)
            {
                Tolerance       = Generics.GetTolerance(linearCurve, circularCurve);
                Transformations = new Transformations(circularCurve.LocalOrigin, new CartesianCoordinate(circularCurve.LocalOrigin.X + 1, circularCurve.LocalOrigin.Y));
                LinearCurve linearCurveLocal = transformToLocal(linearCurve);

                D = Numbers.ValueAsZeroIfWithinAbsoluteTolerance(linearCurveLocal.ControlPointI.CrossProduct(linearCurveLocal.ControlPointJ), Tolerance);
                CartesianOffset offset = linearCurveLocal.Range.End.Limit.OffsetFrom(linearCurveLocal.Range.Start.Limit);

                dx = offset.X();
                dy = offset.Y();
                dr = AlgebraLibrary.SRSS(dx, dy);

                IncidenceDelta = Numbers.ValueAsZeroIfWithinAbsoluteTolerance((circularCurve.Radius * dr).Squared() - D.Squared(), Tolerance);
            }
Ejemplo n.º 14
0
        /// <summary>
        /// Converts to cylindrical coordinates.
        /// </summary>
        /// <returns>CylindricalCoordinate.</returns>
        public static CylindricalCoordinate ToCylindrical(CartesianCoordinate3D coordinate)
        {
            double radialDistance = AlgebraLibrary.SRSS(coordinate.X, coordinate.Y);
            double height         = coordinate.Z;
            double angleAzimuth   = 0;

            if (coordinate.X.IsZeroSign() && coordinate.Y.IsZeroSign())
            {
                angleAzimuth = 0;
            }
            else if (coordinate.X.IsGreaterThanOrEqualTo(0) && !coordinate.Y.IsZeroSign())
            {
                angleAzimuth = NMath.Asin(coordinate.Y / radialDistance);
            }
            else if (coordinate.X.IsNegativeSign())
            {
                angleAzimuth = -NMath.Asin(coordinate.Y / radialDistance) + Numbers.Pi;
            }

            return(new CylindricalCoordinate(radialDistance, height, angleAzimuth, coordinate.Tolerance));
        }
Ejemplo n.º 15
0
        public static void CubicCurveLowestRoot(double a, double b, double c, double d, double expectedResult)
        {
            double result = AlgebraLibrary.CubicCurveLowestRoot(a, b, c, d);

            Assert.AreEqual(expectedResult, result, 0.001);
        }
Ejemplo n.º 16
0
 public static void QuadraticFormula_Throws_Exception_When_SQRT_of_Negative_Value()
 {
     Assert.Throws <ArgumentException>(() => { double[] results = AlgebraLibrary.QuadraticFormula(1, 1, 1); });  // operad2Sqrt = -3< 0
 }
Ejemplo n.º 17
0
 public static void QuadraticFormula_Throws_Exception_When_a_is_0(double a, double b, double c)
 {
     Assert.Throws <ArgumentException>(() => { double[] results = AlgebraLibrary.QuadraticFormula(a, b, c); });
 }
Ejemplo n.º 18
0
        public static void SRSS(double value1, double value2, double value3)
        {
            double expectedResult = NMath.Sqrt(value1.Squared() + value2.Squared() + value3.Squared());

            Assert.AreEqual(expectedResult, AlgebraLibrary.SRSS(value1, value2, value3));
        }
Ejemplo n.º 19
0
 public static void IntersectionX_Between_Two_Coordinates_Throws_Exception_for_Parallel_Line_of_Line_Formed()
 {
     Assert.Throws <ArgumentException>(() => { AlgebraLibrary.IntersectionX(3, new CartesianCoordinate(2, 3), new CartesianCoordinate(6, 3)); });
 }
Ejemplo n.º 20
0
 /// <summary>
 /// The linear distance the coordinate is from the origin.
 /// </summary>
 /// <returns>System.Double.</returns>
 public double DistanceFromOrigin()
 {
     return(AlgebraLibrary.SRSS(X, Y));
 }
Ejemplo n.º 21
0
 public static void InterpolationLinear_Between_Two_Values_Throws_Exception_if_Weight_Outside_Bounds(double value1, double value2, double point2Weight)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => { AlgebraLibrary.InterpolationLinear(value1, value2, point2Weight); });
 }
Ejemplo n.º 22
0
 public static void IntersectionX_Throws_Exception_for_Line_as_Point()
 {
     Assert.Throws <ArgumentException>(() => { AlgebraLibrary.IntersectionX(3, 2, 3, 2, 3); });
 }
Ejemplo n.º 23
0
        [TestCase(-1, 2, 3, -2, -3, -0.666667)] // negative slope
        public static void IntersectionX_Returns_X_Coordinate_Intersection(double y, double x1, double y1, double x2, double y2, double expectedX)
        {
            double result = AlgebraLibrary.IntersectionX(y, x1, y1, x2, y2);

            Assert.AreEqual(expectedX, result, Tolerance);
        }
Ejemplo n.º 24
0
 public static void QuadraticFormula(double a, double b, double c, double expectedPositive, double expectedNegative)
 {
     double[] results = AlgebraLibrary.QuadraticFormula(a, b, c);
     Assert.AreEqual(expectedNegative, results[0], Tolerance);
     Assert.AreEqual(expectedPositive, results[1], Tolerance);
 }
 /// <summary>
 /// Distance, c, from focus,f, to origin.
 /// </summary>
 /// <param name="a">a.</param>
 /// <param name="b">The b.</param>
 /// <returns>System.Double.</returns>
 protected static double distanceFromFocusToOrigin(double a, double b)
 {
     return(AlgebraLibrary.SRSS(a, b));
 }
 /// <summary>
 /// The separation distance between the provided points.
 /// </summary>
 /// <param name="coord1">The coord1.</param>
 /// <param name="coord2">The coord2.</param>
 /// <returns>System.Double.</returns>
 public static double Separation(CartesianCoordinate coord1, CartesianCoordinate coord2)
 {
     return(AlgebraLibrary.SRSS((coord2.X - coord1.X), (coord2.Y - coord1.Y)));
 }
Ejemplo n.º 27
0
        public static void InterpolationLinear_Between_Two_Values(double value1, double value2, double point2Weight, double expectedResult)
        {
            double interpolatedValue = AlgebraLibrary.InterpolationLinear(value1, value2, point2Weight);

            Assert.AreEqual(expectedResult, interpolatedValue);
        }
Ejemplo n.º 28
0
 public static void IntersectionX_Throws_Exception_for_Parallel_Line()
 {
     Assert.Throws <ArgumentException>(() => { AlgebraLibrary.IntersectionX(3, 2, 3, 6, 3); });
 }
Ejemplo n.º 29
0
        [TestCase(-1, 2, 3, -2, -3, -0.666667)] // negative slope
        public static void IntersectionX_Between_Two_Coordinates_Returns_X_Coordinate_Intersection_of_Line_Formed(double y, double x1, double y1, double x2, double y2, double expectedX)
        {
            double result = AlgebraLibrary.IntersectionX(y, new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2));

            Assert.AreEqual(expectedX, result, Tolerance);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// The total straight length of the offset.
 /// </summary>
 /// <returns>System.Double.</returns>
 public double Length()
 {
     return(AlgebraLibrary.SRSS(X(), Y(), Z()));
 }