Exemple #1
0
        public static Inclusions EllipticalArcContainsPoint1(
            double cX, double cY,
            double r1, double r2,
            double cosT, double sinT,
            double startCosT, double startSinT,
            double sweepCosT, double sweepSinT,
            double pX, double pY,
            double epsilon = Epsilon)
        {
            // If the ellipse is empty it can't contain anything.
            if (r1 <= 0d || r2 <= 0d)
            {
                return(Inclusions.Outside);
            }

            // If the Sweep angle is Tau, the EllipticalArc must be an Ellipse.
            if (Abs(sweepCosT - 1d) < epsilon && Abs(sweepSinT) < epsilon)
            {
                return(EllipseWithVectorAngleContainsPointTests.EllipseContainsPoint(cX, cY, r1, r2, sinT, cosT, pX, pY));
            }

            var endSinT = (sweepSinT * startCosT) + (sweepCosT * startSinT);
            var endCosT = (sweepCosT * startCosT) - (sweepSinT * startSinT);

            // Find the start and end angles.
            var sa = EllipticalPolarVectorTests.EllipticalPolarVector(startCosT, startSinT, r1, r2);
            var ea = EllipticalPolarVectorTests.EllipticalPolarVector(endCosT, endSinT, r1, r2);

            // Ellipse equation for an ellipse at origin for the chord end points.
            var u1 = r1 * sa.cosT;
            var v1 = -(r2 * sa.sinT);
            var u2 = r1 * ea.cosT;
            var v2 = -(r2 * ea.sinT);

            // Find the points of the chord.
            var sX = cX + ((u1 * cosT) + (v1 * sinT));
            var sY = cY + ((u1 * sinT) - (v1 * cosT));
            var eX = cX + ((u2 * cosT) + (v2 * sinT));
            var eY = cY + ((u2 * sinT) - (v2 * cosT));

            // Find the determinant of the chord.
            var determinant = ((sX - pX) * (eY - pY)) - ((eX - pX) * (sY - pY));

            // Check whether the point is on the same side of the chord as the center.
            if (Sign(-determinant) == Sign(sweepSinT * sweepCosT))
            {
                return(Inclusions.Outside);
            }

            // Translate point to origin.
            var u0 = pX - cX;
            var v0 = pY - cY;

            // Apply the rotation transformation to the point at the origin.
            var a = (u0 * cosT) + (v0 * sinT);
            var b = (u0 * sinT) - (v0 * cosT);

            // Normalize the radius.
            var normalizedRadius
                = (a * a / (r1 * r1))
                  + (b * b / (r2 * r2));

            return((normalizedRadius <= 1d)
                ? ((Abs(normalizedRadius - 1d) < epsilon)
                ? Inclusions.Boundary : Inclusions.Inside) : Inclusions.Outside);
        }
Exemple #2
0
 public static double EllipticalPolarAngle1(double angle, double rx, double ry)
 {
     var(cosT, sinT) = EllipticalPolarVectorTests.EllipticalPolarVector(Cos(angle), Sin(angle), rx, ry);
     return(Atan2(sinT, cosT));
 }