Skip to content

Commit

Permalink
further refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo committed Jan 2, 2024
1 parent cd7d2cb commit 5231798
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
14 changes: 9 additions & 5 deletions pygears/_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# * *
# ***************************************************************************

from __future__ import division
from numpy import sin, cos, dot, array, ndarray, vstack, transpose, sqrt
from numpy.linalg import solve, norm

Expand All @@ -26,7 +25,8 @@ def reflection(angle):
[-sin(2 * angle), -cos(2 * angle)]])

def func(x):
# why not use mat @ x???
# we do not use matrix-multiplication here because this is meant to work
# on an array of points
return dot(x, mat)

return func
Expand All @@ -50,7 +50,8 @@ def func(x):

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 @@ -63,7 +64,9 @@ def func(xx):

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

def func(xx):
Expand All @@ -74,7 +77,8 @@ def func(xx):

def translation(vec):
def trans(x):
return [x[0] + vec[0], x[1] + vec[1]]
return [x[0] + vec[0],
x[1] + vec[1]]

def func(x):
return array(list(map(trans, x)))
Expand Down
3 changes: 0 additions & 3 deletions pygears/bevel_tooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# * *
# ***************************************************************************

from __future__ import division
from __future__ import division
from numpy import (
cos,
sin,
Expand All @@ -28,7 +26,6 @@
array,
linspace,
transpose,
vstack,
sqrt,
)
from ._functions import rotation3D, reflection3D, intersection_line_circle
Expand Down
5 changes: 3 additions & 2 deletions pygears/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def root_inv(x):

def d_root_inv(x):
return 1.0 / np.cos(x) - 1

alpha_w = find_root(alpha, root_inv, d_root_inv)

# use scipy (sp.optimize.minimize(f, f0, df).x) here (as we depent on scipy anyways)
alpha_w = find_root(alpha, root_inv, d_root_inv)
dist = m * (t1 + t2) / 2 * np.cos(alpha) / np.cos(alpha_w)
return dist, alpha_w

Expand Down
1 change: 0 additions & 1 deletion pygears/cycloid_tooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# * *
# ***************************************************************************

from __future__ import division
from numpy import cos, sin, arccos, pi, array, linspace, transpose, vstack
from ._functions import rotation, reflection

Expand Down
1 change: 0 additions & 1 deletion pygears/involute_tooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# * *
# ***************************************************************************

from __future__ import division
from numpy import (
tan,
cos,
Expand Down
19 changes: 19 additions & 0 deletions pygears/profile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * This program is free software: you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation, either version 3 of the License, or *
# * (at your option) any later version. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU General Public License for more details. *
# * *
# * You should have received a copy of the GNU General Public License *
# * along with this program. If not, see <http://www.gnu.org/licenses/>. *
# * *
# ***************************************************************************


import numpy as np
from .involute_tooth import InvoluteTooth, InvoluteRack
from .bevel_tooth import BevelTooth
Expand Down

0 comments on commit 5231798

Please sign in to comment.