예제 #1
0
        public static Circle ConstructCircle(Point p1, Point p2, Point p3)
        {
            //
            // Find the center of the circle.
            //
            Segment chord1 = new Segment(p1, p2);
            Segment chord2 = new Segment(p2, p3);

            Segment perpBis1 = chord1.GetPerpendicular(chord1.Midpoint());
            Segment perpBis2 = chord2.GetPerpendicular(chord2.Midpoint());

            Point center = perpBis1.FindIntersection(perpBis2);

            //
            // Radius is the distance between the circle and any of the original points.
            //
            return new Circle(center, Point.calcDistance(center, p1));
        }
예제 #2
0
        public static Circle ConstructCircle(Point p1, Point p2, Point p3)
        {
            //
            // Find the center of the circle.
            //
            Segment chord1 = new Segment(p1, p2);
            Segment chord2 = new Segment(p2, p3);

            Segment perpBis1 = chord1.GetPerpendicular(chord1.Midpoint());
            Segment perpBis2 = chord2.GetPerpendicular(chord2.Midpoint());

            Point center = perpBis1.FindIntersection(perpBis2);

            //
            // Radius is the distance between the circle and any of the original points.
            //
            return(new Circle(center, Point.calcDistance(center, p1)));
        }
예제 #3
0
        //
        // Determine if the segment passes through the circle (we know it is not a chord since they have been filtered).
        //
        private bool IsSecant(Segment segment, List<Point> figPoints, out Segment chord)
        {
            // Make it null and overwrite when necessary.
            chord = null;

            // Is the segment exterior to the circle, but intersects at an endpoint (and wasn't tangent).
            if (this.PointIsExterior(segment.Point1) && this.PointLiesOn(segment.Point2)) return false;
            if (this.PointIsExterior(segment.Point2) && this.PointLiesOn(segment.Point1)) return false;

            // Is one endpoint of the segment simply on the interior of the circle (so we have nothing)?
            if (this.PointIsInterior(segment.Point1) || this.PointIsInterior(segment.Point2)) return false;

            if (ContainsDiameter(segment))
            {
                chord = ConstructChord(segment, this.center, this.radius, figPoints);

                // Add radii to the list.
                radii.Add(new Segment(this.center, chord.Point1));
                radii.Add(new Segment(this.center, chord.Point2));

                return true;
            }

            // Acquire the line perpendicular to the segment that passes through the center of the circle.
            Segment perpendicular = segment.GetPerpendicular(this.center);

            // Is this perpendicular segment a radius? If so, it's tangent, not a secant
            //if (Utilities.CompareValues(perpendicular.Length, this.radius)) return false;

            // Is the perpendicular a radius? Check if the intersection of the segment and the perpendicular is on the circle. If so, it's tangent
            Point intersection = segment.FindIntersection(perpendicular);
            if (this.PointLiesOn(intersection)) return false;

            //Adjust perpendicular segment to include intersection with segment
            perpendicular = new Segment(intersection, this.center);

            // Filter the fact that there are no intersections
            if (perpendicular.Length > this.radius) return false;

            //            1/2 chord length
            //                 _____   circPoint
            //                |    /
            //                |   /
            // perp.Length    |  / radius
            //                | /
            //                |/
            // Determine the half-chord length via Pyhtagorean Theorem.
            double halfChordLength = Math.Sqrt(Math.Pow(this.radius, 2) - Math.Pow(perpendicular.Length, 2));

            chord = ConstructChord(segment, perpendicular.OtherPoint(this.center), halfChordLength, figPoints);

            return true;
        }
예제 #4
0
        // return the midpoint between these two on the circle.
        public Point Midpoint(Point a, Point b)
        {
            if (!this.PointLiesOn(a)) return null;
            if (!this.PointLiesOn(b)) return null;

            // Make the chord.
            Segment chord = new Segment(a, b);

            Point pt1 = null;
            Point pt2 = null;

            // Is this a diameter? If so, quickly return a point perpendicular to the diameter
            if (DefinesDiameter(chord))
            {
                Segment perp = chord.GetPerpendicular(center);

                this.FindIntersection(perp, out pt1, out pt2);

                // Arbitrarily choose one of the points.
                return pt1 != null ? pt1 : pt2;
            }

            // Make radius through the midpoint of the chord.
            Segment radius = new Segment(center, chord.Midpoint());

            this.FindIntersection(radius, out pt1, out pt2);

            if (pt2 == null) return pt1;

            Point theMidpoint = Arc.StrictlyBetweenMinor(pt1, new MinorArc(this, a, b)) ? pt1 : pt2;

            double angle1 = new Angle(a, center, theMidpoint).measure;
            double angle2 = new Angle(b, center, theMidpoint).measure;
            if (!Utilities.CompareValues(angle1, angle2))
            {
                throw new ArgumentException("Midpoint is incorrect; angles do not equate: " + angle1 + " " + angle2);
            }

            return theMidpoint;
        }
예제 #5
0
        //
        // Determine tangency of the given segment.
        // Indicate tangency by returning the segment which creates the 90^0 angle.
        //
        public Segment IsTangent(Segment segment)
        {
            // If the center and the segment points are collinear, this will not be a tangent.
            if (segment.PointLiesOn(this.center)) return null;

            // Acquire the line perpendicular to the segment that passes through the center of the circle.
            Segment perpendicular = segment.GetPerpendicular(this.center);

            // If the segment was found to pass through the center, it is not a tangent
            if (perpendicular.Equals(segment)) return null;

            // Is this perpendicular segment a radius? Check length
            //if (!Utilities.CompareValues(perpendicular.Length, this.radius)) return null;

            // Is the perpendicular a radius? Check that the intersection of the segment and the perpendicular is on the circle
            Point intersection = segment.FindIntersection(perpendicular);
            if (!this.PointLiesOn(intersection)) return null;

            // The intersection between the perpendicular and the segment must be within the endpoints of the segment.
            return segment.PointLiesOnAndBetweenEndpoints(intersection) ? perpendicular : null;
        }