public SegmentRatio GetOtherRatio(SegmentRatio that)
        {
            // Check for the obvious shared ratio
            if (lhs.StructurallyEquals(that)) return this.rhs;
            if (rhs.StructurallyEquals(that)) return this.lhs;

            return GetOtherImpliedRatio(that);
        }
Exemple #2
0
        //
        // Compare the numeric proportion between the relations
        //
        public bool ProportionallyEquals(SegmentRatio that)
        {
            if (this.proportion.Key == -1 && this.proportion.Value == -1)
            {
                return(Utilities.CompareValues(this.dictatedProportion, that.dictatedProportion));
            }

            return(this.proportion.Key == that.proportion.Key && this.proportion.Value == that.proportion.Value);
        }
Exemple #3
0
        public override bool Equals(Object obj)
        {
            SegmentRatio p = obj as SegmentRatio;

            if (p == null)
            {
                return(false);
            }
            return(smallerSegment.Equals(p.smallerSegment) && largerSegment.Equals(p.largerSegment) && base.Equals(obj));
        }
Exemple #4
0
        public override bool StructurallyEquals(Object obj)
        {
            SegmentRatio p = obj as SegmentRatio;

            if (p == null)
            {
                return(false);
            }
            return(smallerSegment.StructurallyEquals(p.smallerSegment) && largerSegment.StructurallyEquals(p.largerSegment));
        }
        //
        // Create the three resultant angles from each triangle to create the congruency of angles
        //
        private static List <GenericInstantiator.EdgeAggregator> GenerateSegmentRatio(SimilarTriangles simTris,
                                                                                      List <Point> orderedTriOnePts,
                                                                                      List <Point> orderedTriTwoPts)
        {
            segmentAnnotation.active = EngineUIBridge.JustificationSwitch.SIMILARITY;

            //
            // Cycle through the points creating the angles: ABC - DEF ; BCA - EFD ; CAB - FDE
            //
            List <SegmentRatio> ratios = new List <SegmentRatio>();

            for (int i = 0; i < orderedTriOnePts.Count; i++)
            {
                Segment      cs1   = new Segment(orderedTriOnePts[0], orderedTriOnePts[1]);
                Segment      cs2   = new Segment(orderedTriTwoPts[0], orderedTriTwoPts[1]);
                SegmentRatio ratio = new SegmentRatio(cs1, cs2);

                ratios.Add(ratio);

                // rotate the lists
                Point tmp = orderedTriOnePts.ElementAt(0);
                orderedTriOnePts.RemoveAt(0);
                orderedTriOnePts.Add(tmp);

                tmp = orderedTriTwoPts.ElementAt(0);
                orderedTriTwoPts.RemoveAt(0);
                orderedTriTwoPts.Add(tmp);
            }

            //
            // Take the ratios and create ratio equations.
            //
            List <GroundedClause> ratioEqs = new List <GroundedClause>();

            for (int i = 0; i < ratios.Count; i++)
            {
                ratioEqs.Add(new GeometricSegmentRatioEquation(ratios[i], ratios[(i + 1) % ratios.Count]));
            }

            //
            // Construct the new deduced edges: proportional segments.
            //
            List <GenericInstantiator.EdgeAggregator> newGrounded = new List <GenericInstantiator.EdgeAggregator>();

            List <GroundedClause> antecedent = Utilities.MakeList <GroundedClause>(simTris);

            foreach (GroundedClause eq in ratioEqs)
            {
                newGrounded.Add(new GenericInstantiator.EdgeAggregator(antecedent, eq, segmentAnnotation));
            }

            return(newGrounded);
        }
        //
        //  if x / y = z / w   and we are checking for  x / z OR y / w
        //
        private bool HasImpliedRatio(SegmentRatio thatRatio)
        {
            if (thatRatio.HasSegment(lhs.largerSegment) && thatRatio.HasSegment(rhs.largerSegment))
            {
                return(true);
            }
            if (thatRatio.HasSegment(lhs.smallerSegment) && thatRatio.HasSegment(rhs.smallerSegment))
            {
                return(true);
            }

            return(false);
        }
