static void Main(string[] args) { #if false //test code StreamWriter testsw = new StreamWriter("D:\\PersonalProjects\\Bridges 2011\\artshow\\sphere.stl"); testsw.WriteLine("solid sphereshell"); new Sphere(36.128, 5, true).Output(testsw, 1.0); //Torus(5, 1.5, 3).Output(testsw, 1.0); testsw.WriteLine("endsolid"); testsw.Close(); return; #endif ModelType model = ModelType.Outside; if (args.Count() > 1) { try { model = (ModelType)(Int16.Parse(args[1])); } catch { model = ModelType.Outside; } } double dRadius = 50.0; double dHalfLineWidth = 0.5; double dHalfLineHeight = 0.4; if (model == ModelType.Empty) { dHalfLineWidth = 0.5; dHalfLineHeight = 1.0; dRadius = 36.128 + dHalfLineHeight; //inside shell is a little smaller than white plastic ball } string Filename = args[0]; if (model == ModelType.Empty) Filename += "_empty.stl"; else if (model == ModelType.Inside) Filename += "_glow.stl"; else if (model == ModelType.Outside) Filename += ".stl"; StreamWriter sw = new StreamWriter(Filename); if (model == ModelType.Inside || model == ModelType.Outside) { sw.WriteLine("solid sphereshell"); Surface SphereSurface = new Surface(); if (model == ModelType.Inside) { SphereSurface.AddSurface(new Sphere(dRadius + dHalfLineHeight + 1.95, 6, true)); SphereSurface.AddSurface(new Sphere(dRadius + dHalfLineHeight - 0.05, 4, false)); } else if (model == ModelType.Outside) { SphereSurface.AddSurface(new Sphere(dRadius - dHalfLineHeight - 1.95, 4, true)); SphereSurface.AddSurface(new Sphere(dRadius - dHalfLineHeight + 0.05, 6, false)); } Point3D HolePunch = new Point3D(0, -1, 0).ScaledTo(dRadius); SurfaceTools.PunchHole(ref SphereSurface, //surf HolePunch, //center HolePunch, //direction 10, //length 1.2); //radius SphereSurface.Output(sw, 1.0); sw.WriteLine("endsolid"); } sw.WriteLine("solid tour"); Tour newTour = new Tour(args[0] + ".csv", dRadius, dHalfLineWidth, dHalfLineHeight); Surface TourSurface = new Surface(); TourSurface.AddSurface(newTour); TourSurface.Output(sw, 1.0); sw.WriteLine("endsolid"); sw.Close(); }
public static void PunchHole(ref Surface surf, Point3D center, Point3D direction, double Length, double Radius) { Surface HoleWall = new Surface(); List<int> HoleIdxs = new List<int>(); Point3D dir = direction.Normalized; for (int i = 0; i < surf.NumPoints; i++) { if (!IsInCylinder(surf.Point(i), center, dir, Length, Radius)) continue; for (int j = surf.NumFaces - 1; j >= 0; j--) { if (surf.Face(j).I == i || surf.Face(j).J == i || surf.Face(j).K == i) { if (!IsInCylinder(surf.Point(surf.Face(j).I), center, dir, Length, Radius)) HoleIdxs.Add(surf.Face(j).I); if (!IsInCylinder(surf.Point(surf.Face(j).J), center, dir, Length, Radius)) HoleIdxs.Add(surf.Face(j).J); if (!IsInCylinder(surf.Point(surf.Face(j).K), center, dir, Length, Radius)) HoleIdxs.Add(surf.Face(j).K); surf.RemoveFace(j); } } } //make sure points in hole wall are unique for (int j = HoleIdxs.Count() - 1; j >= 0; j--) { Point3D NewPt = surf.Point(HoleIdxs[j]); //check that existing points in HoleWall surface don't match int k; for (k = 0; k < HoleWall.NumPoints; k++) { if (NewPt == HoleWall.Point(k)) break; } //add if we haven't found it. if (k == HoleWall.NumPoints) HoleWall.AddPoint(NewPt); } //get the convex hull faces, then either remove them if they're pointing in our direction, or reverse them ConvexHull(ref HoleWall); for (int i = HoleWall.NumFaces - 1; i >= 0; i--) { double IR = HoleWall.Point(HoleWall.Face(i).I).R; double JR = HoleWall.Point(HoleWall.Face(i).J).R; double KR = HoleWall.Point(HoleWall.Face(i).K).R; if ( IR > center.R && JR > center.R && KR > center.R || IR < center.R && JR < center.R && KR < center.R ) { HoleWall.RemoveFace(i); } else { HoleWall.Face(i).Reverse(); } } //add in the new hole wall surf.AddSurface(HoleWall); }