Skip to content

Commit

Permalink
refactoring:
Browse files Browse the repository at this point in the history
make rotation matrix rotating from x -> y (changing the sign of the rotation)
not sure why it was defined the other way ???
  • Loading branch information
looooo committed Jan 2, 2024
1 parent fd73f5e commit 323c922
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 23 deletions.
6 changes: 3 additions & 3 deletions freecad/gears/bevelgear.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def generate_gear_shape(self, fp):
fp.gear.clearance = fp.clearance / scale
fp.gear._update()
pts = list(fp.gear.points(num=fp.numpoints))
rot = rotation3D(2 * np.pi / fp.teeth)
rot = rotation3D(- 2 * np.pi / fp.teeth)
# if fp.beta.Value != 0:
# pts = [np.array([self.spherical_rot(j, fp.beta.Value * np.pi / 180.) for j in i]) for i in pts]

Expand All @@ -142,7 +142,7 @@ def generate_gear_shape(self, fp):
else:
for scale_i in np.linspace(scale_0, scale_1, 20):
# beta_i = (scale_i - scale_0) * fp.beta.Value * np.pi / 180
# rot = rotation3D(beta_i)
# rot = rotation3D(- beta_i)
# points = [rot(pt) * scale_i for pt in pts]
angle = (
fp.beta.Value
Expand Down Expand Up @@ -203,4 +203,4 @@ def scale(x):

def spherical_rot(self, point, phi):
new_phi = np.sqrt(np.linalg.norm(point)) * phi
return rotation3D(new_phi)(point)
return rotation3D(- new_phi)(point)
2 changes: 1 addition & 1 deletion freecad/gears/cycloidgear.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def generate_gear_shape(self, fp):
fp.gear._update()

pts = fp.gear.points(num=fp.numpoints)
rot = rotation(-fp.gear.phipart)
rot = rotation(fp.gear.phipart)
rotated_pts = list(map(rot, pts))
pts.append([pts[-1][-1], rotated_pts[0][0]])
pts += rotated_pts
Expand Down
2 changes: 1 addition & 1 deletion freecad/gears/internalinvolutegear.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def generate_gear_shape(self, fp):
if not fp.simple:
# head-fillet:
pts = fp.gear.points(num=fp.numpoints)
rot = rotation(-fp.gear.phipart)
rot = rotation(fp.gear.phipart)
rotated_pts = list(map(rot, pts))
pts.append([pts[-1][-1], rotated_pts[0][0]])
pts += rotated_pts
Expand Down
2 changes: 1 addition & 1 deletion freecad/gears/involutegear.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def generate_gear_shape(self, obj):

if not obj.simple:
pts = obj.gear.points(num=obj.numpoints)
rot = rotation(-obj.gear.phipart)
rot = rotation(obj.gear.phipart)
rotated_pts = list(map(rot, pts))
pts.append([pts[-1][-1], rotated_pts[0][0]])
pts += rotated_pts
Expand Down
2 changes: 1 addition & 1 deletion freecad/gears/lanterngear.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def find_phi_min(phi_min):
app.Vector(*p_1, 0.0), app.Vector(*p_12, 0.0), app.Vector(*p_2, 0.0)
).toShape()

rot = rotation(-np.pi * 2 / teeth)
rot = rotation(np.pi * 2 / teeth)
p_3 = rot(np.array([p_2_end]))[0]
# l = part.LineSegment(fcvec(p_1_end), fcvec(p_3)).toShape()
l = part_arc_from_points_and_center(
Expand Down
2 changes: 1 addition & 1 deletion freecad/gears/timinggear_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def dist_p2(s):
mirror = reflection(0.0) # reflect the points at the x-axis
p_3, p_4 = mirror(np.array([p_2, p_1]))

rot = rotation(-gamma_0) # why is the rotation in wrong direction ???
rot = rotation(gamma_0) # why is the rotation in wrong direction ???
p_5 = rot(np.array([p_1]))[0] # the rotation expects a list of points

l1 = part.LineSegment(fcvec(p_1), fcvec(p_2)).toShape()
Expand Down
9 changes: 4 additions & 5 deletions pygears/_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ def reflection3D(angle):
)

