Download examples/gear.py from HelloSun/WFreeCAD: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/spaces/HelloSun/WFreeCAD/resolve/main/examples/gear.py
- Command line
-
hf download hf://spaces/HelloSun/WFreeCAD/examples/gear.py
-
curl -L -o gear.py https://huggingface.co/spaces/HelloSun/WFreeCAD/resolve/main/examples/gear.py
1.7 kB
| import math | |
| import FreeCAD as App | |
| import Part | |
| # A chunky spur gear, built from a closed 2D profile and extruded. | |
| teeth = 18 | |
| module = 2.2 | |
| thickness = 6.0 | |
| pitch_r = module * teeth / 2.0 | |
| tip_r = pitch_r + module * 0.9 | |
| root_r = pitch_r - module * 1.1 | |
| step = 2.0 * math.pi / teeth | |
| points = [] | |
| for i in range(teeth): | |
| a = i * step | |
| for frac, radius in ( | |
| (-0.46, root_r), | |
| (-0.40, root_r), | |
| (-0.35, root_r + (tip_r - root_r) * 0.30), | |
| (-0.28, root_r + (tip_r - root_r) * 0.82), | |
| (-0.20, tip_r), | |
| (0.20, tip_r), | |
| (0.28, root_r + (tip_r - root_r) * 0.82), | |
| (0.35, root_r + (tip_r - root_r) * 0.30), | |
| (0.40, root_r), | |
| (0.46, root_r), | |
| ): | |
| angle = a + frac * step | |
| points.append( | |
| App.Vector(math.cos(angle) * radius, math.sin(angle) * radius, 0) | |
| ) | |
| points.append(points[0]) | |
| profile = Part.Face(Part.makePolygon(points, True)) | |
| gear = profile.extrude(App.Vector(0, 0, thickness)) | |
| # Centre bore. | |
| gear = gear.cut( | |
| Part.makeCylinder(4.5, thickness + 2.0, App.Vector(0, 0, -1.0)) | |
| ) | |
| # Five lightening holes. | |
| for i in range(5): | |
| angle = 2.0 * math.pi * i / 5.0 + math.pi / 10.0 | |
| centre = App.Vector( | |
| math.cos(angle) * pitch_r * 0.62, | |
| math.sin(angle) * pitch_r * 0.62, | |
| -1.0, | |
| ) | |
| gear = gear.cut(Part.makeCylinder(2.8, thickness + 2.0, centre)) | |
| plate = Part.show(gear, "GearPlate") | |
| plate.ViewObject.ShapeColor = (0.94, 0.68, 0.32) | |
| hub = Part.makeCylinder(6.8, thickness + 3.0, App.Vector(0, 0, -1.5)) | |
| hub = hub.cut(Part.makeCylinder(4.15, thickness + 5.0, App.Vector(0, 0, -2.5))) | |
| hub_obj = Part.show(hub, "Hub") | |
| hub_obj.ViewObject.ShapeColor = (0.27, 0.38, 0.35) | |