From 1a35948243ff305b90515b1ddbcd017238be64bc Mon Sep 17 00:00:00 2001 From: looooo Date: Sat, 25 Apr 2020 09:10:58 +0200 Subject: [PATCH] lgtm cleaning --- examples/animation.py | 3 +-- freecad/gears/features.py | 4 ++-- pygears/_functions.py | 10 ++++------ pygears/bevel_tooth.py | 23 ----------------------- pygears/involute_tooth.py | 18 ++++++++---------- pygears/profile.py | 1 - 6 files changed, 15 insertions(+), 44 deletions(-) diff --git a/examples/animation.py b/examples/animation.py index e8ea23f..425c426 100644 --- a/examples/animation.py +++ b/examples/animation.py @@ -1,10 +1,9 @@ # script for bevel-gear animation -from PySide import QtGui, QtCore +from PySide import QtCore import FreeCAD as app import FreeCADGui as gui import numpy as np -import imageio doc = app.ActiveDocument g2 = doc.Common diff --git a/freecad/gears/features.py b/freecad/gears/features.py index 929aa5d..bc7ee7b 100644 --- a/freecad/gears/features.py +++ b/freecad/gears/features.py @@ -32,8 +32,8 @@ from pygears._functions import rotation3D, rotation import FreeCAD as App import Part from Part import BSplineCurve, Shape, Wire, Face, makePolygon, \ - BRepOffsetAPI, Shell, makeLoft, Solid, Line, BSplineSurface, makeCompound,\ - show, makePolygon, makeHelix, makeShell, makeSolid + makeLoft, Line, BSplineSurface, \ + makePolygon, makeHelix, makeShell, makeSolid __all__ = ["InvoluteGear", diff --git a/pygears/_functions.py b/pygears/_functions.py index 4211c34..4580997 100644 --- a/pygears/_functions.py +++ b/pygears/_functions.py @@ -21,8 +21,7 @@ from __future__ import division from numpy import sin, cos, dot, array, ndarray, vstack, transpose, sqrt -from numpy.linalg import solve -import numpy as np +from numpy.linalg import solve, norm def reflection(pressure_angle): @@ -109,7 +108,6 @@ def trim(p1, p2, p3, p4): return(a1 + g * (a2 - a1)) else: return(False) - return(False) def trimfunc(l1, l2): @@ -137,9 +135,9 @@ def trimfunc(l1, l2): return(False) -def norm(vec1, vec2): +def diff_norm(vec1, vec2): vec = array(vec2) - array(vec1) - return np.linalg.norm(vec) + return norm(vec) def nearestpts(evolv, underc): @@ -166,7 +164,7 @@ def intersection_line_circle(p1, p2, r): """return the intersection point of a line from p1 to p2 and a sphere of radius 1 and midpoint 0,0,0""" d = p2 - p1 - d /= np.linalg.norm(d) + d /= norm(d) p_half = d.dot(p1) q = p1.dot(p1) - r ** 2 t = -p_half + sqrt(p_half ** 2 - q) diff --git a/pygears/bevel_tooth.py b/pygears/bevel_tooth.py index b7d6b2b..cd2e1a7 100644 --- a/pygears/bevel_tooth.py +++ b/pygears/bevel_tooth.py @@ -22,7 +22,6 @@ from __future__ import division from __future__ import division from numpy import cos, sin, tan, arccos, arctan, pi, array, linspace, transpose, vstack, sqrt -import numpy as np from ._functions import rotation3D, reflection3D, intersection_line_circle @@ -61,27 +60,6 @@ class BevelTooth(object): self.z_f = cos(self.pitch_angle - sin(pitch_angle) * 2 / self.z) self.add_foot = True - # if self.involute_start_radius < self.r_f: - # self.add_foot = False - # self.involute_start = -arccos( - # sqrt((42 + 16*cos(2*self.pressure_angle) + 6*cos(4*self.pressure_angle) - - # 4*cos(4*self.pressure_angle - 2*self.pitch_angle) - 8*cos(2*(self.pressure_angle - self.pitch_angle)) + - # cos(4*(self.pressure_angle - self.pitch_angle)) + 24*cos(2*self.pitch_angle) - 2*cos(4*self.pitch_angle) - - # 8*cos(2*(self.pressure_angle + self.pitch_angle)) + cos(4*(self.pressure_angle + self.pitch_angle)) - - # 4*cos(2*(2*self.pressure_angle + self.pitch_angle)) + 24*cos((4*sin(self.pitch_angle))/self.z) + - # 4*cos(2*self.pressure_angle - (4*sin(self.pitch_angle))/self.z) + 16*cos(2*self.pitch_angle - - # (4*sin(self.pitch_angle))/self.z) + 24*cos(4*self.pitch_angle - (4*sin(self.pitch_angle))/self.z) + - # 4*cos(2*self.pressure_angle + 4*self.pitch_angle - (4*sin(self.pitch_angle))/self.z) - - # 8*cos(2*(self.pressure_angle + self.pitch_angle - (2*sin(self.pitch_angle))/self.z)) + - # 4*cos(2*self.pressure_angle + (4*sin(self.pitch_angle))/self.z) + 4*cos(2*self.pressure_angle - - # 4*self.pitch_angle + (4*sin(self.pitch_angle))/self.z) - 8*cos(2*self.pressure_angle - 2*self.pitch_angle + - # (4*sin(self.pitch_angle))/self.z) + 32*sqrt(2)*sqrt(-(cos(self.pressure_angle)**2* - # (-2 - 2*cos(2*self.pressure_angle) + cos(2*(self.pressure_angle - self.pitch_angle)) - - # 2*cos(2*self.pitch_angle) + cos(2*(self.pressure_angle + self.pitch_angle)) + - # 4*cos(2*self.pitch_angle - (4*sin(self.pitch_angle))/self.z))*cos(self.pitch_angle - (2*sin(self.pitch_angle))/self.z)**2* - # sin(2*self.pitch_angle)**2)))/(-6 - 2*cos(2*self.pressure_angle) + cos(2*(self.pressure_angle - self.pitch_angle)) - - # 2*cos(2*self.pitch_angle) + cos(2*(self.pressure_angle + self.pitch_angle)))**2)/sqrt(2)) - def involute_function_x(self): def func(s): return(( @@ -143,7 +121,6 @@ class BevelTooth(object): pts = rot(pts) ref = reflection3D(pi/2) pts1 = ref(pts)[::-1] - rot = rotation3D(2*pi/self.z) if self.add_foot: return(array([ array([pts[0], pts[1]]), diff --git a/pygears/involute_tooth.py b/pygears/involute_tooth.py index 04bd763..051e480 100644 --- a/pygears/involute_tooth.py +++ b/pygears/involute_tooth.py @@ -21,8 +21,7 @@ from __future__ import division from numpy import tan, cos, sin, sqrt, arctan, pi, array, linspace, transpose, vstack, ndarray -from ._functions import nearestpts, rotation, reflection, trimfunc, norm, translation -import numpy as np +from ._functions import nearestpts, rotation, reflection, trimfunc, diff_norm, translation class InvoluteTooth(): @@ -49,7 +48,7 @@ class InvoluteTooth(): self.pressure_angle_t = self.pressure_angle self.m = self.m_n - self.pitch = self.m * np.pi + self.pitch = self.m * pi self.c = self.clearance * self.m_n self.midpoint = [0., 0.] self.d = self.z * self.m @@ -112,7 +111,7 @@ class InvoluteTooth(): u1 = False if self.dg > self.df: u1 = vstack( - [[l2[0] * self.df / (norm(l2[0], [0, 0]) * 2)], [l2[0]]]) + [[l2[0] * self.df / (diff_norm(l2[0], [0, 0]) * 2)], [l2[0]]]) e1 = l2 else: e1 = l2 @@ -120,7 +119,6 @@ class InvoluteTooth(): reflect = reflection(0) e2 = reflect(e1)[::-1] if isinstance(u1, bool): - u2 = False one_tooth = [e1, [e1[-1], e2[0]], e2] else: u2 = reflect(u1)[::-1] @@ -214,10 +212,10 @@ class InvoluteRack(object): teeth[-1][0][0] = 0 teeth[-1][0][1] += a / 2 - teeth = np.array([v for t in teeth for v in t]) # flattening + teeth = array([v for t in teeth for v in t]) # flattening if self.add_endings: - ext1 = teeth[0] + np.array([0., a + b - pitch / 2]) - ext2 = teeth[-1] - np.array([0., a + b - pitch / 2]) + ext1 = teeth[0] + array([0., a + b - pitch / 2]) + ext2 = teeth[-1] - array([0., a + b - pitch / 2]) teeth = [ext1.tolist(), ext1.tolist()] + teeth.tolist() + [ext2.tolist(), ext2.tolist()] else: teeth = [teeth[0].tolist()] + teeth.tolist() + [teeth[-1].tolist()] @@ -226,7 +224,7 @@ class InvoluteRack(object): #teeth.append(list(teeth[0])) teeth[-1][0] -= self.thickness teeth.append(teeth[0]) - return np.array(teeth) + return array(teeth) def compute_properties(self): if self.properties_from_tool: @@ -238,5 +236,5 @@ class InvoluteRack(object): m = self.m m_n = self.m - pitch = m * np.pi + pitch = m * pi return m, m_n, pitch, pressure_angle_t diff --git a/pygears/profile.py b/pygears/profile.py index d110e06..8d8c812 100644 --- a/pygears/profile.py +++ b/pygears/profile.py @@ -28,7 +28,6 @@ class CycloideProfile(CycloideTooth, _GearProfile): class BevelProfile(BevelTooth, _GearProfile): rot3D = True - pass class InvoluteRackProfile(InvoluteRack): def profile(self):