Exemple #7
0
        public bool IsDistinctFrom(SegmentRatio thatProp)
        {
            if (this.smallerSegment.StructurallyEquals(thatProp.smallerSegment))
            {
                return(false);
            }
            if (this.largerSegment.StructurallyEquals(thatProp.largerSegment))
            {
                return(false);
            }

            return(true);
        }
        public SegmentRatio GetOtherRatio(SegmentRatio that)
        {
            // Check for the obvious shared ratio
            if (lhs.StructurallyEquals(that))
            {
                return(this.rhs);
            }
            if (rhs.StructurallyEquals(that))
            {
                return(this.lhs);
            }

            return(GetOtherImpliedRatio(that));
        }
        private SegmentRatio GetOtherImpliedRatio(SegmentRatio thatRatio)
        {
            if (thatRatio.HasSegment(lhs.largerSegment) && thatRatio.HasSegment(rhs.largerSegment))
            {
                return(new SegmentRatio(lhs.smallerSegment, rhs.smallerSegment));
            }

            if (thatRatio.HasSegment(lhs.smallerSegment) && thatRatio.HasSegment(rhs.smallerSegment))
            {
                return(new SegmentRatio(lhs.largerSegment, rhs.largerSegment));
            }

            return(null);
        }
        //public KeyValuePair<int, int> proportion { get; protected set; }
        //public double dictatedProportion { get; protected set; }

        public SegmentRatioEquation(SegmentRatio ell, SegmentRatio r) : base()
        {
            if (!ell.ProportionallyEquals(r))
            {
                throw new ArgumentException("Ratios of segments are not proportionally equal: " + ell + " " + r);
            }

            lhs = ell;
            rhs = r;

            segments = new List <Segment>();
            segments.Add(lhs.smallerSegment);
            segments.Add(lhs.largerSegment);
            segments.Add(rhs.smallerSegment);
            segments.Add(rhs.largerSegment);
        }
        //public KeyValuePair<int, int> proportion { get; protected set; }
        //public double dictatedProportion { get; protected set; }
        public SegmentRatioEquation(SegmentRatio ell, SegmentRatio r)
            : base()
        {
            if (!ell.ProportionallyEquals(r))
            {
                throw new ArgumentException("Ratios of segments are not proportionally equal: " + ell + " " + r);
            }

            lhs = ell;
            rhs = r;

            segments = new List<Segment>();
            segments.Add(lhs.smallerSegment);
            segments.Add(lhs.largerSegment);
            segments.Add(rhs.smallerSegment);
            segments.Add(rhs.largerSegment);
        }
Exemple #12
0
        public static List <GenericInstantiator.EdgeAggregator> InstantiateEquation(GroundedClause clause)
        {
            List <GenericInstantiator.EdgeAggregator> newGrounded = new List <GenericInstantiator.EdgeAggregator>();

            if (!(clause is SegmentEquation))
            {
                return(newGrounded);
            }

            Equation original = clause as Equation;

            Equation     copyEq    = (Equation)original.DeepCopy();
            FlatEquation flattened = new FlatEquation(copyEq.lhs.CollectTerms(), copyEq.rhs.CollectTerms());

            if (flattened.lhsExps.Count != 1 || flattened.rhsExps.Count != 1)
            {
                return(newGrounded);
            }

            KeyValuePair <int, int> ratio = Utilities.RationalRatio(flattened.lhsExps[0].multiplier, flattened.rhsExps[0].multiplier);

            if (ratio.Key != -1)
            {
                if (ratio.Key <= 2 && ratio.Value <= 2)
                {
                    SegmentRatio prop = new SegmentRatio((Segment)flattened.lhsExps[0].DeepCopy(),
                                                         (Segment)flattened.rhsExps[0].DeepCopy());
                    prop.MakeProportionValueKnown();

                    List <GroundedClause> antecedent = Utilities.MakeList <GroundedClause>(original);
                    newGrounded.Add(new GenericInstantiator.EdgeAggregator(antecedent, prop, atomAnnotation));
                }
            }

            return(newGrounded);
        }
