public List <Line> Offset3D(List <Polyline> x, double y) { List <Line> output = new List <Line>(); if (x.Count < 4) { return(output); } List <Line> lines = breakPoly(x[0]); for (int i = 1; i < x.Count; i++) { List <Line> ls = breakPoly(x[i]); //Print(ls.Count.ToString()); for (int ii = 0; ii < ls.Count; ii++) { bool sign = true; for (int j = 0; j < lines.Count; j++) { if (isDumpLines(lines[j], ls[ii])) { sign = false; break; } } //Print(sign.ToString()); if (sign) { lines.Add(ls[ii]); } } } Point3d cen = new Point3d(); for (int i = 0; i < lines.Count; i++) { cen += lines[i].From; cen += lines[i].To; } // B = lines; cen /= 2 * lines.Count; HullFrame.box box = new HullFrame.box(lines); HullFrame.hull hull = new HullFrame.hull(box, cen); for (int i = 0; i < x.Count; i++) { if (x[i].Count < 3) {//Print("00001"); return(output); } Plane p = new Plane(x[i][0], x[i][1], x[i][2]); Vector3d v = cen - p.ClosestPoint(cen); v.Unitize(); p = new Plane(x[i][0], v); p.Transform(Transform.Translation(v * y)); hull.intersect(p); hull.clearnull(); } for (int i = 0; i < hull.edges.Count; i++) { output.Add(new Line(hull.edges[i].p1.pos, hull.edges[i].p2.pos)); } List <Point3d> pt = new List <Point3d>(); for (int i = 0; i < hull.pts.Count; i++) { pt.Add(hull.pts[i].pos); } return(output); }
public List<Line> Offset3D(List<Polyline> x, double y) { List<Line> output = new List<Line>(); if (x.Count < 4) return output; List<Line> lines = breakPoly(x[0]); for (int i = 1; i < x.Count; i++) { List<Line> ls = breakPoly(x[i]); //Print(ls.Count.ToString()); for (int ii = 0; ii < ls.Count; ii++) { bool sign = true; for (int j = 0; j < lines.Count; j++) { if (isDumpLines(lines[j], ls[ii])) { sign = false; break; } } //Print(sign.ToString()); if (sign) lines.Add(ls[ii]); } } Point3d cen = new Point3d(); for (int i = 0; i < lines.Count; i++) { cen += lines[i].From; cen += lines[i].To; } // B = lines; cen /= 2 * lines.Count; HullFrame.box box = new HullFrame.box(lines); HullFrame.hull hull = new HullFrame.hull(box, cen); for (int i = 0; i < x.Count; i++) { if (x[i].Count < 3) {//Print("00001"); return output; } Plane p = new Plane(x[i][0], x[i][1], x[i][2]); Vector3d v = cen - p.ClosestPoint(cen); v.Unitize(); p = new Plane(x[i][0], v); p.Transform(Transform.Translation(v * y)); hull.intersect(p); hull.clearnull(); } for (int i = 0; i < hull.edges.Count; i++) { output.Add(new Line(hull.edges[i].p1.pos, hull.edges[i].p2.pos)); } List<Point3d> pt = new List<Point3d>(); for (int i = 0; i < hull.pts.Count; i++) { pt.Add(hull.pts[i].pos); } return output; }