Esempio n. 1
0
        /// <summary>
        /// Returns a regular polygon sized by the inradius.
        /// </summary>
        /// <param name="numberOfSides">The number of sides.</param>
        /// <param name="inRadius">The inradius.</param>
        /// <returns>RegularPolygon.</returns>
        public static RegularPolygon RegularPolygonByInradius(int numberOfSides, double inRadius)
        {
            numberOfSides = NMath.Max(_minNumberOfSides, numberOfSides.Abs());
            double circumRadius = inRadius.Abs() * Trig.Sec(Numbers.Pi / numberOfSides);

            return(new RegularPolygon(numberOfSides, circumRadius));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="IsoscelesTriangle" /> class.
 /// </summary>
 /// <param name="lengthB">The length b, of the base of the triangle. This is the unequal length.</param>
 /// <param name="anglesEqualAlpha">The two angles of equal magnitude, α, which are opposite of the two sides of equal length.</param>
 public IsoscelesTriangle(double lengthB, Angle anglesEqualAlpha)
 {
     _sidesEqual  = 0.5 * lengthB / Trig.Cos(anglesEqualAlpha.Radians);
     _sideUnequal = lengthB;
     SetCoordinates(LocalCoordinates());
     setCenterCoordinates();
 }
Esempio n. 3
0
        /// <summary>
        /// Rotates the specified coordinate by the specifed angle about the origin.
        /// </summary>
        /// <param name="coordinate">The coordinate.</param>
        /// <param name="angleRadians">The angle [radians], where counter-clockwise is positive.</param>
        /// <returns>MPT.Math.Coordinates.CartesianCoordinate.</returns>
        public static CartesianCoordinate Rotate(CartesianCoordinate coordinate, double angleRadians)
        {
            double xRotated = coordinate.X * Trig.Cos(angleRadians) - coordinate.Y * Trig.Sin(angleRadians);
            double yRotated = coordinate.X * Trig.Sin(angleRadians) + coordinate.Y * Trig.Cos(angleRadians);

            return(new CartesianCoordinate(xRotated, yRotated));
        }
        /// <summary>
        /// Converts to Cartesian coordinates.
        /// </summary>
        /// <returns>CartesianCoordinate.</returns>
        public static CartesianCoordinate ToCartesian(PolarCoordinate coordinate)
        {
            double x = coordinate.Radius * Trig.Cos(coordinate.Azimuth.Radians);
            double y = coordinate.Radius * Trig.Sin(coordinate.Azimuth.Radians);

            return(new CartesianCoordinate(x, y, coordinate.Tolerance));
        }
        /// <summary>
        /// Sets the orthocenter.
        /// </summary>
        protected void setOrthocenter()
        {
            // If any angle is 90 degrees, the orthocenter lies at the vertex at that angle
            double angleA = getAngleA();

            if (angleA.IsEqualTo(Num.PiOver2, 10E-10))
            {
                OrthoCenter = PointA;
                return;
            }

            double angleB = getAngleB();

            if (angleB.IsEqualTo(Num.PiOver2, 10E-10))
            {
                OrthoCenter = PointB;
                return;
            }

            double angleC = getAngleC();

            if (angleC.IsEqualTo(Num.PiOver2, 10E-10))
            {
                OrthoCenter = PointC;
                return;
            }

            double denominator = Trig.Tan(angleA) + Trig.Tan(angleB) + Trig.Tan(angleC);

            OrthoCenter = new CartesianCoordinate(
                (PointA.X * Trig.Tan(angleA) + PointB.X * Trig.Tan(angleB) + PointC.X * Trig.Tan(angleC)) / denominator,
                (PointA.Y * Trig.Tan(angleA) + PointB.Y * Trig.Tan(angleB) + PointC.Y * Trig.Tan(angleC)) / denominator
                );
        }
Esempio n. 6
0
        /// <summary>
        /// Returns the positive angle [radians] from the x-axis, counter-clockwise, of the coordinates.
        /// </summary>
        /// <param name="x">The x-coordinate.</param>
        /// <param name="y">The y-coordinate.</param>
        /// <returns>System.Double.</returns>
        public static double AsRadians(double x, double y)
        {
            if (x.IsZeroSign())
            {
                if (y.IsPositiveSign())
                {
                    return(Numbers.Pi / 2);
                }                                                  // 90 deg
                if (y.IsNegativeSign())
                {
                    return((3d / 2) * Numbers.Pi);
                }           // 270 deg
                return(0);  // Assume 0 degrees for origin
            }

            double angleOffset = 0;

            if (x.IsNegativeSign()) // 2nd or 3rd quadrant
            {
                angleOffset = Numbers.Pi;
            }
            else if (y.IsNegativeSign()) // 4th quadrant
            {
                angleOffset = 2 * Numbers.Pi;
            }

            return(angleOffset + Trig.ArcTan(y / x));
        }
Esempio n. 7
0
        // If a curve is defined in polar coordinates by the radius expressed as a function of the polar angle, that is r is a function of θ

        /// <summary>
        /// Slope of the curve based on all differentiated components being the polar radius at θ differentiated by θ.
        /// <a href="https://socratic.org/questions/how-do-you-find-the-slope-of-a-polar-curve">Reference</a>.
        /// </summary>
        /// <param name="thetaRadians">The position θ, in radians.</param>
        /// <param name="radius">The polar radius at position θ.</param>
        /// <param name="radiusPrime">The first differential of the polar radius w.r.t. θ.</param>
        /// <returns>System.Double.</returns>
        public static double SlopePolar(double thetaRadians, double radius, double radiusPrime)
        {
            if ((radius == 0 && radiusPrime == 0) || (thetaRadians == 0 && radiusPrime == 0))
            {
                throw new DivideByZeroException("radius & radiusPrime cannot both be zero.");
            }
            return((radiusPrime * Trig.Sin(thetaRadians) + radius * Trig.Cos(thetaRadians)) / (radiusPrime * Trig.Cos(thetaRadians) - radius * Trig.Sin(thetaRadians)));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IsoscelesTriangle" /> class.
        /// </summary>
        /// <param name="apexCoordinate">The apex coordinate.</param>
        public IsoscelesTriangle(CartesianCoordinate apexCoordinate)
        {
            double alphaRadians = getAlpha(apexCoordinate.X, apexCoordinate.Y);

            _sidesEqual  = apexCoordinate.X / Trig.Cos(alphaRadians);
            _sideUnequal = 2 * apexCoordinate.X;
            SetCoordinates(LocalCoordinates());
            setCenterCoordinates();
        }
Esempio n. 9
0
        /// <summary>
        /// Formulates the local coordinates for the shape.
        /// </summary>
        /// <returns>IList&lt;CartesianCoordinate&gt;.</returns>
        public IList <CartesianCoordinate> LocalCoordinates()
        {
            double theta;
            double circumRadius = CircumRadius;
            List <CartesianCoordinate> coordinates = new List <CartesianCoordinate>();

            for (int i = 0; i < _numberOfSides; i++)
            {
                theta = i * Numbers.TwoPi / _numberOfSides;
                coordinates.Add(
                    new CartesianCoordinate(
                        circumRadius * Trig.Cos(theta),
                        circumRadius * Trig.Sin(theta)
                        )
                    );
            }
            return(coordinates);
        }
Esempio n. 10
0
        /// <summary>
        /// Returns a new coordinate offset from the provided coordinate.
        /// </summary>
        /// <param name="distance">The distance to offset.</param>
        /// <param name="center">The center.</param>
        /// <param name="rotation">The rotation.</param>
        /// <returns>CartesianCoordinate.</returns>
        public static CartesianCoordinate OffsetCoordinate(CartesianCoordinate center, double distance, Angle rotation)
        {
            double x = center.X + distance * Trig.Cos(rotation.Radians);

            if (x.IsZeroSign(center.Tolerance))
            {
                x = 0;
            }
            double y = center.Y + distance * Trig.Sin(rotation.Radians);

            if (y.IsZeroSign(center.Tolerance))
            {
                y = 0;
            }
            return(new CartesianCoordinate(
                       x,
                       y,
                       center.Tolerance));
        }
 /// <summary>
 /// Gets the angle gamma.
 /// </summary>
 /// <returns>System.Double.</returns>
 protected double getAngleC()
 {
     return(Trig.ArcCos((SideLengthA().Squared() + SideLengthB().Squared() - SideLengthC().Squared()) / (2 * SideLengthA() * SideLengthB())));
 }
 /// <summary>
 /// The differential change in radius corresponding with a differential change in the angle, measured from the focus as a function of the angle in local coordinates.
 /// </summary>
 /// <param name="angleRadians">The angle in radians in local coordinates.</param>
 /// <returns>System.Double.</returns>
 public override double PrimeByParameter(double angleRadians)
 {
     return(-1 * _parent.Eccentricity.Squared() * _parent.DistanceFromFocusToDirectrix * Trig.Sin(angleRadians) / (1 - _parent.Eccentricity * Trig.Cos(angleRadians)));
 }
 /// <summary>
 /// The radius measured from the focus as a function of the angle in local coordinates.
 /// <a href="https://web.ma.utexas.edu/users/m408s/m408d/CurrentWeb/LM10-6-3.php">Reference</a>
 /// </summary>
 /// <param name="angleRadians">The angle in radians in local coordinates.</param>
 /// <returns>System.Double.</returns>
 public override double BaseByParameter(double angleRadians)
 {
     return(_parent.Eccentricity * _parent.DistanceFromFocusToDirectrix / (1 - _parent.Eccentricity * Trig.Cos(angleRadians)));
 }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RegularPolygon"/> class.
 /// </summary>
 /// <param name="numberOfSides">The number of sides, &gt;= 5</param>
 /// <param name="circumRadius">The circumradius.</param>
 public RegularPolygon(int numberOfSides, double circumRadius)
 {
     _numberOfSides = NMath.Max(_minNumberOfSides, numberOfSides.Abs());
     _lengthOfSides = 2 * circumRadius.Abs() * Trig.Sin(Numbers.Pi / _numberOfSides);
     SetCoordinates(LocalCoordinates());
 }
 /// <summary>
 /// Angle between the tangent of the curve and the radius connecting the origin to the point considered.
 /// This is in local coordinates about the local origin that corresponds to the parametric coordinate given.
 /// </summary>
 /// <param name="angleRadians">Parametric coordinate in radians.</param>
 /// <returns>System.Double.</returns>
 public double PolarTangentialAngleAboutOriginByAngle(double angleRadians)
 {
     return(Trig.ArcTan(1 / RadiusChangeWithRotation));
 }
 /// <summary>
 /// Gets the alpha angle.
 /// </summary>
 /// <param name="halfBase">Half of the base width.</param>
 /// <param name="height">The height.</param>
 /// <returns>System.Double.</returns>
 private static double getAlpha(double halfBase, double height)
 {
     return(Trig.ArcTan(height / halfBase));
 }
 /// <summary>
 /// Primes the double by angle.
 /// </summary>
 /// <param name="angleRadians">The angle radians.</param>
 /// <returns>System.Double.</returns>
 public override double PrimeDoubleByParameter(double angleRadians)
 {
     return(_parent.RadiusAtOrigin * Numbers.E.Pow(_parent.RadiusChangeWithRotation * angleRadians) * 2 * Trig.Cos(angleRadians));
 }
Esempio n. 18
0
 /// <summary>
 /// The coordinate of the handle tip.
 /// </summary>
 /// <returns>CartesianCoordinate.</returns>
 public CartesianCoordinate GetHandleTip()
 {
     return(ControlPoint + new CartesianCoordinate(Radius * Trig.Cos(Rotation.Radians), Radius * Trig.Sin(Rotation.Radians), ControlPoint.Tolerance));
 }
Esempio n. 19
0
        /// <summary>
        /// Returns a decagon sized by the inradius.
        /// </summary>
        /// <param name="inRadius">The inradius.</param>
        /// <returns>RegularPolygon.</returns>
        public static Decagon DecagonByInradius(double inRadius)
        {
            double circumRadius = inRadius * Trig.Sec(Numbers.Pi / _setNumberOfSides);

            return(new Decagon(circumRadius));
        }
 /// <summary>
 /// Gets the alpha angle.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <returns>System.Double.</returns>
 protected double getAlpha(double width, double height)
 {
     return(Trig.ArcTan(height / width));
 }