Skip to content

Commit de5a349

Browse files
Jojainmarcus7070
andauthored
Gear generator classes (#19)
* Create gear_generator.py * Add bevel gear * Update gear_generator.py * add crown gear * Create rack_gear.py * add docstring, improve organisation * changed imports * add readme and setup files * moved to module dir structure Implemented the same changes as @marcus7070 did for the more_selectors plugin * update functions calls * testing import solutions * made plugin functions work * setup test functions * Update .gitignore * add working tests * add auto link of methods in __init__ * change function names * Update cutter_objects.py * add register fct to modules * add imgs for readme * finalize PR version * Update README.md * Update test_gear_generator.py * Rewrote the plugin in OOP I rewrote the plugin using OOP. For now there is only bevel gear and spur gear, I removed all the other ones cause they werent mature enough * correction of error in rotation angle change twist angle from radians to degrees * Update test_gear_generator.py modified tests to handle the update in twistangle * Update test_gear_generator.py modify precision due to difference with ubuntu 18.04 Trying hacky stuff and triggering the test * Revert "Trying hacky stuff" This reverts commit a37287b. --------- Co-authored-by: Marcus Boyd <[email protected]>
1 parent d263aa9 commit de5a349

File tree

11 files changed

+606
-0
lines changed

11 files changed

+606
-0
lines changed

plugins/gear_generator/README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Gear generator
2+
3+
This plugin provide classes to create various gears.
4+
As for now you can create these gears (all the gears are involutes):
5+
* Spur gear
6+
7+
<img src="images/straight_gear.PNG" width="600"/>
8+
9+
* Helical gear
10+
11+
<img src="images/helical_gear.PNG" width="600"/>
12+
13+
* Bevel gear (straight and helical)
14+
15+
<img src="images/bevel_gear.PNG" width="600"/>
16+
17+
* Bevel gear system (straight and helical)
18+
19+
<img src="images/bevel_gear_system.PNG" width="600"/>
20+
21+
22+
## Installation
23+
24+
To install this plugin, the following line should be used.
25+
26+
```
27+
pip install -e "git+https://github.com/CadQuery/cadquery-plugins.git#egg=gear_generator&subdirectory=plugins/gear_generator"
28+
```
29+
30+
31+
## Dependencies
32+
33+
This plugin has no dependencies other than the cadquery library.
34+
35+
## Usage
36+
37+
To use this plugin after it has been installed, import it and create Gear objects
38+
```python
39+
import cadquery as cq
40+
import gear_generator
41+
42+
module = 2
43+
nb_teeth = 12
44+
width = 8
45+
gear = Gear(module, nb_teeth, width).build() #Instantiate a gear object and call it's build method to get the gear in a cq.Workplane
46+
```
47+
<img src="images/readme_example.PNG" width="300"/>
48+
49+
Below is the list of implemented gear classes :
50+
```python
51+
Gear(args)
52+
BevelGear(args)
53+
BevelGearSystem(args)
54+
55+
#You can get info about the parameters by running
56+
help(BevelGear)
57+
58+
Help on class Gear in module gear_generator.main:
59+
60+
class Gear(BaseGear)
61+
| Gear(m: float, z: int, b: float, alpha: float = 20, helix_angle: float = 0, raw: bool = False)
62+
|
63+
| Base gear class
64+
| This class stores attributes that are shared by any types of gear
65+
| Other gear classes inherit from this class
66+
|
67+
| Attributes :
68+
| m : gear modulus
69+
| b : gear tooth facewidth
70+
| z : gear number of teeth
71+
| p : gear pitch
72+
-- Suite --
73+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .main import *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from math import cos, sin, radians, acos
2+
import cadquery as cq
3+
4+
def involute(r: float, sign: int = 1):
5+
"""
6+
Defines an involute curve to create the flanks of the involute gears
7+
8+
Args:
9+
r : Radius of the involute (for a gear it's the pitch radius)
10+
sign : 1 or -1 , to draw the involute in positive or negative direction
11+
12+
Returns:
13+
x,y -> tuple() : 2-tuple of x and y coordinates in space
14+
"""
15+
def curve(t):
16+
x = r*(cos(t) + t*sin(t))
17+
y = r*(sin(t) - t*cos(t))
18+
return x,sign*y
19+
return curve
20+
21+
def spherical_involute(delta, delta_b, R):
22+
"""
23+
Equation of the spherical involute that lies on a sphere
24+
25+
Args:
26+
delta : the function variable, goes from the gear root cone angle to the gear tip cone angle
27+
delta_b : angle of the base cone
28+
R : radius of the associated sphere
29+
30+
Returns:
31+
x,y,z -> tuple() : 3-tuple of x and y and z coordinates in space
32+
"""
33+
theta = acos(cos(delta)/cos(delta_b))/sin(delta_b)
34+
x = R*cos(theta*sin(delta_b))*sin(delta_b)*cos(theta) - R*sin(theta*sin(delta_b))* - sin(theta)
35+
y = R*cos(theta*sin(delta_b))*sin(delta_b)*sin(theta) - R*sin(theta*sin(delta_b))* cos(theta)
36+
z = R*cos(theta*sin(delta_b))*cos(delta_b)
37+
return x,y,z
38+
39+
40+
41+
def rotate_vector_2D(vector: cq.Vector, angle: float):
42+
"""
43+
Rotates a 2D cq.Vector `vector`by an angle of `angle` in degrees
44+
"""
45+
angle = radians(angle)
46+
x = cos(angle)*vector.x - sin(angle)*vector.y
47+
y = sin(angle)*vector.x + cos(angle)*vector.y
48+
return cq.Vector((x,y))

0 commit comments

Comments
 (0)