public void Arc3DTest_0001() { var tol = 1e-7; var p1 = new Vector3D("X = 13.87329226 Y = 134.93466652 Z = -3.70729037"); var p2 = new Vector3D("X = 75.89230418 Y = 224.11406806 Z = 35.97437873"); var p3 = new Vector3D("X = 97.48181688 Y = 229.31008314 Z = 16.9314998"); var arc = new Arc3D(tol, p1, p2, p3); var plo = new Vector3D("X = -74.96786784 Y = 178.50832685 Z = -43.45380285"); var plx = new Vector3D("X = 61.65932598 Y = 313.82398026 Z = -33.75931542"); var ply = new Vector3D("X = 87.35160811 Y = 8.94741958 Z = 35.66234059"); var plcs = new CoordinateSystem3D(plo, plx - plo, ply - plo); var iSegmentPts = arc.Intersect(tol, plcs, only_perimeter: false).ToList(); var i1 = iSegmentPts[0]; var i2 = iSegmentPts[1]; var iSegment = new Line3D(i1, i2); Assert.True(plcs.Contains(tol, i1)); Assert.True(plcs.Contains(tol, i2)); Assert.True(arc.Contains(tol, i1, onlyPerimeter: false)); Assert.True(arc.Contains(tol, i2, onlyPerimeter: false)); Assert.True(i1.EqualsTol(tol, new Vector3D("X = 40.09735573 Y = 156.48945821 Z = -7.46179105"))); Assert.True(i2.EqualsTol(tol, new Vector3D("X = 72.20796391 Y = 188.29182351 Z = -5.18335819"))); }
public void Arc3DTest_001() { var o = new Vector3D(4.4249, 1.0332, -3.7054); var cs_ = new CoordinateSystem3D(o, new Vector3D(-.1201, 4.4926, 1.4138), new Vector3D(-1.6282, 3.2952, 2.1837)); // build cs for arc with same cad representation var csCAD = new CoordinateSystem3D(o, cs_.BaseZ, CoordinateSystem3DAutoEnum.AAA); var r = 4.2753; var ang1 = 63.97731d.ToRad(); var ange2 = 26.10878d.ToRad(); var arc = new Arc3D(1e-4, csCAD, r, ang1, ange2); var c = new Circle3D(arc); var seg_i = new Line3D(2.2826, 10.2516, -3.7469, 1.3767, -3.7709, 1.5019); var ip_circ = c.Intersect(1e-4, seg_i, segment_mode: false); var ip_arc = arc.Intersect(1e-2, seg_i); // segment intersecting arc Assert.True(ip_circ.Count() == 1); Assert.True(ip_circ.First().EqualsTol(1e-4, ip_arc.First())); Assert.True(ip_circ.First().EqualsTol(1e-2, 1.83, 3.24, -1.12)); // segment not intersecting arc var seg_i2 = seg_i.Scale(seg_i.From, .3); Assert.True(c.Intersect(1e-4, seg_i2, segment_mode: true).Count() == 0); Assert.True(arc.Intersect(1e-4, seg_i2, segment_mode: true).Count() == 0); // segment not intersecting, but line intersecting arc Assert.True(c.Intersect(1e-4, seg_i2, segment_mode: false).Count() == 1); Assert.True(c.Intersect(1e-4, seg_i2, segment_mode: false).First().EqualsTol(1e-4, ip_arc.First())); // segment intresecting circle, but not arc var seg_e = new Line3D(2.4523, 9.6971, -1.8004, 4.6142, -.0631, -2.0519); Assert.True(c.Intersect(1e-4, seg_e, segment_mode: false).Count() == 1); Assert.True(c.Intersect(1e-4, seg_e, segment_mode: false).First().EqualsTol(1e-2, 3.53, 4.82, -1.93)); Assert.True(arc.Intersect(1e-4, seg_e).Count() == 0); // Geometry Assert.True(arc.GeomFrom.EqualsTol(1e-3, arc.From)); Assert.True(arc.GeomTo.EqualsTol(1e-3, arc.To)); var vertexes = arc.Vertexes.ToList(); Assert.True(vertexes.Count == 2 && vertexes.Any(a => a.EqualsTol(1e-3, arc.From)) && vertexes.Any(a => a.EqualsTol(1e-3, arc.To))); // PtAngle and mid var midpoint = arc.MidPoint; Assert.True(arc.PtAtAngle(arc.AngleStart + arc.Angle / 2).EqualsTol(1e-3, midpoint)); // segment Assert.True(arc.Segment.EqualsTol(1e-3, new Line3D(arc.From, arc.To))); // arc equals Assert.True(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.From, arc.MidPoint, arc.To))); Assert.True(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.CS, arc.Radius, arc.AngleStart, arc.AngleEnd))); Assert.False(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.CS, arc.Radius / 2, arc.AngleStart, arc.AngleEnd))); Assert.False(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.CS.Move(new Vector3D(1, 0, 0)), arc.Radius, arc.AngleStart, arc.AngleEnd))); Assert.False(arc.EqualsTol(1e-3, new Arc3D(1e-3, arc.CS, arc.Radius, arc.AngleStart + 1, arc.AngleEnd + 1))); // arc bulge Assert.True(arc.Bulge(1e-3, arc.From, arc.To, arc.CS.BaseZ).EqualsTol(1e-3, Tan(arc.Angle / 4))); Assert.True(arc.Bulge(1e-3, arc.From, arc.To, -arc.CS.BaseZ).EqualsTol(1e-3, -Tan(arc.Angle / 4))); // arc contains Assert.False(arc.Contains(1e-3, new Vector3D(3.084, 3.965, -1.843), onlyPerimeter: false)); // out arc shape - in plane Assert.False(arc.Contains(1e-3, new Vector3D(2.821, 4.417, -2.795), onlyPerimeter: false)); // out of plane Assert.True(arc.Contains(1e-3, new Vector3D(5.446, 3.708, -3.677), onlyPerimeter: false)); // arc shape - in plane Assert.False(arc.Contains(1e-3, new Vector3D(5.142, 3.774, -4.713), onlyPerimeter: false)); // out of plane // read arc from dxf and use comparer { var doc = netDxf.DxfDocument.Load("_torefact/doc/Arc3DTest_001.dxf"); var arc_from_dxf = doc.Arcs.First().ToArc3D(1e-3); var cmp = new Arc3DEqualityComparer(1e-3); var q = new[] { arc_from_dxf, arc, new Arc3D(1e-3, arc.From, arc.MidPoint, arc.To), new Arc3D(1e-3, arc.CS, arc.Radius, arc.AngleStart, arc.AngleEnd) }; Assert.True(q.Distinct(cmp).Count() == 1); Assert.True(arc_from_dxf.EqualsTol(1e-3, ((netDxf.Entities.Arc)arc.DxfEntity).ToArc3D(1e-3))); } }