Exemple #13
0
        //
        // Compare the numeric proportion between the relations
        //
        public bool ProportionallyEquals(SegmentRatio that)
        {
            if (this.proportion.Key == -1 && this.proportion.Value == -1)
            {
                return Utilities.CompareValues(this.dictatedProportion, that.dictatedProportion);
            }

            return this.proportion.Key == that.proportion.Key && this.proportion.Value == that.proportion.Value;
        }
Exemple #14
0
        public bool IsDistinctFrom(SegmentRatio thatProp)
        {
            if (this.smallerSegment.StructurallyEquals(thatProp.smallerSegment)) return false;
            if (this.largerSegment.StructurallyEquals(thatProp.largerSegment)) return false;

            return true;
        }
Exemple #15
0
        public static List<GenericInstantiator.EdgeAggregator> InstantiateEquation(GroundedClause clause)
        {
            List<GenericInstantiator.EdgeAggregator> newGrounded = new List<GenericInstantiator.EdgeAggregator>();

            if (!(clause is SegmentEquation)) return newGrounded;

            Equation original = clause as Equation;

            Equation copyEq = (Equation)original.DeepCopy();
            FlatEquation flattened = new FlatEquation(copyEq.lhs.CollectTerms(), copyEq.rhs.CollectTerms());

            if (flattened.lhsExps.Count != 1 || flattened.rhsExps.Count != 1) return newGrounded;

            KeyValuePair<int, int> ratio = Utilities.RationalRatio(flattened.lhsExps[0].multiplier, flattened.rhsExps[0].multiplier);
            if (ratio.Key != -1)
            {
                if (ratio.Key <= 2 && ratio.Value <= 2)
                {
                    SegmentRatio prop = new SegmentRatio((Segment)flattened.lhsExps[0].DeepCopy(),
                                                         (Segment)flattened.rhsExps[0].DeepCopy());
                    prop.MakeProportionValueKnown();

                    List<GroundedClause> antecedent = Utilities.MakeList<GroundedClause>(original);
                    newGrounded.Add(new GenericInstantiator.EdgeAggregator(antecedent, prop, atomAnnotation));
                }
            }

            return newGrounded;
        }
 public GeometricSegmentRatioEquation(SegmentRatio r1, SegmentRatio r2)
     : base(r1, r2)
 {
 }
        //
        // Create the three resultant angles from each triangle to create the congruency of angles
        //
        private static List<GenericInstantiator.EdgeAggregator> GenerateSegmentRatio(SimilarTriangles simTris,
                                                                                     List<Point> orderedTriOnePts,
                                                                                     List<Point> orderedTriTwoPts)
        {
            segmentAnnotation.active = EngineUIBridge.JustificationSwitch.SIMILARITY;

            //
            // Cycle through the points creating the angles: ABC - DEF ; BCA - EFD ; CAB - FDE
            //
            List<SegmentRatio> ratios = new List<SegmentRatio>();
            for (int i = 0; i < orderedTriOnePts.Count; i++)
            {
                Segment cs1 = new Segment(orderedTriOnePts[0], orderedTriOnePts[1]);
                Segment cs2 = new Segment(orderedTriTwoPts[0], orderedTriTwoPts[1]);
                SegmentRatio ratio = new SegmentRatio(cs1, cs2);

                ratios.Add(ratio);

                // rotate the lists
                Point tmp = orderedTriOnePts.ElementAt(0);
                orderedTriOnePts.RemoveAt(0);
                orderedTriOnePts.Add(tmp);

                tmp = orderedTriTwoPts.ElementAt(0);
                orderedTriTwoPts.RemoveAt(0);
                orderedTriTwoPts.Add(tmp);
            }

            //
            // Take the ratios and create ratio equations.
            //
            List<GroundedClause> ratioEqs = new List<GroundedClause>();
            for (int i = 0; i < ratios.Count; i++)
            {
                ratioEqs.Add(new GeometricSegmentRatioEquation(ratios[i], ratios[(i + 1) % ratios.Count]));
            }

            //
            // Construct the new deduced edges: proportional segments.
            //
            List<GenericInstantiator.EdgeAggregator> newGrounded = new List<GenericInstantiator.EdgeAggregator>();

            List<GroundedClause> antecedent = Utilities.MakeList<GroundedClause>(simTris);
            foreach (GroundedClause eq in ratioEqs)
            {
                newGrounded.Add(new GenericInstantiator.EdgeAggregator(antecedent, eq, segmentAnnotation));
            }

            return newGrounded;
        }
        //
        //
        //
        private static List<EdgeAggregator> IfCongruencesApplyToTrianglesGenerate(Triangle ct1, Triangle ct2, CongruentSegments css1, CongruentSegments css2)
        {
            List<EdgeAggregator> newGrounded = new List<EdgeAggregator>();

            //
            // The congruent relationships need to link the given triangles
            //
            if (!css1.LinksTriangles(ct1, ct2)) return newGrounded;
            if (!css2.LinksTriangles(ct1, ct2)) return newGrounded;

            Segment seg1Tri1 = ct1.GetSegment(css1);
            Segment seg2Tri1 = ct1.GetSegment(css2);

            Segment seg1Tri2 = ct2.GetSegment(css1);
            Segment seg2Tri2 = ct2.GetSegment(css2);

            // Avoid redundant segments, if it arises
            if (seg1Tri1.StructurallyEquals(seg2Tri1)) return newGrounded;
            if (seg1Tri2.StructurallyEquals(seg2Tri2)) return newGrounded;

            //
            // Proportional Segments (we generate only as needed to avoid bloat in the hypergraph (assuming they are used by both triangles)
            // We avoid generating proportions if they are truly congruences.
            //
            List<GroundedClause> propAntecedent = new List<GroundedClause>();
            propAntecedent.Add(css1);
            propAntecedent.Add(css2);

            SegmentRatio ratio1 = new SegmentRatio(seg1Tri1, seg1Tri2);
            SegmentRatio ratio2 = new SegmentRatio(seg2Tri1, seg2Tri2);

            GeometricSegmentRatioEquation newEq = new GeometricSegmentRatioEquation(ratio1, ratio2);

            newGrounded.Add(new EdgeAggregator(propAntecedent, newEq, annotation));

            ////
            //// Only generate if ratios are not 1.
            ////

            //GeometricSegmentRatio newProp = null;
            //if (!Utilities.CompareValues(seg1Tri1.Length, seg1Tri2.Length))
            //{
            //    newProp = new GeometricSegmentRatio(seg1Tri1, seg1Tri2);
            //    newGrounded.Add(new EdgeAggregator(propAntecedent, newProp, annotation));
            //}
            //if (!Utilities.CompareValues(seg1Tri1.Length, seg2Tri2.Length))
            //{
            //    newProp = new GeometricSegmentRatio(seg1Tri1, seg2Tri2);
            //    newGrounded.Add(new EdgeAggregator(propAntecedent, newProp, annotation));
            //}
            //if (!Utilities.CompareValues(seg2Tri1.Length, seg1Tri2.Length))
            //{
            //    newProp = new GeometricSegmentRatio(seg2Tri1, seg1Tri2);
            //    newGrounded.Add(new EdgeAggregator(propAntecedent, newProp, annotation));
            //}
            //if (!Utilities.CompareValues(seg2Tri1.Length, seg2Tri2.Length))
            //{
            //    newProp = new GeometricSegmentRatio(seg2Tri1, seg2Tri2);
            //    newGrounded.Add(new EdgeAggregator(propAntecedent, newProp, annotation));
            //}

            return newGrounded;
        }
        private static List<EdgeAggregator> CheckAndGenerateProportionality(Triangle tri, Intersection inter1,
                                                                            Intersection inter2, Parallel parallel)
        {
            List<EdgeAggregator> newGrounded = new List<EdgeAggregator>();

            // The two intersections should not be at the same vertex
            if (inter1.intersect.Equals(inter2.intersect)) return newGrounded;

            //
            // Do these intersections share a segment? That is, do they share the transversal?
            //
            Segment transversal = inter1.AcquireTransversal(inter2);
            if (transversal == null) return newGrounded;

            //
            // Is the transversal a side of the triangle? It should not be.
            //
            if (tri.LiesOn(transversal)) return newGrounded;

            //
            // Determine if one parallel segment is a side of the triangle (which must occur)
            //
            Segment coinciding = tri.DoesParallelCoincideWith(parallel);
            if (coinciding == null) return newGrounded;

            // The transversal and common segment must be distinct
            if (coinciding.IsCollinearWith(transversal)) return newGrounded;

            //
            // Determine if the simplified transversal is within the parallel relationship.
            //
            Segment parallelTransversal = parallel.OtherSegment(coinciding);
            Segment simpleParallelTransversal = new Segment(inter1.intersect, inter2.intersect);

            if (!parallelTransversal.IsCollinearWith(simpleParallelTransversal)) return newGrounded;

            //            A
            //           /\
            //          /  \
            //         /    \
            //  off1  /------\ off2
            //       /        \
            //    B /__________\ C

            //
            // Both intersections should create a T-shape.
            //
            Point off1 = inter1.CreatesTShape();
            Point off2 = inter2.CreatesTShape();
            if (off1 == null || off2 == null) return newGrounded;

            // Get the intersection segments which should coincide with the triangle sides
            KeyValuePair<Segment, Segment> otherSides = tri.OtherSides(coinciding);

            // The intersections may be outside this triangle
            if (otherSides.Key == null || otherSides.Value == null) return newGrounded;

            Segment side1 = inter1.OtherSegment(transversal);
            Segment side2 = inter2.OtherSegment(transversal);

            // Get the actual sides of the triangle
            Segment triangleSide1 = null;
            Segment triangleSide2 = null;
            if (side1.IsCollinearWith(otherSides.Key) && side2.IsCollinearWith(otherSides.Value))
            {
                triangleSide1 = otherSides.Key;
                triangleSide2 = otherSides.Value;
            }
            else if (side1.IsCollinearWith(otherSides.Value) && side2.IsCollinearWith(otherSides.Key))
            {
                triangleSide1 = otherSides.Value;
                triangleSide2 = otherSides.Key;
            }
            else return newGrounded;

            // Verify the opposing parts of the T are on the opposite sides of the triangle
            if (!triangleSide1.PointLiesOnAndExactlyBetweenEndpoints(off2)) return newGrounded;
            if (!triangleSide2.PointLiesOnAndExactlyBetweenEndpoints(off1)) return newGrounded;

            //
            // Construct the new proprtional relationship and resultant equation
            //
            Point sharedVertex = triangleSide1.SharedVertex(triangleSide2);
            SegmentRatio newProp1 = new SegmentRatio(new Segment(sharedVertex, off2), triangleSide1);
            SegmentRatio newProp2 = new SegmentRatio(new Segment(sharedVertex, off1), triangleSide2);

            GeometricSegmentRatioEquation newEq = new GeometricSegmentRatioEquation(newProp1, newProp2);

            // Construct hyperedge
            List<GroundedClause> antecedent = new List<GroundedClause>();
            antecedent.Add(tri);
            antecedent.Add(inter1);
            antecedent.Add(inter2);
            antecedent.Add(parallel);

            newGrounded.Add(new EdgeAggregator(antecedent, newEq, annotation));

            return newGrounded;
        }
