From 8464f37a73e3cfbee7f0716f9eb7611a7c2086ba Mon Sep 17 00:00:00 2001 From: looooo Date: Thu, 8 Sep 2016 16:54:43 +0200 Subject: [PATCH] occt7 updates --- gearfunc/_Classes.py | 86 ++++++++++++++++++++-------------------- gearfunc/_bevel_tooth.py | 6 +-- gearfunc/_functions.py | 3 +- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/gearfunc/_Classes.py b/gearfunc/_Classes.py index 10b25ea..4272695 100644 --- a/gearfunc/_Classes.py +++ b/gearfunc/_Classes.py @@ -27,9 +27,9 @@ from ._cycloide_tooth import cycloide_tooth from ._bevel_tooth import bevel_tooth from Part import BSplineCurve, Shape, Wire, Face, makePolygon, \ BRepOffsetAPI, Shell, makeLoft, Solid, Line, BSplineSurface, Compound,\ - show, makePolygon, makeLoft, makeHelix + show, makePolygon, makeHelix import Part -from ._functions import rotation3D +from ._functions import rotation3D, rotation from numpy import pi, cos, sin, tan import numpy @@ -123,29 +123,20 @@ class involute_gear(): fp.gear.backlash = fp.backlash.Value fp.gear._update() pts = fp.gear.points(num=fp.numpoints) + rotated_pts = pts + rot = rotation(-fp.gear.phipart) + for i in range(fp.gear.z - 1): + rotated_pts = map(rot, rotated_pts) + pts.append(numpy.array([pts[-1][-1], rotated_pts[0][0]])) + pts += rotated_pts + pts.append(numpy.array([pts[-1][-1], pts[0][0]])) if not fp.simple: wi = [] for i in pts: out = BSplineCurve() out.interpolate(list(map(fcvec, i))) - wi.append(out) - s = Wire(Shape(wi).Edges) - wi = [] - for i in range(fp.gear.z): - rot = App.Matrix() - rot.rotateZ(-i * fp.gear.phipart) - tooth_rot = s.transformGeometry(rot) - if i != 0: - pt_0 = wi[-1].Edges[-1].Vertexes[0].Point - pt_1 = tooth_rot.Edges[0].Vertexes[-1].Point - wi.append(Wire([Line(pt_0, pt_1).toShape()])) - wi.append(tooth_rot) - pt_0 = wi[-1].Edges[-1].Vertexes[0].Point - pt_1 = wi[0].Edges[0].Vertexes[-1].Point - wi.append(Wire([Line(pt_0, pt_1).toShape()])) - + wi.append(out.toShape()) wi = Wire(wi) - fp.Shape = wi if fp.beta.Value == 0: sh = Face(wi) fp.Shape = sh.extrude(App.Vector(0, 0, fp.height.Value)) @@ -255,25 +246,18 @@ class cycloide_gear(): fp.gear.backlash = fp.backlash.Value fp.gear._update() pts = fp.gear.points(num=fp.numpoints) + rotated_pts = pts + rot = rotation(-fp.gear.phipart) + for i in range(fp.gear.z - 1): + rotated_pts = map(rot, rotated_pts) + pts.append(numpy.array([pts[-1][-1], rotated_pts[0][0]])) + pts += rotated_pts + pts.append(numpy.array([pts[-1][-1], pts[0][0]])) wi = [] for i in pts: out = BSplineCurve() out.interpolate(list(map(fcvec, i))) - wi.append(out) - s = Wire(Shape(wi).Edges) - wi = [] - for i in range(fp.gear.z): - rot = App.Matrix() - rot.rotateZ(-i * fp.gear.phipart) - tooth_rot = s.transformGeometry(rot) - if i != 0: - pt_0 = wi[-1].Edges[-1].Vertexes[0].Point - pt_1 = tooth_rot.Edges[0].Vertexes[-1].Point - wi.append(Wire([Line(pt_0, pt_1).toShape()])) - wi.append(tooth_rot) - pt_0 = wi[-1].Edges[-1].Vertexes[0].Point - pt_1 = wi[0].Edges[0].Vertexes[-1].Point - wi.append(Wire([Line(pt_0, pt_1).toShape()])) + wi.append(out.toShape()) wi = Wire(wi) if fp.beta.Value == 0: sh = Face(wi) @@ -372,11 +356,18 @@ class bevel_gear(): scale = fp.m.Value * fp.gear.z / 2 / tan(fp.pitch_angle.Value * pi / 180) fp.gear.clearance = fp.clearance / scale fp.gear._update() - pts = fp.gear.points(num=fp.numpoints) + pts = list(fp.gear.points(num=fp.numpoints)) + rotated_pts = pts + rot = rotation3D(2 * pi / fp.teeth) + for i in range(fp.gear.z - 1): + rotated_pts = map(rot, rotated_pts) + pts.append(numpy.array([pts[-1][-1], rotated_pts[0][0]])) + pts += rotated_pts + pts.append(numpy.array([pts[-1][-1], pts[0][0]])) scale1 = scale - fp.height.Value / 2 scale2 = scale + fp.height.Value / 2 - fp.Shape = makeLoft([self.create_teeth(pts, scale1, fp.teeth), - self.create_teeth(pts, scale2, fp.teeth)], True) + fp.Shape = makeLoft([makeBSplineWire([pt * scale1 for pt in pts]), + makeBSplineWire([pt * scale2 for pt in pts])], True) # fp.Shape = self.create_teeth(pts, pos1, fp.teeth) @@ -405,12 +396,13 @@ class bevel_gear(): def create_teeth(self, pts, pos, teeth): w1 = [] - for i in pts: - scale = lambda x: x * pos - i_scale = list(map(scale, i)) - out = BSplineCurve() - out.interpolate(list(map(fcvec, i_scale))) - w1.append(out) + pts = [pt * pos for pt in pts] + rotated_pts = scaled_points + rot = rotation3D(- 2 * i * pi / teeth) + for i in range(teeth - 1): + rotated_pts = map(rot, rotated_pts) + pts.append(numpy.array([pts[-1][-1], rotated_pts[0][0]])) + pts += rotated_pts s = Wire(Shape(w1).Edges) wi = [] for i in range(teeth): @@ -469,3 +461,11 @@ def make_face(edge1, edge2): w = Wire([e3, e4, e1, e2]) return(Face(w)) + +def makeBSplineWire(pts): + wi = [] + for i in pts: + out = BSplineCurve() + out.interpolate(list(map(fcvec, i))) + wi.append(out.toShape()) + return Wire(wi) diff --git a/gearfunc/_bevel_tooth.py b/gearfunc/_bevel_tooth.py index 7b2fb4e..33b257a 100644 --- a/gearfunc/_bevel_tooth.py +++ b/gearfunc/_bevel_tooth.py @@ -145,11 +145,11 @@ class bevel_tooth(object): rot = rotation3D(2*pi/self.z) if self.add_foot: return(array([ - [pts[0], pts[1]], + array([pts[0], pts[1]]), pts[1:], - [pts[-1], pts1[0]], + array([pts[-1], pts1[0]]), pts1[:-1], - [pts1[-2], pts1[-1]] + array([pts1[-2], pts1[-1]]) ])) else: return(array([pts, [pts[-1], pts1[0]], pts1])) diff --git a/gearfunc/_functions.py b/gearfunc/_functions.py index 57a7863..4ff2f43 100644 --- a/gearfunc/_functions.py +++ b/gearfunc/_functions.py @@ -44,8 +44,7 @@ def reflection3D(pressure_angle): def rotation(pressure_angle, midpoint=None): - print(midpoint) - midpoint = midpoint or [0, 0] + midpoint = midpoint or [0., 0.] mat = array([[cos(pressure_angle), -sin(pressure_angle)], [sin(pressure_angle), cos(pressure_angle)]]) midpoint = array(midpoint) vec = midpoint - dot(midpoint, mat)