static void notesImagePlanar_Executing(object sender, EventArgs e) { Bitmap bitmap = OpenBitmap(); if (bitmap == null) { return; } Part part = CreateImagePart(); Point[] points = new Point[4]; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { points[0] = Point.Create((i + 0) * stepSize, (j + 0) * stepSize, 0); points[1] = Point.Create((i + 1) * stepSize, (j + 0) * stepSize, 0); points[2] = Point.Create((i + 1) * stepSize, (j + 1) * stepSize, 0); points[3] = Point.Create((i + 0) * stepSize, (j + 1) * stepSize, 0); DesignBody designBody = ShapeHelper.CreatePolygon(points, Plane.PlaneXY, 0, part); designBody.SetColor(null, GetOpaquePixel(bitmap, i, j)); } } }
private static void CreateThreadCurves(Face cylinderFace, double pitch, double angle, double positionOffset, out CurveSegment innerCurve, out CurveSegment outerCurveA, out CurveSegment outerCurveB) { double radius, innerRadius, outerRadius; Line axis; Matrix trans; Cylinder cylinder = cylinderFace.Geometry as Cylinder; Debug.Assert(cylinder != null); radius = cylinder.Radius; axis = cylinder.Axis; Line axisCopy = axis; //needed for out property in lambda expression Interval bounds = AxisBounds(cylinderFace, axisCopy); Interval extendedBounds = Interval.Create(bounds.Start - pitch, bounds.End + pitch); CreateUntransformedThreadCurves(cylinderFace, pitch, angle, extendedBounds, positionOffset, out radius, out axis, out innerCurve, out outerCurveA, out outerCurveB, out trans, out innerRadius, out outerRadius); var planeA = Plane.PlaneXY; var planeB = Plane.Create(Frame.Create(Point.Create(0, 0, bounds.Span), Direction.DirZ)); trans = trans * Matrix.CreateTranslation(Vector.Create(0, 0, pitch)); innerCurve = TrimAndTransform(ref trans, planeA, planeB, innerCurve); outerCurveA = TrimAndTransform(ref trans, planeA, planeB, outerCurveA); outerCurveB = TrimAndTransform(ref trans, planeA, planeB, outerCurveB); }
// http://en.wikipedia.org/wiki/Boy%27s_surface public static Point Evaluate(Complex z) { Complex denom = z.Pow(6) + Math.Sqrt(5) * z.Pow(3) - 1; double g1 = -1.5 * (z * (1 - z.Pow(4)) / denom).Im; double g2 = -1.5 * (z * (1 + z.Pow(4)) / denom).Re; double g3 = ((1 + z.Pow(6)) / denom).Im - 0.5; double g = g1 * g1 + g2 * g2 + g3 * g3; return(Point.Create(g1 / g, g2 / g, g3 / g)); }
private static Body CreateBlock(Plane basePlane, double length, double width, double height) { var halfLength = length / 2; var halfWidth = width / 2; var point1 = Point.Create(-halfLength, -halfWidth, 0); var point2 = Point.Create(halfLength, -halfWidth, 0); var point3 = Point.Create(halfLength, halfWidth, 0); var point4 = Point.Create(-halfLength, halfWidth, 0); return(Body.ExtrudeProfile(basePlane, CreatePolyline(point1, point2, point3, point4, point1), height)); }
void Reset() { StopThread(); Rendering = null; StatusText = "Get ready for some mayhem."; double size = Math.PI; DesignBody desBody = ShapeHelper.CreateBlock(Point.Create(-size, -size, -size), Point.Origin, Window.ActiveWindow.Scene as Part); desBody.SetVisibility(null, false); gyroid.Reset(); }
public static DesignBody CreateBlock(Point point1, Point point2, IPart part) { List <Point> points = new List <Point>(); points.Add(point1); points.Add(Point.Create(point2.X, point1.Y, point1.Z)); points.Add(Point.Create(point2.X, point2.Y, point1.Z)); points.Add(Point.Create(point1.X, point2.Y, point1.Z)); return(CreatePolygon( points, Plane.Create(Frame.Create(point1, Direction.DirX, Direction.DirY)), point2.Z - point1.Z, part)); }
private static void CreateUntransformedThreadCurves(Face cylinderFace, double pitch, double angle, Interval bounds, double positionOffset, out double radius, out Line axis, out CurveSegment innerCurve, out CurveSegment outerCurveA, out CurveSegment outerCurveB, out Matrix trans, out double innerRadius, out double outerRadius) { Cylinder cylinder = cylinderFace.Geometry as Cylinder; Debug.Assert(cylinder != null); radius = cylinder.Radius; axis = cylinder.Axis; double threadDepth = pitch / (2 * Math.Tan(angle / 2)); innerRadius = radius + threadDepth * (positionOffset - 0.5); outerRadius = radius + threadDepth * (positionOffset + 0.5); int pointsPerTurn = 360; int pointCount = (int)(bounds.Span / pitch * pointsPerTurn); var outerPoints = new Point[pointCount]; var innerPoints = new Point[pointCount]; double s = bounds.Span; double a = Const.Tau * s / pitch; for (int i = 0; i < pointCount; i++) { double t = (double)i / (pointCount - 1); double rotation = a * t; double depth = s * t; outerPoints[i] = Point.Create(outerRadius * Math.Cos(rotation), outerRadius * Math.Sin(rotation), depth); innerPoints[i] = Point.Create(innerRadius * Math.Cos(rotation), innerRadius * Math.Sin(rotation), depth); } Func <double, double, Vector> Derivative = (t, r) => Vector.Create(-r * a * Math.Sin(a * t), r * a * Math.Cos(a * t), s); var outerCurve = CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, outerPoints, Accuracy.LinearResolution * 1E1, Derivative(0, outerRadius), Derivative(1, outerRadius))); innerCurve = CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, innerPoints, Accuracy.LinearResolution * 1E1, Derivative(0, innerRadius), Derivative(1, innerRadius))); var translation = Matrix.CreateTranslation(Vector.Create(0, 0, -pitch)); var offset = Matrix.CreateTranslation(Direction.DirZ * pitch / 2); outerCurveA = outerCurve.CreateTransformedCopy(translation * offset); outerCurveB = outerCurve.CreateTransformedCopy(translation * offset.Inverse); innerCurve = innerCurve.CreateTransformedCopy(translation); trans = Matrix.CreateMapping(Frame.Create(axis.Evaluate(bounds.Start).Point, axis.Direction)); }
protected override bool OnClickStart(ScreenPoint cursorPos, Line cursorRay) { DesignEdge designEdge = InteractionContext.Preselection as DesignEdge; if (designEdge == null) { return(false); } Circle edgeCircle = (Circle)designEdge.Shape.Geometry; Frame frame = edgeCircle.Frame; Face face = designEdge.Faces.Where(f => f.Shape.Geometry is Plane).First().Shape; Plane plane = (Plane)face.Geometry; if (frame.DirZ == plane.Frame.DirZ ^ !face.IsReversed) { frame = Frame.Create(frame.Origin, -frame.DirZ); } double angle = apiGroove.Angle; double depth = apiGroove.Depth; var points = new[] { Point.Create(apiGroove.InnerDiameter / 2, 0, 0), Point.Create(apiGroove.InnerDiameter / 2 + Math.Sin(angle) * depth, 0, -Math.Cos(angle) * depth), Point.Create(apiGroove.OuterDiameter / 2 - Math.Sin(angle) * depth, 0, -Math.Cos(angle) * depth), Point.Create(apiGroove.OuterDiameter / 2, 0, 0) }; var profile = points.AsPolygon(); var path = new[] { CurveSegment.Create(Circle.Create(Frame.World, 1)) }; WriteBlock.ExecuteTask("Create Profile", () => { var body = Body.SweepProfile(Plane.PlaneZX, profile, path); body.Transform(Matrix.CreateMapping(frame)); var cutter = DesignBody.Create(designEdge.Parent.Parent, "temp", body); designEdge.Parent.Shape.Subtract(new[] { cutter.Shape }); }); return(false); }
static void notesImageCylindrical_Executing(object sender, EventArgs e) { Bitmap bitmap = OpenBitmap(); if (bitmap == null) { return; } Part part = CreateImagePart(); int width = bitmap.Width; double radius = 0.5 * stepSize / Math.Sin(Math.PI / width) * Math.PI; Point[] points = new Point[4]; for (int i = 0; i < width; i++) { double angle1 = (double)i / width * 2 * Math.PI; double angle2 = (double)(i + 1) / width * 2 * Math.PI; for (int j = 0; j < bitmap.Height; j++) { double x1 = Math.Sin(angle1) * radius; double y1 = Math.Cos(angle1) * radius; double z1 = j * stepSize; double x2 = Math.Sin(angle2) * radius; double y2 = Math.Cos(angle2) * radius; double z2 = (j + 1) * stepSize; points[0] = Point.Create(x1, y1, z1); points[1] = Point.Create(x1, y1, z2); points[2] = Point.Create(x2, y2, z2); points[3] = Point.Create(x2, y2, z1); DesignBody designBody = ShapeHelper.CreatePolygon(points, null, 0, part); designBody.SetColor(null, GetOpaquePixel(bitmap, i, j)); } } }
private static IList <IList <Point> > GetChains(FaceToolPath toolPath) { var positions = new List <IList <Point> >(); var points = new List <Point>(); var box = toolPath.Face.GetBoundingBox(Matrix.Identity); var count = box.Size.Z / toolPath.CuttingParameters.StepOver; for (int i = 0; i < count; i++) { var z = i * toolPath.CuttingParameters.StepOver; var plane = Plane.Create(Frame.Create(Point.Create(0, 0, z), Direction.DirZ)); var section = toolPath.Face.Geometry.IntersectSurface(plane); foreach (var iTrimmedCurve in section.Curves) { for (int j = 0; j < 3; j++) { foreach (var offsetCurve in iTrimmedCurve.Offset(plane, j * toolPath.CuttingParameters.StepOver)) { points.AddRange(iTrimmedCurve.TessellateCurve(toolPath.CuttingParameters.Increment)); } } } if (points.Count < 1) { continue; } positions.Add(points); } return(positions); }
static void notesImageSpherical_Executing(object sender, EventArgs e) { Bitmap bitmap = OpenBitmap(); if (bitmap == null) { return; } Part part = CreateImagePart(); int width = bitmap.Width; int height = bitmap.Height; double radius = 0.5 * stepSize / Math.Sin(Math.PI / width) * Math.PI; Point startPoint = Point.Create(radius, 0, 0); Line yAxis = Line.Create(Point.Origin, Direction.DirY); Line zAxis = Line.Create(Point.Origin, Direction.DirZ); List <Point> points = new List <Point>(4); for (int i = 0; i < 4; i++) { points.Add(Point.Origin); } for (int i = 0; i < width; i++) { double angle1 = (double)i / width * 2 * Math.PI; double angle2 = (double)(i + 1) / width * 2 * Math.PI; for (int j = 0; j < height; j++) { double azimuth1 = ((double)j) / height * Math.PI - Math.PI / 2; double azimuth2 = ((double)j + 1) / height * Math.PI - Math.PI / 2; points[0] = Matrix.CreateRotation(zAxis, angle1) * Matrix.CreateRotation(yAxis, azimuth1) * startPoint; points[1] = Matrix.CreateRotation(zAxis, angle1) * Matrix.CreateRotation(yAxis, azimuth2) * startPoint; points[2] = Matrix.CreateRotation(zAxis, angle2) * Matrix.CreateRotation(yAxis, azimuth2) * startPoint; points[3] = Matrix.CreateRotation(zAxis, angle2) * Matrix.CreateRotation(yAxis, azimuth1) * startPoint; Point?extraPoint = null; if (Accuracy.Equals(points[3], points[0])) { extraPoint = points[0]; points.Remove(points[0]); } else { for (int k = 0; k < 3; k++) { if (Accuracy.Equals(points[k], points[k + 1])) { extraPoint = points[k]; points.Remove(points[k]); break; } } } DesignBody designBody = ShapeHelper.CreatePolygon(points, null, 0, part); designBody.SetColor(null, GetOpaquePixel(bitmap, i, j)); if (extraPoint != null) { points.Add(extraPoint.Value); } } } }
public Point RestPoint(Point point) { return(Point.Create(point.X, point.Y, CuttingParameters.RestZ + CuttingTool.Radius)); }
private static Body CreateThreadBody(Face cylinderFace, double pitch, double angle, double positionOffset) { double stitchTolerance = Accuracy.LinearResolution * 1E4; double radius, innerRadius, outerRadius; Line axis; CurveSegment innerCurve, outerCurveA, outerCurveB; Matrix trans; Cylinder cylinder = cylinderFace.Geometry as Cylinder; Debug.Assert(cylinder != null); axis = cylinder.Axis; Interval bounds = AxisBounds(cylinderFace, axis); int threadsPerSurface = 2; double threads = bounds.Span / pitch / threadsPerSurface; int threadSurfaceCount = (int)threads + 2; var surfaceBounds = Interval.Create(bounds.Start, bounds.Start + pitch * threadsPerSurface); // var extendedSurfaceBounds = Interval.Create(surfaceBounds.Start - surfaceBounds.Span / threadsPerSurface, surfaceBounds.End + surfaceBounds.Span / threadsPerSurface); CreateUntransformedThreadCurves(cylinderFace, pitch, angle, surfaceBounds, positionOffset, out radius, out axis, out innerCurve, out outerCurveA, out outerCurveB, out trans, out innerRadius, out outerRadius); Body loftBodyA = Body.LoftProfiles(new[] { new[] { outerCurveA }, new[] { innerCurve } }, false, false); Body loftBodyB = Body.LoftProfiles(new[] { new[] { innerCurve }, new[] { outerCurveB } }, false, false); loftBodyA.Stitch(new[] { loftBodyB }, stitchTolerance, null); loftBodyA.Transform(Matrix.CreateTranslation(Direction.DirZ * -pitch * threadsPerSurface / 2)); double threadDepth = outerRadius - innerRadius; double padding = 1.1; double paddedOuterRadius = innerRadius + threadDepth * padding; var copies = new Body[threadSurfaceCount]; for (int i = 0; i < threadSurfaceCount; i++) { copies[i] = loftBodyA.CreateTransformedCopy(Matrix.CreateTranslation(Direction.DirZ * surfaceBounds.Span * (i + 1))); } loftBodyA.Stitch(copies, stitchTolerance, null); double length = bounds.Span; var capA = Body.SweepProfile(Plane.PlaneZX, new[] { Point.Origin, Point.Create(innerRadius, 0, 0), Point.Create(paddedOuterRadius, 0, threadDepth * Math.Tan(angle / 2) * padding), Point.Create(paddedOuterRadius, 0, length - threadDepth * Math.Tan(angle / 2) * padding), Point.Create(innerRadius, 0, length), Point.Create(0, 0, length) }.AsPolygon(), new[] { CurveSegment.Create(Circle.Create(Frame.World, 1)) }); loftBodyA.Imprint(capA); capA.DeleteFaces(capA.Faces .Where(f => f.Edges .Where(e => (e.Geometry is Circle && Accuracy.EqualLengths(((Circle)e.Geometry).Radius, paddedOuterRadius)) ).Count() > 0).ToArray(), RepairAction.None ); loftBodyA.Fuse(new[] { capA }, true, null); while (!loftBodyA.IsManifold) { loftBodyA.DeleteFaces(loftBodyA.Faces.Where(f => f.Edges.Where(e => e.Faces.Count == 1).Count() > 0).ToArray(), RepairAction.None); } // loftBodyA.Faces.Select(f => loftBodyA.CopyFaces(new[] { f })).ToArray().Print(); loftBodyA.Transform(trans); return(loftBodyA); }