Exemple #20
0
 public GeometricSegmentRatioEquation(SegmentRatio r1, SegmentRatio r2) : base(r1, r2)
 {
 }
Exemple #21
0
        public static List<GenericInstantiator.EdgeAggregator> CreateProportionEquation(SegmentRatio ratio1, SegmentRatio ratio2)
        {
            List<GenericInstantiator.EdgeAggregator> newGrounded = new List<GenericInstantiator.EdgeAggregator>();

            // Double-Check that the ratios are, in-fact, known.
            if (!ratio1.ProportionValueKnown() || !ratio2.ProportionValueKnown()) return newGrounded;

            //
            // Create the antecedent clauses
            //
            List<GroundedClause> antecedent = new List<GroundedClause>();
            antecedent.Add(ratio1);
            antecedent.Add(ratio2);

            // Create the consequent proportionality equation.
            GeometricSegmentRatioEquation gsreq = new GeometricSegmentRatioEquation(ratio1, ratio2);

            newGrounded.Add(new GenericInstantiator.EdgeAggregator(antecedent, gsreq, propAnnotation));

            return newGrounded;
        }
 public AlgebraicSegmentRatioEquation(SegmentRatio r1, SegmentRatio r2)
     : base(r1, r2)
 {
 }
Exemple #23
0
        public static List <GenericInstantiator.EdgeAggregator> CreateProportionEquation(SegmentRatio ratio1, SegmentRatio ratio2)
        {
            List <GenericInstantiator.EdgeAggregator> newGrounded = new List <GenericInstantiator.EdgeAggregator>();

            // Double-Check that the ratios are, in-fact, known.
            if (!ratio1.ProportionValueKnown() || !ratio2.ProportionValueKnown())
            {
                return(newGrounded);
            }

            //
            // Create the antecedent clauses
            //
            List <GroundedClause> antecedent = new List <GroundedClause>();

            antecedent.Add(ratio1);
            antecedent.Add(ratio2);

            // Create the consequent proportionality equation.
            GeometricSegmentRatioEquation gsreq = new GeometricSegmentRatioEquation(ratio1, ratio2);

            newGrounded.Add(new GenericInstantiator.EdgeAggregator(antecedent, gsreq, propAnnotation));

            return(newGrounded);
        }
 public AlgebraicSegmentRatioEquation(SegmentRatio r1, SegmentRatio r2) : base(r1, r2)
 {
 }
        private SegmentRatio GetOtherImpliedRatio(SegmentRatio thatRatio)
        {
            if (thatRatio.HasSegment(lhs.largerSegment) && thatRatio.HasSegment(rhs.largerSegment))
            {
                return new SegmentRatio(lhs.smallerSegment, rhs.smallerSegment);
            }

            if (thatRatio.HasSegment(lhs.smallerSegment) && thatRatio.HasSegment(rhs.smallerSegment))
            {
                return new SegmentRatio(lhs.largerSegment, rhs.largerSegment);
            }

            return null;
        }
Exemple #26
0
        // Of the propportional pair, return the segment that applies to this triangle
        public Segment GetSegment(SegmentRatio prop)
        {
            if (HasSegment(prop.smallerSegment)) return prop.smallerSegment;
            if (HasSegment(prop.largerSegment)) return prop.largerSegment;

            return null;
        }
        //
        //  if x / y = z / w   and we are checking for  x / z OR y / w
        //
        private bool HasImpliedRatio(SegmentRatio thatRatio)
        {
            if (thatRatio.HasSegment(lhs.largerSegment) && thatRatio.HasSegment(rhs.largerSegment)) return true;
            if (thatRatio.HasSegment(lhs.smallerSegment) && thatRatio.HasSegment(rhs.smallerSegment)) return true;

            return false;
        }