def func(x):
# why not use mat @ x
return dot(x, mat)

return func


def rotation(angle, midpoint=None):
midpoint = midpoint or [0.0, 0.0]
mat = array([[cos(angle), -sin(angle)],
[sin(angle), cos(angle)]])
mat = array([[cos(angle), sin(angle)],
[-sin(angle), cos(angle)]])
midpoint = array(midpoint)
vec = midpoint - dot(midpoint, mat)
trans = translation(vec)
Expand All @@ -64,8 +63,8 @@ def func(xx):

def rotation3D(angle):
mat = array(
[[cos(angle), -sin(angle), 0.0],
[sin(angle), cos(angle), 0.0],
[[cos(angle), sin(angle), 0.0],
[-sin(angle), cos(angle), 0.0],
[0.0, 0.0, 1.0]]
)

Expand Down
4 changes: 2 additions & 2 deletions pygears/bevel_tooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ def involute_points(self, num=10):
intersection_point = intersection_line_circle(xy[i], point, r_cut)
xy = array([intersection_point] + list(xy[i + 1 :]))
xyz = [[p[0], p[1], 1] for p in xy]
backlash_rot = rotation3D(self.angular_backlash / 2)
backlash_rot = rotation3D(- self.angular_backlash / 2)
xyz = backlash_rot(xyz)
return xyz

def points(self, num=10):
pts = self.involute_points(num=num)
rot = rotation3D(-pi / self.z / 2)
rot = rotation3D(pi / self.z / 2)
pts = rot(pts)
ref = reflection3D(pi / 2)
pts1 = ref(pts)[::-1]
Expand Down
2 changes: 1 addition & 1 deletion pygears/cycloid_tooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def points(self, num=10):
pts_outer = transpose([pts_outer_x, pts_outer_y])
pts_inner = transpose([pts_inner_x, pts_inner_y])
pts1 = vstack([pts_inner[:-2], pts_outer])
rot = rotation(self.phipart / 4 - self.angular_backlash / 2)
rot = rotation(- self.phipart / 4 + self.angular_backlash / 2)
pts1 = rot(pts1)
ref = reflection(0.0)
pts2 = ref(pts1)[::-1]
Expand Down
8 changes: 2 additions & 6 deletions pygears/involute_tooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def undercut_points(self, num=10):
y = array(list(map(fy, pts)))
xy = transpose([x, y])
rotate = rotation(
self.undercut_rot + self.phipart / 2 - self.angular_backlash / 2
- self.undercut_rot - self.phipart / 2 + self.angular_backlash / 2
)
xy = rotate(xy)
return array(xy)
Expand All @@ -136,7 +136,7 @@ def involute_points(self, num=10):
x = array(list(map(fx, pts)))
fy = self.involute_function_y()
y = array(list(map(fy, pts)))
rot = rotation(self.involute_rot - self.angular_backlash / 2)
rot = rotation(- self.involute_rot + self.angular_backlash / 2)
xy = rot(transpose(array([x, y])))
return xy

Expand Down Expand Up @@ -168,10 +168,6 @@ def points(self, num=10):
one_tooth = [u1, e1, [e1[-1], e2[0]], e2, u2]
return one_tooth

def gearfunc(self, x):
rot = rotation(2 * x / self.dw, self.midpoint)
return rot

def undercut_function_x(self):
def func(psi):
return cos(psi - (self.df * tan(psi)) / self.dw) * sqrt(
Expand Down
2 changes: 1 addition & 1 deletion pygears/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def profile(self, num=10):
if self.rot3D:
rot = rotation3D(np.pi * 2 / self.z)
else:
rot = rotation(-np.pi * 2 / self.z)
rot = rotation(np.pi * 2 / self.z)
profile = tooth
for i in range(self.z - 1):
tooth = rot(tooth).tolist()
Expand Down

0 comments on commit 323c922

Please sign in to comment.