public void TestEdgeAngleBisectorPoint() { Vertex v1; Vertex v2; Vertex v3; v1 = new Vertex(1, 3); v2 = new Vertex(1, 1); v3 = new Vertex(3, 1); LineSegment ls1 = new LineSegment(v1, v2); LineSegment ls2 = new LineSegment(v2, v3); Vertex bisector = MathLibrary.GetAngleBisectorVertex(ls1, ls2); Assert.AreEqual(1.71, Math.Round(bisector.GetX(), 2)); Assert.AreEqual(1.71, Math.Round(bisector.GetY(), 2)); v1 = new Vertex(5.78, 5.90); v2 = new Vertex(5, 3); v3 = new Vertex(6.93, 3.52); ls1 = new LineSegment(v1, v2); ls2 = new LineSegment(v2, v3); bisector = MathLibrary.GetAngleBisectorVertex(ls1, ls2); Assert.AreEqual(5.71, Math.Round(bisector.GetX(), 2)); Assert.AreEqual(3.71, Math.Round(bisector.GetY(), 2)); }
public void TestEqualSegments() { LineSegment ls1 = new LineSegment(v1, v2); LineSegment ls2 = new LineSegment(v1, v2); Assert.AreEqual(ls1, ls2); }
public void TestLineSegment() { LineSegment ls = new LineSegment(v1, v2); Assert.AreEqual(0, ls.Start.GetX()); Assert.AreEqual(1, ls.Start.GetY()); Assert.AreEqual(2, ls.End.GetX()); Assert.AreEqual(3, ls.End.GetY()); }
public Vertex(double x, double y) { this.x = x; this.y = y; this.prevVertex = null; this.nextVertex = null; this.bisectorVertex = null; this.prevLS = null; this.nextLS = null; this.processed = false; this.type = VertexType.Undefined; }
public Intersection(double x, double y, Vertex vA, Vertex vB, Vertex.VertexType type, LineSegment lsVA, LineSegment lsVB) { this.x = x; this.y = y; this.vA = vA; this.vB = vB; this.type = type; this.lsVA = lsVA; this.lsVB = lsVB; this.distance = MathLibrary.GetDistanceBetweenLineAndVertex(vA, vB, new Vertex(x, y)); }
public static Vertex GetAngleBisectorVertex(LineSegment ls1, LineSegment ls2) { Vertex intersection = GetIntersectionPoint(ls1, ls2); //THE LINES ARE PARALLEL if (double.IsInfinity(intersection.GetX()) || double.IsNaN(intersection.GetX()) || double.IsInfinity(intersection.GetY()) || double.IsNaN(intersection.GetY())) return null; Vertex maxLine1; Vertex maxLine2; if (GetDistanceBetweenVertices(ls1.Start, intersection) >= GetDistanceBetweenVertices(ls1.End, intersection)) maxLine1 = ls1.Start; else maxLine1 = ls1.End; if (GetDistanceBetweenVertices(ls2.Start, intersection) >= GetDistanceBetweenVertices(ls2.End, intersection)) maxLine2 = ls2.Start; else maxLine2 = ls2.End; double bisectorX = 0; double bisectorY = 0; double distance12 = GetDistanceBetweenVertices(maxLine1, intersection); double distance32 = GetDistanceBetweenVertices(maxLine2, intersection); bisectorX = (maxLine1.GetX() - intersection.GetX()) / distance12; bisectorY = (maxLine1.GetY() - intersection.GetY()) / distance12; bisectorX = bisectorX + ((maxLine2.GetX() - intersection.GetX()) / distance32); bisectorY = bisectorY + ((maxLine2.GetY() - intersection.GetY()) / distance32); bisectorX = bisectorX * 0.5; bisectorY = bisectorY * 0.5; double distance = GetDistanceOfVertex(bisectorX, bisectorY); bisectorX = intersection.GetX() + (bisectorX / distance); bisectorY = intersection.GetY() + (bisectorY / distance); Vertex bisectorVertex = new Vertex(bisectorX, bisectorY); return bisectorVertex; }
public void TestIntersectionPointLineEquations() { Vertex v1 = new Vertex(1, 3); Vertex v2 = new Vertex(1, 1); Vertex v3 = new Vertex(3, 1); LineSegment ls1 = new LineSegment(v1, v2); LineSegment ls2 = new LineSegment(v2, v3); Assert.AreEqual(new Vertex(1, 1), MathLibrary.GetIntersectionPoint(ls1, ls2)); v1 = new Vertex(1, 1); v2 = new Vertex(5, 5); v3 = new Vertex(0, 4); Vertex v4 = new Vertex(4, 0); ls1 = new LineSegment(v1, v2); ls2 = new LineSegment(v3, v4); Assert.AreEqual(new Vertex(2, 2), MathLibrary.GetIntersectionPoint(ls1, ls2)); }
public void TestSplitAngleBisectorPoint() { Vertex v1 = new Vertex(4, 0); Vertex v2 = new Vertex(4, 3); Vertex v3 = new Vertex(8, 3); LineSegment ls1 = new LineSegment(v1, v2); LineSegment ls2 = new LineSegment(v2, v3); Vertex bisector = MathLibrary.GetAngleBisectorVertex(ls1, ls2); bisector = MathLibrary.Rotate(v2, bisector, 180); Assert.AreEqual(3.29, Math.Round(bisector.GetX(), 2)); Assert.AreEqual(3.71, Math.Round(bisector.GetY(), 2)); }
public void TestSetLineSegmentEdges() { Vertex v1 = new Vertex(0, 1); Vertex v2 = new Vertex(0, 0); Vertex v3 = new Vertex(1, 0); LineSegment ls1 = new LineSegment(new Vertex(1, 1), new Vertex(3, 3)); LineSegment ls2 = new LineSegment(new Vertex(10, 10), new Vertex(30, 30)); Assert.IsNull(v2.PrevLineSegment); Assert.IsNull(v2.NextLineSegment); v2.SetPrevVertex(v1); v2.SetNextVertex(v3); Assert.AreEqual(new LineSegment(v1, v2), v2.PrevLineSegment); Assert.AreEqual(new LineSegment(v2, v3), v2.NextLineSegment); v2.PrevLineSegment = ls1; v2.NextLineSegment = ls2; Assert.AreEqual(ls1, v2.PrevLineSegment); Assert.AreEqual(ls2, v2.NextLineSegment); }
public void SetUp() { ls1 = new LineSegment(new Vertex(0, 0), new Vertex(0, 1)); ls2 = new LineSegment(new Vertex(0, 0), new Vertex(1, 0)); }
public void SetPrevVertex(Vertex v) { this.prevVertex = v; this.prevLS = new LineSegment(v, this); }
public void SetNextVertex(Vertex v) { this.nextVertex = v; this.nextLS = new LineSegment(this, v); }
public static Vertex GetIntersectionPoint(LineSegment ls1, LineSegment ls2) { LineEquation le1 = GetLineEquation(ls1.Start, ls1.End); LineEquation le2 = GetLineEquation(ls2.Start, ls2.End); if (double.IsInfinity(le1.Slope)) //VERTICAL LINE { double x = ls1.Start.GetX(); return new Vertex(x, le2.GetY(x)); } else if (double.IsInfinity(le2.Slope)) //VERTICAL LINE { double x = ls2.Start.GetX(); return new Vertex(x, le1.GetY(x)); } else { return GetIntersectionPoint(le1, le2); } }