예제 #1
0
        //
        // Is this segment perpendicular to the given segment in terms of the coordinatization from the UI?
        //
        public Point CoordinatePerpendicular(Segment thatSegment)
        {
            //
            // Do these segments intersect within both sets of stated endpoints?
            //
            Point intersection = this.FindIntersection(thatSegment);

            if (!this.PointLiesOnAndBetweenEndpoints(intersection))
            {
                return(null);
            }
            if (!thatSegment.PointLiesOnAndBetweenEndpoints(intersection))
            {
                return(null);
            }

            //
            // Special Case
            //
            if ((IsVertical() && thatSegment.IsHorizontal()) || (thatSegment.IsVertical() && IsHorizontal()))
            {
                return(intersection);
            }

            // Does m1 * m2 = -1 (opposite reciprocal slopes)
            return(Utilities.CompareValues(thatSegment.Slope * this.Slope, -1) ? intersection : null);
        }
예제 #2
0
        //
        // Parallel and not Coinciding
        //
        public bool IsPerpendicularTo(Segment thatSegment)
        {
            if (IsVertical() && thatSegment.IsHorizontal())
            {
                return(true);
            }

            if (IsHorizontal() && thatSegment.IsVertical())
            {
                return(true);
            }

            return(Utilities.CompareValues(thatSegment.Slope * this.Slope, -1));
        }
예제 #3
0
        //
        // Determine if the given segment is collinear with this segment (same slope and they share a point)
        //
        public bool IsCollinearWith(Segment otherSegment)
        {
            // If the segments are vertical, just compare the X values of one point of each
            if (this.IsVertical() && otherSegment.IsVertical())
            {
                return(Utilities.CompareValues(this.Point1.X, otherSegment.Point1.X));
            }

            // If the segments are horizontal, just compare the Y values of one point of each; this is redundant
            if (this.IsHorizontal() && otherSegment.IsHorizontal())
            {
                return(Utilities.CompareValues(this.Point1.Y, otherSegment.Point1.Y));
            }

            return(Utilities.CompareValues(this.Slope, otherSegment.Slope) &&
                   this.PointLiesOn(otherSegment.Point1) && this.PointLiesOn(otherSegment.Point2)); // Check both endpoints just to be sure
        }
예제 #4
0
        //
        // Parallel and not Coinciding
        //
        public bool IsParallelWith(Segment s)
        {
            if (IsCollinearWith(s))
            {
                return(false);
            }

            if (IsVertical() && s.IsVertical())
            {
                return(true);
            }

            if (IsHorizontal() && s.IsHorizontal())
            {
                return(true);
            }

            return(Utilities.CompareValues(s.Slope, this.Slope));
        }
예제 #5
0
        //
        // Given the secant, there is a midpoint along the secant (wrt to the circle), given the distance,
        // find the two points of intersection between the secant and the circle.
        // Return the resultant chord segment.
        //
        private Segment ConstructChord(Segment secantSegment, Point midpt, double distance, List<Point> figPoints)
        {
            //                distance
            //      circPt1    _____   circPt2
            //
            // Find the exact coordinates of the two 'circ' points.
            //
            double deltaX = 0;
            double deltaY = 0;
            if (secantSegment.IsVertical())
            {
                deltaX = 0;
                deltaY = distance;
            }
            else if (secantSegment.IsHorizontal())
            {
                deltaX = distance;
                deltaY = 0;
            }
            else
            {
                deltaX = Math.Sqrt(Math.Pow(distance, 2) / (1 + Math.Pow(secantSegment.Slope, 2)));
                deltaY = secantSegment.Slope * deltaX;
            }
            Point circPt1 = Utilities.AcquirePoint(figPoints, new Point("", midpt.X + deltaX, midpt.Y + deltaY));

            // intersection is the midpoint of circPt1 and pt2.
            Point circPt2 = Utilities.AcquirePoint(figPoints, new Point("", 2 * midpt.X - circPt1.X, 2 * midpt.Y - circPt1.Y));

            // Create the actual chord
            return new Segment(circPt1, circPt2);
        }
