public void AddCurve(ITrimmedCurve iTrimmedCurve) { if (iTrimmedCurve.Geometry is Line) { dxfCurves.Add(new DxfLine(iTrimmedCurve, textWriter)); return; } if (iTrimmedCurve.Geometry is Circle) { if (iTrimmedCurve.Bounds.Span == 2 * Math.PI) { dxfCurves.Add(new DxfCircle(iTrimmedCurve, textWriter)); } else { dxfCurves.Add(new DxfArc(iTrimmedCurve, textWriter)); } return; } IList <Point> points = iTrimmedCurve.Geometry.GetPolyline(iTrimmedCurve.Bounds); for (int i = 0; i < points.Count - 1; i++) { dxfCurves.Add(new DxfLine(CurveSegment.Create(points[i], points[i + 1]), textWriter)); } }
public static MeshPrimitive GetCircularTabMesh(Point p0, Point p1, Direction normal, double angle, bool isMale) { Circle circle = GetCircularTabCircle(p0, p1, normal, angle, isMale); double centerParam = Math.PI / 2; if (!isMale) { angle *= -1; centerParam += Math.PI; } ITrimmedCurve circleSegment = CurveSegment.Create(circle, Interval.Create(centerParam - angle / 2, centerParam + angle / 2)); IList <Point> points = circleSegment.GetPolyline(); Debug.Assert(points.Count > 3, "Not enough points for tab faceting."); var facets = new List <Facet>(); for (int i = 1; i < points.Count - 1; i++) { facets.Add(new Facet(0, i, i + 1)); } return(MeshPrimitive.Create(points, normal, facets)); }
private static Body CreateSphericalSegment(Point tangent, Direction normal, double radius, double halfWidth, double thickness) { Point center = tangent + normal * radius; radius = Math.Abs(radius); Plane plane = Plane.Create(Frame.Create(center, normal, normal.ArbitraryPerpendicular)); Circle circle = Circle.Create(plane.Frame, radius); CurveSegment circleCurve = CurveSegment.Create(circle, Interval.Create(0, Math.Asin(halfWidth / radius))); Point rearCenter = tangent - normal * thickness; Point rearUpper = rearCenter + plane.Frame.DirY * halfWidth; var profile = new List <ITrimmedCurve>(); profile.Add(circleCurve); profile.Add(CurveSegment.Create(rearCenter, tangent)); profile.Add(CurveSegment.Create(rearCenter, rearUpper)); profile.Add(CurveSegment.Create(rearUpper, circleCurve.EndPoint)); foreach (ITrimmedCurve curve in profile) { DesignCurve.Create(Window.ActiveWindow.Scene as Part, curve); } ITrimmedCurve path = CurveSegment.Create(Circle.Create(Frame.Create(tangent, normal), 1)); return(Body.SweepProfile(plane, profile, new ITrimmedCurve[] { path })); // return Body.CreatePlanarBody(plane, new ITrimmedCurve[] { CurveSegment.Create(circle) }); // return ShapeHelper.CreateCircle(plane.Frame, radius * 2, Window.ActiveWindow.Scene as Part).Shape.Copy(); }
public static IList <ITrimmedCurve> AsPolygon(this IList <Point> points) { var profile = new List <ITrimmedCurve>(); for (int i = 0; i < points.Count; i++) { ITrimmedCurve iTrimmedCurve = null; if (i < points.Count - 1) { iTrimmedCurve = CurveSegment.Create(points[i], points[i + 1]); } else { iTrimmedCurve = CurveSegment.Create(points[i], points[0]); } if (iTrimmedCurve == null) // if points are the same, the curve is null { continue; } profile.Add(iTrimmedCurve); } if (profile.Count == 0) { return(null); } return(profile); }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { base.OnExecute(command, context, buttonRect); ICollection <IDesignEdge> designEdges = Window.ActiveWindow.ActiveContext.GetSelection <IDesignEdge>(); List <ITrimmedCurve> trimmedCurves = new List <ITrimmedCurve>(); Dictionary <ITrimmedCurve, IDesignEdge> curveToEdge = new Dictionary <ITrimmedCurve, IDesignEdge>(); foreach (IDesignEdge designEdge in designEdges) { ITrimmedCurve trimmedCurve = designEdge.Shape; trimmedCurves.Add(trimmedCurve); curveToEdge[trimmedCurve] = designEdge; } TrimmedCurveChain curveChain = new TrimmedCurveChain(trimmedCurves); Point startPoint = curveChain.Curves[0].StartPoint; Point startTail = startPoint + GetAverageNormal(startPoint, curveToEdge[curveChain.Curves[0].TrimmedCurve]) * edgeOffset; for (int i = 0; i < curveChain.Curves.Count; i++) { Point endPoint = curveChain.Curves[i].EndPoint; Point endTail = endPoint + GetAverageNormal(endPoint, curveToEdge[curveChain.Curves[i].TrimmedCurve]) * edgeOffset; if (i != curveChain.Curves.Count - 1) { endTail = new Point[] { endTail, endPoint + GetAverageNormal(endPoint, curveToEdge[curveChain.Curves[i + 1].TrimmedCurve]) * edgeOffset } }
public static ICollection <ITrimmedCurve> OffsetChainInward(this ICollection <ITrimmedCurve> curves, Face face, double distance, OffsetCornerType offsetCornerType) { if (!(face.Geometry is Plane)) { throw new ArgumentException("Face must be planar"); } Plane plane = (Plane)face.Geometry; ITrimmedCurve firstEdge = curves.First(); ITrimmedCurve[] otherEdges = curves.Skip(1).ToArray(); ICollection <ITrimmedCurve> offsetCurves = firstEdge.OffsetChain(plane, distance, otherEdges, offsetCornerType); if (offsetCurves.Count == 0) { return(new ITrimmedCurve[0]); } if (face.ContainsPoint(offsetCurves.First().StartPoint) ^ distance > 0) { return(offsetCurves); } offsetCurves = firstEdge.OffsetChain(plane, -distance, otherEdges, offsetCornerType); if (offsetCurves.Count == 0) { return(new ITrimmedCurve[0]); } return(offsetCurves); }
public static void CreateDashes(ITrimmedCurve curve, Part part, double dashMinSize, Layer dashLayer) { double length = curve.Length; int count = (int)Math.Floor(length / dashMinSize / 2) * 2; if (curve.StartPoint != curve.EndPoint) // odd number when not closed curve { count++; } double lastParam = curve.Bounds.Start; double param; for (int i = 0; i < count; i++) { if (curve.Geometry.TryOffsetParam(lastParam, length / count, out param)) { if (i % 2 == 1) { DesignCurve dash = DesignCurve.Create(part, CurveSegment.Create(curve.Geometry, Interval.Create(lastParam, param))); dash.Layer = dashLayer; } lastParam = param; } } }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { if (excelWorksheet == null) { excelWorksheet = new ExcelWorksheet(); } Window activeWindow = Window.ActiveWindow; List <ITrimmedCurve> iTrimmedCurves = new List <ITrimmedCurve>(activeWindow.GetAllSelectedITrimmedCurves()); if (iTrimmedCurves.Count != 2) { return; } ITrimmedCurve curveA = iTrimmedCurves[0]; ITrimmedCurve curveB = iTrimmedCurves[1]; var intersections = new List <IntPoint <CurveEvaluation, CurveEvaluation> >(curveA.IntersectCurve(curveB)); CurveEvaluation evalA = curveA.ProjectPoint(intersections[0].Point); CurveEvaluation evalB = curveB.ProjectPoint(intersections[0].Point); double angle = Math.Acos(Vector.Dot(evalA.Tangent.UnitVector, evalB.Tangent.UnitVector)); excelWorksheet.SetCell(row++, 1, angle * 180 / Math.PI); }
public static ICollection <Face> OffsetFaceEdgesInward(this Face face, double distance, OffsetCornerType offsetCornerType) { if (!(face.Geometry is Plane)) { throw new ArgumentException("Face must be planar"); } Plane plane = (Plane)face.Geometry; ITrimmedCurve[] curves = face.Edges.ToArray(); ITrimmedCurve firstEdge = curves.First(); ITrimmedCurve[] otherEdges = curves.Skip(1).ToArray(); ICollection <ITrimmedCurve> offsetCurves = firstEdge.OffsetChain(plane, distance, otherEdges, offsetCornerType); if (offsetCurves.Count == 0) { return(null); } if (face.ContainsPoint(offsetCurves.First().StartPoint) ^ distance > 0) { return(DoInWriteBlock <ICollection <Face> >(() => Body.CreatePlanarBody(plane, offsetCurves).SeparatePieces().Select(b => b.Faces.First()).ToList())); } offsetCurves = firstEdge.OffsetChain(plane, -distance, otherEdges, offsetCornerType); if (offsetCurves.Count == 0) { return(null); } return(Body.CreatePlanarBody(plane, offsetCurves).SeparatePieces().Select(b => b.Faces.First()).ToList()); }
protected override Body GetCappingBody() { Point startOuter = StartCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale); Point endOuter = EndCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale); Point startKnee = StartCone.WrapPoint(0, -(1 + BevelKneeRatio) * GearData.Module); Point endKnee = EndCone.WrapPoint(0, -(1 + BevelKneeRatio) * GearData.Module); Point startCenter = Axis.ProjectPoint(startKnee).Point; Point endCenter = Axis.ProjectPoint(endKnee).Point; IList <ITrimmedCurve> cappingProfile = new Point[] { startCenter, startKnee, startOuter, endOuter, endKnee, endCenter }.AsPolygon(); IList <ITrimmedCurve> revolvePath = new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(StartFrame, 1)) }; Body cappingBody = null; try { cappingBody = Body.SweepProfile(Plane.PlaneZX, cappingProfile, revolvePath); } catch { foreach (ITrimmedCurve curve in cappingProfile) { DesignCurve.Create(Part, curve); } } return(cappingBody); }
public static Body CreateCable(ITrimmedCurve iTrimmedCurve, double diameter) { double radius = diameter / 2; CurveEvaluation curveEvaluation = iTrimmedCurve.Geometry.Evaluate(iTrimmedCurve.Bounds.Start); Point startPoint = curveEvaluation.Point; Direction dirZ = curveEvaluation.Tangent; Direction dirX = dirZ.ArbitraryPerpendicular; Direction dirY = Direction.Cross(dirZ, dirX); Frame profileFrame = Frame.Create(startPoint, dirX, dirY); Circle profileCircle = Circle.Create(profileFrame, radius); IList<ITrimmedCurve> profile = new List<ITrimmedCurve>(); profile.Add(CurveSegment.Create(profileCircle)); IList<ITrimmedCurve> path = new List<ITrimmedCurve>(); path.Add(iTrimmedCurve); Body body = Body.SweepProfile(Plane.Create(profileFrame), profile, path); if (body == null) { Debug.Fail("Sweep failed."); return null; } return body; }
public static CurveSegment CreateHelixAroundCurve(this ITrimmedCurve curveSegment, double turns, double radius, double pointCount) { var points = new List <Point>(); Direction lastNormal = curveSegment.Geometry.Evaluate(curveSegment.Bounds.Start).Tangent.ArbitraryPerpendicular; for (int i = 0; i < pointCount; i++) { double ratio = (double)i / pointCount; double param = curveSegment.Bounds.Start + ratio * curveSegment.Bounds.Span; CurveEvaluation curveEval = curveSegment.Geometry.Evaluate(param); Direction normal = Direction.Cross(Direction.Cross(curveEval.Tangent, lastNormal), curveEval.Tangent); if (normal.IsZero) { normal = lastNormal; } Point point = curveEval.Point; Matrix rotation = Matrix.CreateRotation(Line.Create(point, curveEval.Tangent), 2 * Math.PI * turns * ratio); point += radius * normal; point = rotation * point; points.Add(point); lastNormal = normal; } return(CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, points, 0.000001))); }
public static Body CreateCable(ITrimmedCurve iTrimmedCurve, double diameter) { double radius = diameter / 2; CurveEvaluation curveEvaluation = iTrimmedCurve.Geometry.Evaluate(iTrimmedCurve.Bounds.Start); Point startPoint = curveEvaluation.Point; Direction dirZ = curveEvaluation.Tangent; Direction dirX = dirZ.ArbitraryPerpendicular; Direction dirY = Direction.Cross(dirZ, dirX); Frame profileFrame = Frame.Create(startPoint, dirX, dirY); Circle profileCircle = Circle.Create(profileFrame, radius); IList <ITrimmedCurve> profile = new List <ITrimmedCurve>(); profile.Add(CurveSegment.Create(profileCircle)); IList <ITrimmedCurve> path = new List <ITrimmedCurve>(); path.Add(iTrimmedCurve); Body body = Body.SweepProfile(Plane.Create(profileFrame), profile, path); if (body == null) { Debug.Fail("Sweep failed."); return(null); } return(body); }
protected override ITrimmedCurve GetTransformedProfileCurve(ITrimmedCurve iTrimmedCurve, double param) { Matrix trans = Matrix.CreateTranslation(Vector.Create(0, 0, -Depth * param + Depth / 2)) * Matrix.CreateRotation(Axis, HelixRotations * (param - 0.5)); return(iTrimmedCurve.CreateTransformedCopy(trans)); }
private static NurbsCurve GetFirstNurbsCurveFromPart(Part part) { List <DesignCurve> curves = new List <DesignCurve>(part.Curves); ITrimmedCurve testCurve = curves[0].Shape; Debug.Assert(testCurve.Geometry is NurbsCurve); return(testCurve.Geometry as NurbsCurve); }
public static ICollection <ITrimmedCurve> OffsetTowards(this ICollection <ITrimmedCurve> curves, Point point, Plane plane, double distance) { ITrimmedCurve firstCurve = curves.First(); ITrimmedCurve[] otherCurves = curves.Skip(1).ToArray(); bool isLeft = Vector.Dot(Vector.Cross(firstCurve.Geometry.Evaluate(0).Tangent.UnitVector, point - firstCurve.StartPoint), plane.Frame.DirZ.UnitVector) >= 0; return(firstCurve.OffsetChain(plane, (isLeft ? -1 : 1) * distance, otherCurves, OffsetCornerType.NaturalExtension)); }
public static DesignBody CreateCable(ITrimmedCurve iTrimmedCurve, double diameter, IPart part) { Body body = CreateCable(iTrimmedCurve, diameter); if (part == null) part = Window.ActiveWindow.ActiveContext.ActivePart; DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sweep", body); desBodyMaster.Transform(part.TransformToMaster); return desBodyMaster; }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { Part mainPart = Window.ActiveWindow.Scene as Part; Layer layer = NoteHelper.CreateOrGetLayer(mainPart.Document, "Convex Hull", Color.DarkTurquoise); foreach (Part part in mainPart.Components.Select(c => c.Content.Master).Where(p => p.Bodies.Count > 0)) { foreach (Body body in part.Bodies.Select(b => b.Shape)) { foreach (Face face in body.Faces) { foreach (Loop loop in face.Loops.Where(l => l.IsOuter)) { List <Point> points = new List <Point>(); foreach (Fin fin in loop.Fins) { bool wasPreviousLine = false; Line line = fin.Edge.Geometry as Line; if (line != null) { if (!wasPreviousLine) { points.Add(fin.TrueStartPoint()); } points.Add(fin.TrueEndPoint()); wasPreviousLine = true; } Circle circle = fin.Edge.Geometry as Circle; if (circle != null && fin.Edge.Bounds.Span < Math.PI) { continue; } ITrimmedCurve iTrimmedCurve = fin.Edge; double mid = (iTrimmedCurve.Bounds.Start + iTrimmedCurve.Bounds.End) / 2; points.Add(iTrimmedCurve.Geometry.Evaluate(mid).Point); } points.Add(points[0]); foreach (ITrimmedCurve iTrimmedCurve in points.CreatePolyline()) { DesignCurve desCurve = DesignCurve.Create(part, iTrimmedCurve); desCurve.Layer = layer; } } } } } }
public static DesignBody CreateCable(ITrimmedCurve iTrimmedCurve, double diameter, IPart part) { Body body = CreateCable(iTrimmedCurve, diameter); if (part == null) { part = Window.ActiveWindow.ActiveContext.ActivePart; } DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sweep", body); desBodyMaster.Transform(part.TransformToMaster); return(desBodyMaster); }
static void CreateShotNearPoint(Point point, double height, double radius) { Window activeWindow = Window.ActiveWindow; Line rayLine = Line.Create(point, activeWindow.Projection.Inverse * Direction.DirZ); ITrimmedCurve rayCurve = CurveSegment.Create(rayLine, Interval.Create(1000, -1000)); //DesignCurve.Create(activeWindow.Scene as Part, rayCurve); // draws the ray as a design object var intersectionList = new List <IntPoint <SurfaceEvaluation, CurveEvaluation> >(); foreach (IDesignBody designBody in (activeWindow.Scene as Part).Bodies) { foreach (IDesignFace designFace in designBody.Faces) { intersectionList.AddRange(designFace.Shape.IntersectCurve(rayCurve)); } } Point? closePoint = null; double closeParam = Double.MinValue; foreach (IntPoint <SurfaceEvaluation, CurveEvaluation> intersection in intersectionList) { if (intersection.EvaluationB.Param > closeParam) { closeParam = intersection.EvaluationB.Param; closePoint = intersection.Point; } } if (closePoint == null) { return; } DesignBody toolBody = ShapeHelper.CreateSphere(closePoint.Value, radius, activeWindow.Scene as Part); //TBD why doesn't this work on spacklePart? //Frame? frame = GetFrameFromPoint(designFace, point); //if (frame == null) // return; //Body body = CreateCylinder(point, frame.Value.DirX, frame.Value.DirY, radius, height); //DesignBody toolBody = AddInHelper.CreateSphere(frame.Value.Origin, radius, spacklePart); // TBD XXX Fix for v5 //if (spackleMode == SpackleMode.Add) // targetBody.Unite(new IDesignBody[] { toolBody }); //else if (spackleMode == SpackleMode.Cut) // targetBody.Subtract(new IDesignBody[] { toolBody }); }
public TrimmedCurveChain(ICollection <ITrimmedCurve> curveCollection) { Queue <ITrimmedCurve> curveQueue = new Queue <ITrimmedCurve>(curveCollection); orientedCurves.Add(new OrientedTrimmedCurve(curveQueue.Dequeue(), false)); ITrimmedCurve trimmedCurve = null; int failCount = curveQueue.Count; while (curveQueue.Count > 0) { trimmedCurve = curveQueue.Dequeue(); if (trimmedCurve.StartPoint == orientedCurves[orientedCurves.Count - 1].EndPoint) { orientedCurves.Add(new OrientedTrimmedCurve(trimmedCurve, false)); failCount = curveQueue.Count; continue; } if (trimmedCurve.EndPoint == orientedCurves[orientedCurves.Count - 1].EndPoint) { orientedCurves.Add(new OrientedTrimmedCurve(trimmedCurve, true)); failCount = curveQueue.Count; continue; } if (trimmedCurve.StartPoint == orientedCurves[0].StartPoint) { orientedCurves.Insert(0, new OrientedTrimmedCurve(trimmedCurve, true)); failCount = curveQueue.Count; continue; } if (trimmedCurve.EndPoint == orientedCurves[0].StartPoint) { orientedCurves.Insert(0, new OrientedTrimmedCurve(trimmedCurve, false)); failCount = curveQueue.Count; continue; } curveQueue.Enqueue(trimmedCurve); if (failCount-- < 0) { Application.ReportStatus("Can't seem to sort curves.", StatusMessageType.Warning, null); break; } } }
protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { base.OnExecute(command, context, buttonRect); List <ITrimmedCurve> iTrimmedCurves = new List <ITrimmedCurve>(activeWindow.GetAllSelectedITrimmedCurves()); List <ITrimmedCurve> uniqueCurves = new List <ITrimmedCurve>(); uniqueCurves.Add(iTrimmedCurves[0]); iTrimmedCurves.RemoveAt(0); foreach (ITrimmedCurve candidate in iTrimmedCurves) { ITrimmedCurve notUnique = null; foreach (ITrimmedCurve uniqueCurve in uniqueCurves) { if (candidate.IsCoincident(uniqueCurve)) { notUnique = uniqueCurve; } } if (notUnique != null) { uniqueCurves.Remove(notUnique); continue; } uniqueCurves.Add(candidate); } // Old crappy way //Dictionary<ITrimmedCurve, bool> uniqueCurves = new Dictionary<ITrimmedCurve, bool>(new ITrimmedCurveComparer()); //foreach (ITrimmedCurve iTrimmedCurve in iTrimmedCurves) { // if (!uniqueCurves.ContainsKey(iTrimmedCurve)) // uniqueCurves.Add(iTrimmedCurve, false); // else // uniqueCurves[iTrimmedCurve] = !uniqueCurves[iTrimmedCurve]; //} //foreach (ITrimmedCurve iTrimmedCurve in uniqueCurves.Keys) { foreach (ITrimmedCurve iTrimmedCurve in uniqueCurves) { DesignCurve.Create(part, iTrimmedCurve); } }
public static Body CreateRevolvedCurve(Line axis, ITrimmedCurve curve) { Point point = curve.Geometry.Evaluate(curve.Bounds.Middle()).Point; Debug.Assert(Accuracy.LengthIsPositive((axis.ProjectPoint(point).Point - point).Magnitude)); Plane plane = null; bool success = AddInHelper.TryCreatePlaneFromPoints(new Point[] { axis.Origin, axis.Evaluate(1).Point, point }, out plane); Debug.Assert(success, "Could not create plane through points."); Point axisStart = axis.ProjectPoint(curve.StartPoint).Point; Point axisEnd = axis.ProjectPoint(curve.EndPoint).Point; var profile = new List <ITrimmedCurve>(); profile.Add(curve); if (axisStart != curve.StartPoint) { profile.Add(CurveSegment.Create(axisStart, curve.StartPoint)); } if (axisEnd != curve.EndPoint) { profile.Add(CurveSegment.Create(axisEnd, curve.EndPoint)); } profile.Add(CurveSegment.Create(axisStart, axisEnd)); try { Body body = Body.SweepProfile(Plane.PlaneZX, profile, new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(Frame.World, 1)) }); body.DeleteFaces(body.Faces.Where(f => f.Geometry is Plane).ToArray(), RepairAction.None); return(body); } catch { return(null); } }
private static IList <ITrimmedCurve> CreatePolyline(params Point[] points) { Debug.Assert(points != null); var nSegments = points.Length - 1; Debug.Assert(nSegments > 0); var segments = new ITrimmedCurve[nSegments]; for (var i = 0; i < nSegments; i++) { segments[i] = CurveSegment.Create(points[i], points[i + 1]); } return(segments); }
public static bool AreEndPointsOnFace(this ITrimmedCurve iTrimmedCurve, Face face) { if ((iTrimmedCurve.GetBoundingBox(Matrix.Identity) & face.GetBoundingBox(Matrix.Identity)).IsEmpty) { return(false); } if (iTrimmedCurve.StartPoint != face.ProjectPoint(iTrimmedCurve.StartPoint).Point) { return(false); } if (iTrimmedCurve.EndPoint != face.ProjectPoint(iTrimmedCurve.EndPoint).Point) { return(false); } return(true); }
public void AddCurve(ITrimmedCurve iTrimmedCurve) { if (iTrimmedCurve.Geometry is Line) { dxfCurves.Add(new DxfLine(iTrimmedCurve, textWriter)); return; } if (iTrimmedCurve.Geometry is Circle) { if (iTrimmedCurve.Bounds.Span == 2 * Math.PI) dxfCurves.Add(new DxfCircle(iTrimmedCurve, textWriter)); else dxfCurves.Add(new DxfArc(iTrimmedCurve, textWriter)); return; } IList<Point> points = iTrimmedCurve.Geometry.GetPolyline(iTrimmedCurve.Bounds); for (int i = 0; i < points.Count - 1; i++) dxfCurves.Add(new DxfLine(CurveSegment.Create(points[i], points[i + 1]), textWriter)); }
public static Body CreateCircularTab(Point p0, Point p1, Direction normal, double angle, bool isMale) { Circle circle = GetCircularTabCircle(p0, p1, normal, angle, isMale); double centerParam = Math.PI / 2; if (!isMale) { angle *= -1; centerParam += Math.PI; } ITrimmedCurve circleSegment = CurveSegment.Create(circle, Interval.Create(centerParam - angle / 2, centerParam + angle / 2)); ITrimmedCurve lineSegment = CurveSegment.Create(p0, p1); //DesignCurve.Create(Window.ActiveWindow.Scene as Part, circleSegment); //DesignCurve.Create(Window.ActiveWindow.Scene as Part, lineSegment); return(Body.CreatePlanarBody(Plane.Create(circle.Frame), new ITrimmedCurve[] { circleSegment, lineSegment })); }
public static IList <Point> TessellateCurve(this ITrimmedCurve curve, double spacing) { double length = curve.Length; int count = (int)Math.Ceiling(length / spacing); double param = Math.Min(curve.Bounds.Start, curve.Bounds.End); double endParam = Math.Max(curve.Bounds.Start, curve.Bounds.End); length = endParam - param; List <Point> points = new List <Point>(); for (int i = 0; i < count; i++) { points.Add(curve.Geometry.Evaluate(param + (double)i * length / count).Point); } points.Add(curve.Geometry.Evaluate(endParam).Point); return(points); }
public static ICollection <ITrimmedCurve> OffsetChainInward(this ICollection <ITrimmedCurve> curves, Plane plane, double distance, OffsetCornerType offsetCornerType) { ITrimmedCurve firstEdge = curves.First(); ITrimmedCurve[] otherEdges = curves.Skip(1).ToArray(); ICollection <ITrimmedCurve> offsetCurvesA = firstEdge.OffsetChain(plane, distance, otherEdges, offsetCornerType); ICollection <ITrimmedCurve> offsetCurvesB = firstEdge.OffsetChain(plane, -distance, otherEdges, offsetCornerType); if (offsetCurvesA.Count == 0 || offsetCurvesB.Count == 0) { return(new ITrimmedCurve[0]); } if (offsetCurvesA.Select(c => c.Length).Sum() < offsetCurvesB.Select(c => c.Length).Sum()) { return(offsetCurvesA); } else { return(offsetCurvesB); } }
public override void WriteXml(Matrix documentTrans) { Debug.Assert(this.ellipse != null); ITrimmedCurve iTrimmedEllipse = CurveSegment.Create(this.ellipse).ProjectToPlane(Plane.PlaneXY); Ellipse ellipse = iTrimmedEllipse.Geometry as Ellipse; Debug.Assert(ellipse != null); double x = Vector.Dot(ellipse.Frame.DirX.UnitVector, Direction.DirX.UnitVector); double y = Vector.Dot(ellipse.Frame.DirX.UnitVector, Direction.DirY.UnitVector); xmlWriter.WriteStartElement("ellipse"); xmlWriter.WriteAttributeString("transform", string.Format("translate({0} {1}) rotate({2})", documentTrans.Scale * ellipse.Frame.Origin.X + documentTrans.Translation.X, documentTrans.Scale * ellipse.Frame.Origin.Y + documentTrans.Translation.Y, Math.Atan2(y, x) * 180 / Math.PI )); xmlWriter.WriteAttributeString("rx", (documentTrans.Scale * ellipse.MajorRadius).ToString()); xmlWriter.WriteAttributeString("ry", (documentTrans.Scale * ellipse.MinorRadius).ToString()); StyleAttributes(strokeColor, fillColor, strokeWidth); xmlWriter.WriteEndElement(); }
protected override ITrimmedCurve GetTransformedProfileCurve(ITrimmedCurve iTrimmedCurve, double param) { int numPoints = 10000; Matrix trans = Matrix.CreateRotation(Axis, HelixRotations * param); Point[] points = new Point[numPoints + 1]; Frame profileFrame = Frame.Create(StartPoint + (EndPoint - StartPoint) * param, StartFrame.DirX, StartFrame.DirY); Cone profileCone = Cone.Create(profileFrame, (StartDiameter + (EndDiameter - StartDiameter) * param) / 2, Math.PI / 2 - Alpha); for (int j = 0; j <= numPoints; j++) { double t = iTrimmedCurve.Bounds.Start + iTrimmedCurve.Bounds.Span * (double)j / numPoints; Vector pointVector = iTrimmedCurve.Geometry.Evaluate(t).Point.Vector; double angle = Circle.Create(Frame.Create(Point.Origin, Direction.DirX, -Direction.DirY), GearData.PitchRadius).ProjectPoint(pointVector.GetPoint()).Param; double startDistance = pointVector.Magnitude - StartDiameter / 2; double endDistance = pointVector.Magnitude * EndScale - EndDiameter / 2; double distance = startDistance + (endDistance - startDistance) * param; points[j] = profileCone.WrapPoint(angle, distance); } return(CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, points, Accuracy.LinearResolution)).CreateTransformedCopy(trans)); }
protected override ITrimmedCurve GetTransformedProfileCurve(ITrimmedCurve iTrimmedCurve, double param) { int numPoints = 10000; Point[] points = new Point[numPoints + 1]; double paramZ = StartZ + (EndZ - StartZ) * param; Frame profileFrame = Frame.Create(StartPoint + (EndPoint - StartPoint) * param, StartFrame.DirX, StartFrame.DirY); Cone profileCone = GetConeAtParameter(paramZ); double radius = profileCone.Radius; ICollection <IntPoint <SurfaceEvaluation, CurveEvaluation> > intersections = profileCone.IntersectCurve(TangentLine); Matrix trans = Matrix.CreateRotation(Axis, intersections.OrderBy(i => Math.Abs(i.Point.Z)).First().EvaluationA.Param.U); // profileCone.Print(Part); // double scale = (radius / A) / Math.Sin(profileCone.HalfAngle); for (int j = 0; j <= numPoints; j++) { double t = iTrimmedCurve.Bounds.Start + iTrimmedCurve.Bounds.Span * (double)j / numPoints; Vector pointVector = iTrimmedCurve.Geometry.Evaluate(t).Point.Vector; double angle = -Circle.Create(Frame.Create(Point.Origin, Direction.DirX, Direction.DirY), GearData.PitchRadius).ProjectPoint(pointVector.GetPoint()).Param; double distance = (pointVector.Magnitude - A) * radius / A; // *Math.Sin(profileCone.HalfAngle); // points[j] = profileCone.WrapPoint(angle, (distance - A) / Math.Sin(profileCone.HalfAngle)); points[j] = profileCone.WrapPoint(angle, distance); } try { return(CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, points, Accuracy.LinearResolution)).CreateTransformedCopy(trans)); } catch { points.Print(); } return(null); }
protected override Body GetCappingBody() { Point startOuter = StartCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale); Point endOuter = EndCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale); Point startKnee = StartCone.WrapPoint(0, -(1 + BevelKneeRatio) * GearData.Module); Point endKnee = EndCone.WrapPoint(0, -(1 + BevelKneeRatio) * GearData.Module); Point startCenter = Axis.ProjectPoint(startKnee).Point; Point endCenter = Axis.ProjectPoint(endKnee).Point; IList<ITrimmedCurve> cappingProfile = new Point[] { startCenter, startKnee, startOuter, endOuter, endKnee, endCenter }.AsPolygon(); IList<ITrimmedCurve> revolvePath = new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(StartFrame, 1)) }; Body cappingBody = null; try { cappingBody = Body.SweepProfile(Plane.PlaneZX, cappingProfile, revolvePath); } catch { foreach (ITrimmedCurve curve in cappingProfile) DesignCurve.Create(Part, curve); } return cappingBody; }
protected override ITrimmedCurve GetTransformedProfileCurve(ITrimmedCurve iTrimmedCurve, double param) { Matrix trans = Matrix.CreateTranslation(Vector.Create(0, 0, -Depth * param + Depth / 2)) * Matrix.CreateRotation(Axis, HelixRotations * (param - 0.5)); return iTrimmedCurve.CreateTransformedCopy(trans); }
public static void Print(this ITrimmedCurve curve, Part part = null) { DesignCurve.Create(part ?? MainPart, curve); }
public DxfLine(ITrimmedCurve iTrimmedCurve, TextWriter textWriter) : base(iTrimmedCurve, textWriter) { }
public DxfCurve(ITrimmedCurve iTrimmedCurve, TextWriter textWriter) { this.iTrimmedCurve = iTrimmedCurve; this.textWriter = textWriter; }
public DxfCircle(ITrimmedCurve iTrimmedCurve, TextWriter textWriter) : base(iTrimmedCurve, textWriter) { circle = iTrimmedCurve.Geometry as Circle; Debug.Assert(circle != null); }
protected override ITrimmedCurve GetTransformedProfileCurve(ITrimmedCurve iTrimmedCurve, double param) { int numPoints = 10000; Matrix trans = Matrix.CreateRotation(Axis, HelixRotations * param); Point[] points = new Point[numPoints + 1]; Frame profileFrame = Frame.Create(StartPoint + (EndPoint - StartPoint) * param, StartFrame.DirX, StartFrame.DirY); Cone profileCone = Cone.Create(profileFrame, (StartDiameter + (EndDiameter - StartDiameter) * param) / 2, Math.PI / 2 - Alpha); for (int j = 0; j <= numPoints; j++) { double t = iTrimmedCurve.Bounds.Start + iTrimmedCurve.Bounds.Span * (double) j / numPoints; Vector pointVector = iTrimmedCurve.Geometry.Evaluate(t).Point.Vector; double angle = Circle.Create(Frame.Create(Point.Origin, Direction.DirX, -Direction.DirY), GearData.PitchRadius).ProjectPoint(pointVector.GetPoint()).Param; double startDistance = pointVector.Magnitude - StartDiameter / 2; double endDistance = pointVector.Magnitude * EndScale - EndDiameter / 2; double distance = startDistance + (endDistance - startDistance) * param; points[j] = profileCone.WrapPoint(angle, distance); } return CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, points, Accuracy.LinearResolution)).CreateTransformedCopy(trans); }
public static Body CreateRevolvedCurve(Line axis, ITrimmedCurve curve) { Point point = curve.Geometry.Evaluate(curve.Bounds.Middle()).Point; Debug.Assert(Accuracy.LengthIsPositive((axis.ProjectPoint(point).Point - point).Magnitude)); Plane plane = null; bool success = AddInHelper.TryCreatePlaneFromPoints(new Point[]{ axis.Origin, axis.Evaluate(1).Point, point }, out plane); Debug.Assert(success, "Could not create plane through points."); Point axisStart = axis.ProjectPoint(curve.StartPoint).Point; Point axisEnd = axis.ProjectPoint(curve.EndPoint).Point; var profile = new List<ITrimmedCurve>(); profile.Add(curve); if (axisStart != curve.StartPoint) profile.Add(CurveSegment.Create(axisStart, curve.StartPoint)); if (axisEnd != curve.EndPoint) profile.Add(CurveSegment.Create(axisEnd, curve.EndPoint)); profile.Add(CurveSegment.Create(axisStart, axisEnd)); try { Body body = Body.SweepProfile(Plane.PlaneZX, profile, new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(Frame.World, 1)) }); body.DeleteFaces(body.Faces.Where(f => f.Geometry is Plane).ToArray(), RepairAction.None); return body; } catch { return null; } }
protected abstract ITrimmedCurve GetTransformedProfileCurve(ITrimmedCurve iTrimmedCurve, double param);
protected override Body GetCappingBody() { Point startOuter = StartCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale); Point endOuter = EndCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale); Point startKnee = StartCone.WrapPoint(0, -(1 + HypoidKneeRatio) * GearData.Module * StartCone.Radius / A); Point endKnee = EndCone.WrapPoint(0, -(1 + HypoidKneeRatio) * GearData.Module * EndCone.Radius / A); Point startCenter = Axis.ProjectPoint(startKnee).Point; Point endCenter = Axis.ProjectPoint(endKnee).Point; CurveSegment startLine = CurveSegment.Create(startKnee, startOuter); CurveSegment endLine = CurveSegment.Create(endKnee, endOuter); ICollection<IntPoint<CurveEvaluation, CurveEvaluation>> intersections = startLine.IntersectCurve(endLine); IList<ITrimmedCurve> cappingProfile; if (intersections.Count > 0) { Point middlePoint = intersections.First().Point; cappingProfile = new Point[] { startCenter, startKnee, middlePoint, endKnee, endCenter }.AsPolygon(); } else cappingProfile = new Point[] { startCenter, startKnee, startOuter, endOuter, endKnee, endCenter }.AsPolygon(); IList<ITrimmedCurve> revolvePath = new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(StartFrame, 1)) }; Body cappingBody = null; try { cappingBody = Body.SweepProfile(Plane.PlaneZX, cappingProfile, revolvePath); } catch { foreach (ITrimmedCurve curve in cappingProfile) DesignCurve.Create(Part, curve); } return cappingBody; }
protected override ITrimmedCurve GetTransformedProfileCurve(ITrimmedCurve iTrimmedCurve, double param) { int numPoints = 10000; Point[] points = new Point[numPoints + 1]; double paramZ = StartZ + (EndZ - StartZ) * param; Frame profileFrame = Frame.Create(StartPoint + (EndPoint - StartPoint) * param, StartFrame.DirX, StartFrame.DirY); Cone profileCone = GetConeAtParameter(paramZ); double radius = profileCone.Radius; ICollection<IntPoint<SurfaceEvaluation, CurveEvaluation>> intersections = profileCone.IntersectCurve(TangentLine); Matrix trans = Matrix.CreateRotation(Axis, intersections.OrderBy(i => Math.Abs(i.Point.Z)).First().EvaluationA.Param.U); // profileCone.Print(Part); // double scale = (radius / A) / Math.Sin(profileCone.HalfAngle); for (int j = 0; j <= numPoints; j++) { double t = iTrimmedCurve.Bounds.Start + iTrimmedCurve.Bounds.Span * (double) j / numPoints; Vector pointVector = iTrimmedCurve.Geometry.Evaluate(t).Point.Vector; double angle = -Circle.Create(Frame.Create(Point.Origin, Direction.DirX, Direction.DirY), GearData.PitchRadius).ProjectPoint(pointVector.GetPoint()).Param; double distance = (pointVector.Magnitude - A) * radius / A;// *Math.Sin(profileCone.HalfAngle); // points[j] = profileCone.WrapPoint(angle, (distance - A) / Math.Sin(profileCone.HalfAngle)); points[j] = profileCone.WrapPoint(angle, distance); } try { return CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, points, Accuracy.LinearResolution)).CreateTransformedCopy(trans); } catch { points.Print(); } return null; }
public static void CreateDashes(ITrimmedCurve curve, Part part, double dashMinSize, Layer dashLayer) { double length = curve.Length; int count = (int) Math.Floor(length / dashMinSize / 2) * 2; if (curve.StartPoint != curve.EndPoint) // odd number when not closed curve count++; double lastParam = curve.Bounds.Start; double param; for (int i = 0; i < count; i++) { if (curve.Geometry.TryOffsetParam(lastParam, length / count, out param)) { if (i % 2 == 1) { DesignCurve dash = DesignCurve.Create(part, CurveSegment.Create(curve.Geometry, Interval.Create(lastParam, param))); dash.Layer = dashLayer; } lastParam = param; } } }