public void ColinearTest() { var l = new Line3D(0, 0, 0, 10, 0, 0); var l2 = new Line3D(20, 0, 0, 30, 0, 0).Scale(new Vector3D(20, 0, 0), 1e6); Assert.True(l.Colinear(1e-1, l2)); Assert.True(l2.Colinear(1e-1, l)); var l3 = l.RotateAboutAxis(new Line3D(0, 0, 0, 0, 0, 1), 1e-1); Assert.False(l.Colinear(1e-1, l3)); Assert.False(l2.Colinear(1e-1, l3)); }
void Line3DTest() { var tolLen = model.MUDomain.Length.DefaultTolerance; // line contains point { var tolLenExcess = tolLen + 1e-10; // line (0,0,0)-(1,0,0) var l = new Line3D(Vector3D.Zero, new Vector3D(1, 0, 0), Line3DConstructMode.PointAndVector); Assert.True(l.LineContainsPoint(tolLen, 2, 0, 0)); Assert.False(l.LineContainsPoint(tolLen, 2, 1, 0)); Assert.False(l.LineContainsPoint(tolLen, 2, 0, 1)); Assert.True(l.SegmentContainsPoint(tolLen, 1, 0, 0)); Assert.True(l.SegmentContainsPoint(tolLen, 0, 0, 0)); Assert.False(l.SegmentContainsPoint(tolLen, -tolLenExcess, 0, 0)); Assert.True(l.SegmentContainsPoint(tolLen, 0, tolLen, 0)); Assert.False(l.SegmentContainsPoint(tolLen, 0, tolLenExcess, 0)); var l2 = new Line3D(Vector3D.Zero, new Vector3D(5, 0, 0), Line3DConstructMode.PointAndVector); // point on line Assert.True(l2.SegmentContainsPoint(.5, new Vector3D(-.5, 0, 0))); Assert.False(l2.SegmentContainsPoint(.5, new Vector3D(-.5 - 1e-10, 0, 0))); } // line 3d intersection { { var l1 = new Line3D(new Vector3D(0, 0, 0), new Vector3D(1, 0, 0)); var l2 = new Line3D(new Vector3D(2, 0, 0), new Vector3D(2, 0, 2)); Assert.True(l1.Intersect(tolLen, l2).EqualsTol(tolLen, 2, 0, 0)); } { var l1 = new Line3D(new Vector3D(0, 0, 0), new Vector3D(0, 1, 0)); var l2 = new Line3D(new Vector3D(0, 2, 0), new Vector3D(2, 2, 0)); Assert.True(l1.Intersect(tolLen, l2).EqualsTol(tolLen, 0, 2, 0)); } { var l1 = new Line3D(new Vector3D(0, 0, 0), new Vector3D(0, 0, 1)); var l2 = new Line3D(new Vector3D(0, 0, 2), new Vector3D(2, 0, 2)); Assert.True(l1.Intersect(tolLen, l2).EqualsTol(tolLen, 0, 0, 2)); } { var l1 = new Line3D(new Vector3D(0, 0, 0), new Vector3D(1.6206, 2, -1.4882)); var l2 = new Line3D(new Vector3D(1.2, .7, 2), new Vector3D(.6338, .3917, .969)); Assert.True(l1.Intersect(tolLen, l2).EqualsTol(tolLen, 0.0675, 0.0833, -0.062)); } } // project point on a line { var p = new Vector3D(1, 1, 0); var perpLine = Line3D.XAxisLine.Perpendicular(tolLen, p); Assert.True(perpLine.From.EqualsTol(tolLen, p) && perpLine.To.EqualsTol(tolLen, 1, 0, 0)); } // check two lines are colinear { Assert.True(new Line3D(new Vector3D(0, 0, 0), new Vector3D(1, 1, 1)) .Colinear(tolLen, new Line3D(new Vector3D(2, 2, 2), new Vector3D(3, 3, 3)))); Assert.False(new Line3D(new Vector3D(0, 0, 0), new Vector3D(1, 1, 1)) .Colinear(tolLen, new Line3D(new Vector3D(0, 0, 0), new Vector3D(1, 1, 1.11)))); { var v1 = Vector3D.From2DCoords(22.646652351539, 13.9522716251755, 23.5544912108728, 15.1454145967669); var v2 = Vector3D.From2DCoords(32.1714356467077, 26.4617928826826, 23.5548859449172, 15.1451142433282); var s1 = new Line3D(v1[0], v1[1]); var s2 = new Line3D(v2[0], v2[1]); Assert.True(s1.Colinear(1e-3, s2) == s2.Colinear(1e-3, s1)); } { var s1 = new Line3D(-90, 29.4932764928483, -90, 40); var s2 = new Line3D(-90, -2.84E-14, -90, 80); var segs = new[] { s1, s2 }; Assert.True(segs.MergeColinearSegments(1e-3).Count() == 1); } } // merge segments { var sega = new Line3D(new Vector3D(0, 0, 0), new Vector3D(2, 0, 0)); var segb = new Line3D(new Vector3D(1, 0, 0), new Vector3D(3, 0, 0)); var segc = new Line3D(new Vector3D(3, 0, 0), new Vector3D(1, 0, 0)); { var merge = new List <Line3D>() { sega, segb }.MergeColinearSegments(tolLen).ToList(); Assert.True(merge.Count == 1 && merge.First().EqualsTol(tolLen, new Line3D(new Vector3D(0, 0, 0), new Vector3D(3, 0, 0)))); } { var merge = new List <Line3D>() { sega, segc }.MergeColinearSegments(tolLen).ToList(); Assert.True(merge.Count == 1 && merge.First().EqualsTol(tolLen, new Line3D(new Vector3D(0, 0, 0), new Vector3D(3, 0, 0)))); } } }