예제 #6
0
        //
        // Parallel and not Coinciding
        //
        public bool IsPerpendicularTo(Segment thatSegment)
        {
            if (IsVertical() && thatSegment.IsHorizontal()) return true;

            if (IsHorizontal() && thatSegment.IsVertical()) return true;

            return Utilities.CompareValues(thatSegment.Slope * this.Slope, -1);
        }
예제 #7
0
        //
        // Parallel and not Coinciding
        //
        public bool IsParallelWith(Segment s)
        {
            if (IsCollinearWith(s)) return false;

            if (IsVertical() && s.IsVertical()) return true;

            if (IsHorizontal() && s.IsHorizontal()) return true;

            return Utilities.CompareValues(s.Slope, this.Slope);
        }
예제 #8
0
        //
        // Determine if the given segment is collinear with this segment (same slope and they share a point)
        //
        public bool IsCollinearWith(Segment otherSegment)
        {
            // If the segments are vertical, just compare the X values of one point of each
            if (this.IsVertical() && otherSegment.IsVertical())
            {
                return Utilities.CompareValues(this.Point1.X, otherSegment.Point1.X);
            }

            // If the segments are horizontal, just compare the Y values of one point of each; this is redundant
            if (this.IsHorizontal() && otherSegment.IsHorizontal())
            {
                return Utilities.CompareValues(this.Point1.Y, otherSegment.Point1.Y);
            }

            return Utilities.CompareValues(this.Slope, otherSegment.Slope) &&
                   this.PointLiesOn(otherSegment.Point1) && this.PointLiesOn(otherSegment.Point2); // Check both endpoints just to be sure
        }
예제 #9
0
        public Point FindIntersection(Segment thatSegment)
        {
            // Special Case: Collinear, but non-overlapping.
            if (this.CoincidingWithoutOverlap(thatSegment)) return null;

            // Special Case: Intersect at an endpoint
            Point shared = this.SharedVertex(thatSegment);
            if (shared != null) return shared;

            double a, b, c, d, e, f;

            if (this.IsVertical() && thatSegment.IsHorizontal()) return new Point(null, this.Point1.X, thatSegment.Point1.Y);

            if (thatSegment.IsVertical() && this.IsHorizontal()) return new Point(null, thatSegment.Point1.X, this.Point1.Y);

            if (this.IsVertical())
            {
                MakeLine(thatSegment.Point1.X, thatSegment.Point1.Y, thatSegment.Point2.X, thatSegment.Point2.Y, out a, out b, out e);
                return new Point(null, this.Point1.X, EvaluateYGivenX(a, b, e, this.Point1.X));
            }
            if (thatSegment.IsVertical())
            {
                MakeLine(this.Point1.X, this.Point1.Y, this.Point2.X, this.Point2.Y, out a, out b, out e);
                return new Point(null, thatSegment.Point1.X, EvaluateYGivenX(a, b, e, thatSegment.Point1.X));
            }
            if (this.IsHorizontal())
            {
                MakeLine(thatSegment.Point1.X, thatSegment.Point1.Y, thatSegment.Point2.X, thatSegment.Point2.Y, out a, out b, out e);
                return new Point(null, EvaluateXGivenY(a, b, e, this.Point1.Y), this.Point1.Y);
            }
            if (thatSegment.IsHorizontal())
            {
                MakeLine(this.Point1.X, this.Point1.Y, this.Point2.X, this.Point2.Y, out a, out b, out e);
                return new Point(null, EvaluateXGivenY(a, b, e, thatSegment.Point1.Y), thatSegment.Point1.Y);
            }

            //
            // ax + by = e
            // cx + dy = f
            //

            MakeLine(Point1.X, Point1.Y, Point2.X, Point2.Y, out a, out b, out e);
            MakeLine(thatSegment.Point1.X, thatSegment.Point1.Y, thatSegment.Point2.X, thatSegment.Point2.Y, out c, out d, out f);

            double overallDeterminant = a * d - b * c;
            double x = determinant(e, b, f, d) / overallDeterminant;
            double y = determinant(a, e, c, f) / overallDeterminant;

            return new Point("Intersection", x, y);
        }
