// Arc // Rh Capture can be a circle OR an arc public Base ArcToSpeckle(ArcCurve a, string units = null) { var u = units ?? ModelUnits; if (a.IsClosed) { RH.Circle preCircle; a.TryGetCircle(out preCircle); Circle myCircle = CircleToSpeckle(preCircle, u); myCircle.domain = IntervalToSpeckle(a.Domain); myCircle.length = a.GetLength(); myCircle.bbox = BoxToSpeckle(new RH.Box(a.GetBoundingBox(true)), u); return(myCircle); } else { RH.Arc preArc; a.TryGetArc(out preArc); Arc myArc = ArcToSpeckle(preArc, u); myArc.domain = IntervalToSpeckle(a.Domain); myArc.length = a.GetLength(); myArc.bbox = BoxToSpeckle(new RH.Box(a.GetBoundingBox(true)), u); return(myArc); } }
public List <Curve> buildGear(List <Circle> C, double Teeth, double Angle, double profileShift, double addendum, double dedendum, out List <int> teethNumber) { List <Curve> curves = new List <Curve>(); ArcCurve sC = new ArcCurve(C[0]); if (C.Count > 1) { sC = smallestCircle(C); } double m = (2 * sC.Radius) / Teeth; addendum = addendum * m; dedendum = dedendum * m; teethNumber = new List <int>(); for (int i = 0; i < C.Count; i++) { List <Curve> profiles = new List <Curve>(); Circle baseCir = new Circle(C[i].Plane, C[i].Radius * Math.Cos(toRadian(Angle))); Circle addCir = new Circle(C[i].Plane, C[i].Radius + addendum); Circle dedCir = new Circle(C[i].Plane, C[i].Radius - dedendum); Curve profile = involute(baseCir, Angle, addCir, dedCir); int teethCount = (int)(Teeth * (C[i].Radius / sC.Radius)); // teeth number teethNumber.Add(teethCount); //mirror profile Vector3d newX = C[i].Plane.XAxis; //the thickness of gear, should be halt of pitch angle if (profileShift != 0) { newX.Rotate((Math.PI + profileShift * Math.PI * Math.Tan(Angle)) / (double)teethCount, C[i].Normal); //circular pitch } else { newX.Rotate(Math.PI / teethCount, C[i].Normal); } Curve mirProfile = profile.DuplicateCurve(); Transform mirror = Transform.Mirror(new Plane(C[i].Center, newX + C[i].Plane.XAxis, C[i].Normal)); mirProfile.Transform(mirror); //align the profile var ccx = Rhino.Geometry.Intersect.Intersection.CurveCurve(profile, new ArcCurve(C[i]), 1, 1); Transform aligned = Transform.Rotation(ccx[0].PointA - C[i].Center, C[i].Plane.XAxis, C[i].Center); profile.Transform(aligned); mirProfile.Transform(aligned); //tip and buttom arc double addAngle = Vector3d.VectorAngle(profile.PointAtEnd - C[i].Center, mirProfile.PointAtEnd - C[i].Center); double dedAngle = (1.0 / (double)teethCount) * Math.PI * 2 - Vector3d.VectorAngle(profile.PointAtStart - C[i].Center, mirProfile.PointAtStart - C[i].Center); Plane addPln = new Plane(C[i].Center, profile.PointAtEnd - C[i].Center, C[i].Plane.YAxis); Plane dedPln = new Plane(C[i].Center, mirProfile.PointAtStart - C[i].Center, C[i].Plane.YAxis); ArcCurve tip = new ArcCurve(new Arc(addPln, C[i].Radius + addendum, addAngle)); ArcCurve buttom = new ArcCurve(new Arc(dedPln, C[i].Radius - dedendum, dedAngle)); //display locations.Add(tip.PointAtNormalizedLength(0.5)); //tip texts.Add(Math.Round(tip.GetLength(), 2).ToString()); sizes.Add((addendum + dedendum) * 4); locations.Add(profile.PointAtStart); //profile texts.Add(Math.Round(profile.GetLength(), 2).ToString()); sizes.Add((addendum + dedendum) * 4); //teeth mirProfile.Reverse(); List <Curve> CS = new List <Curve> { profile, tip, mirProfile, buttom }; Curve teethC = Curve.JoinCurves(CS, 0.1, true)[0]; for (int j = 0; j < teethCount; j++) { Curve presentProfile = teethC.DuplicateCurve(); double step = ((double)j / (double)teethCount) * Math.PI * 2; Transform rotate = Transform.Rotation(step, C[i].Normal, C[i].Center); presentProfile.Transform(rotate); profiles.Add(presentProfile); } curves.Add(Curve.JoinCurves(profiles, 0.01, true)[0]); } return(curves); }