Пример #1
0
        public SegmentRatio GetSharedRatio(SegmentRatioEquation that)
        {
            // Check for the obvious shared ratio
            if (lhs.StructurallyEquals(that.lhs))
            {
                return(that.lhs);
            }
            if (lhs.StructurallyEquals(that.rhs))
            {
                return(that.rhs);
            }
            if (rhs.StructurallyEquals(that.lhs))
            {
                return(that.lhs);
            }
            if (rhs.StructurallyEquals(that.rhs))
            {
                return(that.rhs);
            }

            if (HasImpliedRatio(that.lhs))
            {
                return(that.lhs);
            }
            if (HasImpliedRatio(that.rhs))
            {
                return(that.rhs);
            }

            return(null);
        }
Пример #2
0
        public override bool Equals(Object obj)
        {
            SegmentRatioEquation that = obj as SegmentRatioEquation;

            if (that == null)
            {
                return(false);
            }

            return(lhs.Equals(that.lhs) && rhs.Equals(that.rhs) ||
                   lhs.Equals(that.rhs) && rhs.Equals(that.lhs));
        }
Пример #3
0
        private static bool HandleRatioEquation(KnownMeasurementsAggregator known, SegmentRatioEquation theEq)
        {
            double topLeft = known.GetSegmentLength(theEq.lhs.smallerSegment);
            double bottomLeft = known.GetSegmentLength(theEq.lhs.largerSegment);
            double topRight = known.GetSegmentLength(theEq.rhs.smallerSegment);
            double bottomRight = known.GetSegmentLength(theEq.rhs.largerSegment);

            int unknown = 0;
            if (topLeft <= 0) unknown++;
            if (bottomLeft <= 0) unknown++;
            if (topRight <= 0) unknown++;
            if (bottomRight <= 0) unknown++;
            if (unknown != 1) return false;

            if (topLeft <= 0)
            {
                return known.AddSegmentLength(theEq.lhs.smallerSegment, (topRight / bottomRight) * bottomLeft);
            }
            else if (bottomLeft <= 0)
            {
                return known.AddSegmentLength(theEq.lhs.largerSegment, topLeft * (bottomRight / topRight));
            }
            else if (topRight <= 0)
            {
                return known.AddSegmentLength(theEq.rhs.smallerSegment, (topLeft / bottomLeft) * bottomRight);
            }
            else if (bottomRight <= 0)
            {
                return known.AddSegmentLength(theEq.rhs.largerSegment, topRight * (bottomLeft / topLeft));
            }
            else return false;
        }
Пример #4
0
        //
        //
        //
        private static List<EdgeAggregator> CollectAndCheckSAS(Triangle ct1, Triangle ct2, CongruentAngles cas, SegmentRatioEquation sre)
        {
            List<EdgeAggregator> newGrounded = new List<EdgeAggregator>();

            // Proportions must actually equate
            //if (!pss1.ProportionallyEquals(pss2)) return newGrounded;

            //// The smaller and larger segments of the proportionality must be distinct, respectively.
            //if (!pss1.IsDistinctFrom(pss2)) return newGrounded;

            // The proportional relationships need to link the given triangles
            if (!cas.LinksTriangles(ct1, ct2)) return newGrounded;
            if (!sre.LinksTriangles(ct1, ct2)) return newGrounded;
            //if (!pss1.LinksTriangles(ct1, ct2)) return newGrounded;
            //if (!pss2.LinksTriangles(ct1, ct2)) return newGrounded;

            // The smaller segments must belong to one triangle, same for larger segments.
            //if (!(ct1.HasSegment(pss1.smallerSegment) && ct1.HasSegment(pss2.smallerSegment) &&
            //      ct2.HasSegment(pss1.largerSegment) && ct2.HasSegment(pss2.largerSegment)) &&
            //    !(ct2.HasSegment(pss1.smallerSegment) && ct2.HasSegment(pss2.smallerSegment) &&
            //      ct1.HasSegment(pss1.largerSegment) && ct1.HasSegment(pss2.largerSegment)))
            //    return newGrounded;

            KeyValuePair<Segment, Segment> segsTri1 = sre.GetSegments(ct1);
            KeyValuePair<Segment, Segment> segsTri2 = sre.GetSegments(ct2);

            //Segment seg1Tri1 = ct1.GetSegment(pss1);
            //Segment seg2Tri1 = ct1.GetSegment(pss2);

            //Segment seg1Tri2 = ct2.GetSegment(pss1);
            //Segment seg2Tri2 = ct2.GetSegment(pss2);

            // Avoid redundant segments, if they arise
            if (segsTri1.Key.StructurallyEquals(segsTri1.Value)) return newGrounded;
            if (segsTri2.Key.StructurallyEquals(segsTri2.Value)) return newGrounded;
            //if (seg1Tri1.StructurallyEquals(seg2Tri1)) return newGrounded;
            //if (seg1Tri2.StructurallyEquals(seg2Tri2)) return newGrounded;

            Angle angleTri1 = ct1.AngleBelongs(cas);
            Angle angleTri2 = ct2.AngleBelongs(cas);

            // Check both triangles if this is the included angle; if it is, we have SAS
            if (!angleTri1.IsIncludedAngle(segsTri1.Key, segsTri1.Value)) return newGrounded;
            if (!angleTri2.IsIncludedAngle(segsTri2.Key, segsTri2.Value)) return newGrounded;

            //
            // Generate Similar Triangles
            //
            Point vertex1 = angleTri1.GetVertex();
            Point vertex2 = angleTri2.GetVertex();

            // Construct a list of pairs to return; this is the correspondence from triangle 1 to triangle 2
            List<KeyValuePair<Point, Point>> pairs = new List<KeyValuePair<Point, Point>>();

            // The vertices of the angles correspond
            pairs.Add(new KeyValuePair<Point, Point>(vertex1, vertex2));

            // For the segments, look at the congruences and select accordingly
            pairs.Add(new KeyValuePair<Point, Point>(segsTri1.Key.OtherPoint(vertex1), segsTri2.Key.OtherPoint(vertex2)));
            pairs.Add(new KeyValuePair<Point, Point>(segsTri1.Value.OtherPoint(vertex1), segsTri2.Value.OtherPoint(vertex2)));

            List<GroundedClause> simTriAntecedent = new List<GroundedClause>();
            simTriAntecedent.Add(ct1);
            simTriAntecedent.Add(ct2);
            simTriAntecedent.Add(cas);
            simTriAntecedent.Add(sre);

            newGrounded.AddRange(GenerateCorrespondingParts(pairs, simTriAntecedent, annotation));

            return newGrounded;
        }