예제 #10
0
        //
        // Is this segment perpendicular to the given segment in terms of the coordinatization from the UI?
        //
        public Point CoordinatePerpendicular(Segment thatSegment)
        {
            //
            // Do these segments intersect within both sets of stated endpoints?
            //
            Point intersection = this.FindIntersection(thatSegment);

            if (!this.PointLiesOnAndBetweenEndpoints(intersection)) return null;
            if (!thatSegment.PointLiesOnAndBetweenEndpoints(intersection)) return null;

            //
            // Special Case
            //
            if ((IsVertical() && thatSegment.IsHorizontal()) || (thatSegment.IsVertical() && IsHorizontal())) return intersection;

            // Does m1 * m2 = -1 (opposite reciprocal slopes)
            return Utilities.CompareValues(thatSegment.Slope * this.Slope, -1) ? intersection : null;
        }
예제 #11
0
        public Point FindIntersection(Segment thatSegment)
        {
            // Special Case: Collinear, but non-overlapping.
            if (this.CoincidingWithoutOverlap(thatSegment))
            {
                return(null);
            }

            // Special Case: Intersect at an endpoint
            Point shared = this.SharedVertex(thatSegment);

            if (shared != null)
            {
                return(shared);
            }

            double a, b, c, d, e, f;

            if (this.IsVertical() && thatSegment.IsHorizontal())
            {
                return(new Point(null, this.Point1.X, thatSegment.Point1.Y));
            }

            if (thatSegment.IsVertical() && this.IsHorizontal())
            {
                return(new Point(null, thatSegment.Point1.X, this.Point1.Y));
            }

            if (this.IsVertical())
            {
                MakeLine(thatSegment.Point1.X, thatSegment.Point1.Y, thatSegment.Point2.X, thatSegment.Point2.Y, out a, out b, out e);
                return(new Point(null, this.Point1.X, EvaluateYGivenX(a, b, e, this.Point1.X)));
            }
            if (thatSegment.IsVertical())
            {
                MakeLine(this.Point1.X, this.Point1.Y, this.Point2.X, this.Point2.Y, out a, out b, out e);
                return(new Point(null, thatSegment.Point1.X, EvaluateYGivenX(a, b, e, thatSegment.Point1.X)));
            }
            if (this.IsHorizontal())
            {
                MakeLine(thatSegment.Point1.X, thatSegment.Point1.Y, thatSegment.Point2.X, thatSegment.Point2.Y, out a, out b, out e);
                return(new Point(null, EvaluateXGivenY(a, b, e, this.Point1.Y), this.Point1.Y));
            }
            if (thatSegment.IsHorizontal())
            {
                MakeLine(this.Point1.X, this.Point1.Y, this.Point2.X, this.Point2.Y, out a, out b, out e);
                return(new Point(null, EvaluateXGivenY(a, b, e, thatSegment.Point1.Y), thatSegment.Point1.Y));
            }

            //
            // ax + by = e
            // cx + dy = f
            //

            MakeLine(Point1.X, Point1.Y, Point2.X, Point2.Y, out a, out b, out e);
            MakeLine(thatSegment.Point1.X, thatSegment.Point1.Y, thatSegment.Point2.X, thatSegment.Point2.Y, out c, out d, out f);

            double overallDeterminant = a * d - b * c;
            double x = determinant(e, b, f, d) / overallDeterminant;
            double y = determinant(a, e, c, f) / overallDeterminant;

            return(new Point("Intersection", x, y));
        }