public static LineSymbol GenerateLine(Point pt1, Point pt2) { if (pt1.Equals(pt2)) return null; Debug.Assert(pt1.Concrete); Debug.Assert(pt2.Concrete); /* if (pt1.XCoordinate.Equals(pt2.XCoordinate)) { double d; LogicSharp.IsDouble(pt1.XCoordinate, out d); var line1 = new Line(1, null, -1 * d); return new LineSymbol(line1); } if (pt1.YCoordinate.Equals(pt2.YCoordinate)) { double d; LogicSharp.IsDouble(pt1.YCoordinate, out d); var line2 = new Line(null, 1, -1 * d); return new LineSymbol(line2); }*/ //Strategy: y = mx+b, find slope m and intercept b //step 1: calc slope double p1x, p1y, p2x, p2y; LogicSharp.IsDouble(pt1.XCoordinate, out p1x); LogicSharp.IsDouble(pt1.YCoordinate, out p1y); LogicSharp.IsDouble(pt2.XCoordinate, out p2x); LogicSharp.IsDouble(pt2.YCoordinate, out p2y); var a = p1y - p2y; var b = p2x - p1x; var c = (p1x - p2x)*p1y + (p2y - p1y)*p1x; int intB; int intC; bool cond1 = LogicSharp.IsInt(b/a, out intB); bool cond2 = LogicSharp.IsInt(c/a, out intC); if (cond1 && cond2) { a = 1; b = intB; c = intC; } if (a < 0.0d) { a = -1*a; b = -1*b; c = -1*c; } var line = new Line(a,b,c) {InputType = LineType.Relation}; return new LineSymbol(line); }
public LineSegment(string label, Point pt1, Point pt2) : base(ShapeType.LineSegment, label) { _pt1 = pt1; _pt2 = pt2; if (pt1.Equals(pt2)) throw new Exception("Two points are identical"); InputType = LineSegmentType.Relation; ExtractRelationLabel(pt1.Label, pt2.Label); Calc_Distance(); }
public static LineSegmentSymbol GenerateLineSegment(Point pt1, Point pt2) { if (pt1.Equals(pt2)) return null; Debug.Assert(pt1.Concrete); Debug.Assert(pt2.Concrete); var ls = new LineSegment(pt1, pt2); var lss = new LineSegmentSymbol(ls); if(pt1.Traces.Count != 0) lss.Traces.AddRange(pt1.Traces); if(pt2.Traces.Count != 0) lss.Traces.AddRange(pt2.Traces); TraceInstructionalDesign.FromPointsToLineSegment(lss); return lss; }
public static PointSymbol GenerateMidPoint(Point pt1, Point pt2) { if (pt1.Equals(pt2)) return null; Debug.Assert(pt1.Concrete); Debug.Assert(pt2.Concrete); double p1x, p1y, p2x, p2y; LogicSharp.IsDouble(pt1.XCoordinate, out p1x); LogicSharp.IsDouble(pt1.YCoordinate, out p1y); LogicSharp.IsDouble(pt2.XCoordinate, out p2x); LogicSharp.IsDouble(pt2.YCoordinate, out p2y); var midX = (p1x + p2x)/2; var midY = (p1y + p2y)/2; var midPoint = new Point(midX, midY); return new PointSymbol(midPoint); }
public static PointSymbol GenerateMidPoint(Point pt1, Point pt2) { if (pt1.Equals(pt2)) { return(null); } Debug.Assert(pt1.Concrete); Debug.Assert(pt2.Concrete); double p1x, p1y, p2x, p2y; LogicSharp.IsDouble(pt1.XCoordinate, out p1x); LogicSharp.IsDouble(pt1.YCoordinate, out p1y); LogicSharp.IsDouble(pt2.XCoordinate, out p2x); LogicSharp.IsDouble(pt2.YCoordinate, out p2y); var midX = (p1x + p2x) / 2; var midY = (p1y + p2y) / 2; var midPoint = new Point(midX, midY); return(new PointSymbol(midPoint)); }
public static LineSegmentSymbol GenerateLineSegment(Point pt1, Point pt2) { if (pt1.Equals(pt2)) { return(null); } Debug.Assert(pt1.Concrete); Debug.Assert(pt2.Concrete); var ls = new LineSegment(pt1, pt2); var lss = new LineSegmentSymbol(ls); if (pt1.Traces.Count != 0) { lss.Traces.AddRange(pt1.Traces); } if (pt2.Traces.Count != 0) { lss.Traces.AddRange(pt2.Traces); } TraceInstructionalDesign.FromPointsToLineSegment(lss); return(lss); }
public static LineSymbol GenerateLine(Point pt1, Point pt2) { if (pt1.Equals(pt2)) { return(null); } Debug.Assert(pt1.Concrete); Debug.Assert(pt2.Concrete); /* if (pt1.XCoordinate.Equals(pt2.XCoordinate)) * { * double d; * LogicSharp.IsDouble(pt1.XCoordinate, out d); * var line1 = new Line(1, null, -1 * d); * return new LineSymbol(line1); * } * * if (pt1.YCoordinate.Equals(pt2.YCoordinate)) * { * double d; * LogicSharp.IsDouble(pt1.YCoordinate, out d); * var line2 = new Line(null, 1, -1 * d); * return new LineSymbol(line2); * }*/ //Strategy: y = mx+b, find slope m and intercept b //step 1: calc slope double p1x, p1y, p2x, p2y; LogicSharp.IsDouble(pt1.XCoordinate, out p1x); LogicSharp.IsDouble(pt1.YCoordinate, out p1y); LogicSharp.IsDouble(pt2.XCoordinate, out p2x); LogicSharp.IsDouble(pt2.YCoordinate, out p2y); var a = p1y - p2y; var b = p2x - p1x; var c = (p1x - p2x) * p1y + (p2y - p1y) * p1x; int intB; int intC; bool cond1 = LogicSharp.IsInt(b / a, out intB); bool cond2 = LogicSharp.IsInt(c / a, out intC); if (cond1 && cond2) { a = 1; b = intB; c = intC; } if (a < 0.0d) { a = -1 * a; b = -1 * b; c = -1 * c; } var line = new Line(a, b, c) { InputType = LineType.Relation }; return(new LineSymbol(line)); }