Пример #5
0
 public bool SharesRatio(SegmentRatioEquation that)
 {
     return GetSharedRatio(that) != null;
 }
Пример #6
0
        public SegmentRatio GetSharedRatio(SegmentRatioEquation that)
        {
            // Check for the obvious shared ratio
            if (lhs.StructurallyEquals(that.lhs)) return that.lhs;
            if (lhs.StructurallyEquals(that.rhs)) return that.rhs;
            if (rhs.StructurallyEquals(that.lhs)) return that.lhs;
            if (rhs.StructurallyEquals(that.rhs)) return that.rhs;

            if (HasImpliedRatio(that.lhs)) return that.lhs;
            if (HasImpliedRatio(that.rhs)) return that.rhs;

            return null;
        }
Пример #7
0
        //
        // Of all the congruent segment pairs, choose a subset of 3. Exhaustively check all; if they work, return the set.
        //
        private static List<EdgeAggregator> CheckForSSS(Triangle ct1, Triangle ct2, SegmentRatioEquation sre1, SegmentRatioEquation sre2)
        {
            List<EdgeAggregator> newGrounded = new List<EdgeAggregator>();

            //
            // The proportional relationships need to link the given triangles
            //
            if (!sre1.LinksTriangles(ct1, ct2)) return newGrounded;
            if (!sre2.LinksTriangles(ct1, ct2)) return newGrounded;

            //
            // Both equations must share a fraction (ratio)
            //
            if (!sre1.SharesRatio(sre2)) return newGrounded;

            //
            // Collect all of the applicable segments
            //
            SegmentRatio shared = sre1.GetSharedRatio(sre2);
            SegmentRatio other1 = sre1.GetOtherRatio(shared);
            SegmentRatio other2 = sre2.GetOtherRatio(shared);

            Segment seg1Tri1 = ct1.GetSegment(shared);
            Segment seg2Tri1 = ct1.GetSegment(other1);
            Segment seg3Tri1 = ct1.GetSegment(other2);

            if (seg1Tri1 == null || seg2Tri1 == null || seg3Tri1 == null) return newGrounded;

            Segment seg1Tri2 = ct2.GetSegment(shared);
            Segment seg2Tri2 = ct2.GetSegment(other1);
            Segment seg3Tri2 = ct2.GetSegment(other2);

            if (seg1Tri2 == null || seg2Tri2 == null || seg3Tri2 == null) return newGrounded;

            // Avoid redundant segments, if they arise
            if (seg1Tri1.StructurallyEquals(seg2Tri1) || seg1Tri1.StructurallyEquals(seg3Tri1) || seg2Tri1.StructurallyEquals(seg3Tri1)) return newGrounded;
            if (seg1Tri2.StructurallyEquals(seg2Tri2) || seg1Tri2.StructurallyEquals(seg3Tri2) || seg2Tri2.StructurallyEquals(seg3Tri2)) return newGrounded;

            //
            // Collect the corresponding points
            //
            List<KeyValuePair<Point, Point>> pointPairs = new List<KeyValuePair<Point, Point>>();
            pointPairs.Add(new KeyValuePair<Point, Point>(seg1Tri1.SharedVertex(seg2Tri1), seg1Tri2.SharedVertex(seg2Tri2)));
            pointPairs.Add(new KeyValuePair<Point, Point>(seg1Tri1.SharedVertex(seg3Tri1), seg1Tri2.SharedVertex(seg3Tri2)));
            pointPairs.Add(new KeyValuePair<Point, Point>(seg2Tri1.SharedVertex(seg3Tri1), seg2Tri2.SharedVertex(seg3Tri2)));

            List<GroundedClause> simTriAntecedent = new List<GroundedClause>();
            simTriAntecedent.Add(ct1);
            simTriAntecedent.Add(ct2);
            simTriAntecedent.Add(sre1);
            simTriAntecedent.Add(sre2);

            newGrounded.AddRange(SASSimilarity.GenerateCorrespondingParts(pointPairs, simTriAntecedent, annotation));

            return newGrounded;
        }
Пример #8
0
 public bool SharesRatio(SegmentRatioEquation that)
 {
     return(GetSharedRatio(that) != null);
 }