parameters: (w, m, Z, phi, split=True)
return_statement: return w
docstring: Create an external gear
  
      w is wirebuilder object (in which the gear will be constructed)
  
      if split is True, each profile of a teeth will consist in 2 Bezier
      curves of degree 3, otherwise it will be made of one Bezier curve
      of degree 4
docstring_summary: Create an external gear
docstring_tokens: Create an external gear
function: def CreateExternalGear(w, m, Z, phi, split=True):
      """
      Create an external gear
  
      w is wirebuilder object (in which the gear will be constructed)
  
      if split is True, each profile of a teeth will consist in 2 Bezier
      curves of degree 3, otherwise it will be made of one Bezier curve
      of degree 4
      """
      # ****** external gear specifications
      addendum = m              # distance from pitch circle to tip circle
      dedendum = 1.25 * m         # pitch circle to root, sets clearance
      clearance = dedendum - addendum
  
      # Calculate radii
      Rpitch = Z * m / 2            # pitch circle radius
      Rb = Rpitch*cos(phi * pi / 180)  # base circle radius
      Ra = Rpitch + addendum    # tip (addendum) circle radius
      Rroot = Rpitch - dedendum # root circle radius
      fRad = 1.5 * clearance # fillet radius, max 1.5*clearance
      Rf = sqrt((Rroot + fRad)**2 - fRad**2) # radius at top of fillet
      if (Rb < Rf):
          Rf = Rroot + clearance
  
      # ****** calculate angles (all in radians)
      pitchAngle = 2 * pi / Z  # angle subtended by whole tooth (rads)
      baseToPitchAngle = genInvolutePolar(Rb, Rpitch)
      pitchToFilletAngle = baseToPitchAngle  # profile starts at base circle
      if (Rf > Rb):         # start profile at top of fillet (if its greater)
          pitchToFilletAngle -= genInvolutePolar(Rb, Rf)
  
      filletAngle = atan(fRad / (fRad + Rroot))  # radians
  
      # ****** generate Higuchi involute approximation
      fe = 1       # fraction of profile length at end of approx
      fs = 0.01    # fraction of length offset from base to avoid singularity
      if (Rf > Rb):
          fs = (Rf**2 - Rb**2) / (Ra**2 - Rb**2)  # offset start to top of fillet
  
      if split:
          # approximate in 2 sections, split 25% along the involute
          fm = fs + (fe - fs) / 4   # fraction of length at junction (25% along profile)
          dedInv = BezCoeffs(m, Z, phi, 3, fs, fm)
          addInv = BezCoeffs(m, Z, phi, 3, fm, fe)
  
          # join the 2 sets of coeffs (skip duplicate mid point)
          inv = dedInv + addInv[1:]
      else:
          inv = BezCoeffs(m, Z, phi, 4, fs, fe)
  
      # create the back profile of tooth (mirror image)
      invR = []
      for i, pt in enumerate(inv):
          # rotate all points to put pitch point at y = 0
          ptx, pty = inv[i] = rotate(pt, -baseToPitchAngle - pitchAngle / 4)
          # generate the back of tooth profile nodes, mirror coords in X axis
          invR.append((ptx, -pty))
  
      # ****** calculate section junction points R=back of tooth, Next=front of next tooth)
      fillet = toCartesian(Rf, -pitchAngle / 4 - pitchToFilletAngle) # top of fillet
      filletR = [fillet[0], -fillet[1]]   # flip to make same point on back of tooth
      rootR = toCartesian(Rroot, pitchAngle / 4 + pitchToFilletAngle + filletAngle)
      rootNext = toCartesian(Rroot, 3 * pitchAngle / 4 - pitchToFilletAngle - filletAngle)
      filletNext = rotate(fillet, pitchAngle)  # top of fillet, front of next tooth
  
      # Build the shapes using FreeCAD.Part
      t_inc = 2.0 * pi / float(Z)
      thetas = [(x * t_inc) for x in range(Z)]
  
      w.move(fillet) # start at top of fillet
  
      for theta in thetas:
          w.theta = theta
          if (Rf < Rb):
              w.line(inv[0]) # line from fillet up to base circle
  
          if split:
              w.curve(inv[1], inv[2], inv[3])
              w.curve(inv[4], inv[5], inv[6])
              w.arc(invR[6], Ra, 1) # arc across addendum circle
              w.curve(invR[5], invR[4], invR[3])
              w.curve(invR[2], invR[1], invR[0])
          else:
              w.curve(*inv[1:])
              w.arc(invR[-1], Ra, 1) # arc across addendum circle
              w.curve(*invR[-2::-1])
  
          if (Rf < Rb):
              w.line(filletR) # line down to topof fillet
  
          if (rootNext[1] > rootR[1]):    # is there a section of root circle between fillets?
              w.arc(rootR, fRad, 0) # back fillet
              w.arc(rootNext, Rroot, 1) # root circle arc
  
          w.arc(filletNext, fRad, 0)
  
      w.close()
      return w
function_tokens: def CreateExternalGear ( w , m , Z , phi , split = True ) : # ****** external gear specifications addendum = m # distance from pitch circle to tip circle dedendum = 1.25 * m # pitch circle to root, sets clearance clearance = dedendum - addendum # Calculate radii Rpitch = Z * m / 2 # pitch circle radius Rb = Rpitch * cos ( phi * pi / 180 ) # base circle radius Ra = Rpitch + addendum # tip (addendum) circle radius Rroot = Rpitch - dedendum # root circle radius fRad = 1.5 * clearance # fillet radius, max 1.5*clearance Rf = sqrt ( ( Rroot + fRad ) ** 2 - fRad ** 2 ) # radius at top of fillet if ( Rb < Rf ) : Rf = Rroot + clearance # ****** calculate angles (all in radians) pitchAngle = 2 * pi / Z # angle subtended by whole tooth (rads) baseToPitchAngle = genInvolutePolar ( Rb , Rpitch ) pitchToFilletAngle = baseToPitchAngle # profile starts at base circle if ( Rf > Rb ) : # start profile at top of fillet (if its greater) pitchToFilletAngle -= genInvolutePolar ( Rb , Rf ) filletAngle = atan ( fRad / ( fRad + Rroot ) ) # radians # ****** generate Higuchi involute approximation fe = 1 # fraction of profile length at end of approx fs = 0.01 # fraction of length offset from base to avoid singularity if ( Rf > Rb ) : fs = ( Rf ** 2 - Rb ** 2 ) / ( Ra ** 2 - Rb ** 2 ) # offset start to top of fillet if split : # approximate in 2 sections, split 25% along the involute fm = fs + ( fe - fs ) / 4 # fraction of length at junction (25% along profile) dedInv = BezCoeffs ( m , Z , phi , 3 , fs , fm ) addInv = BezCoeffs ( m , Z , phi , 3 , fm , fe ) # join the 2 sets of coeffs (skip duplicate mid point) inv = dedInv + addInv [ 1 : ] else : inv = BezCoeffs ( m , Z , phi , 4 , fs , fe ) # create the back profile of tooth (mirror image) invR = [ ] for i , pt in enumerate ( inv ) : # rotate all points to put pitch point at y = 0 ptx , pty = inv [ i ] = rotate ( pt , - baseToPitchAngle - pitchAngle / 4 ) # generate the back of tooth profile nodes, mirror coords in X axis invR . append ( ( ptx , - pty ) ) # ****** calculate section junction points R=back of tooth, Next=front of next tooth) fillet = toCartesian ( Rf , - pitchAngle / 4 - pitchToFilletAngle ) # top of fillet filletR = [ fillet [ 0 ] , - fillet [ 1 ] ] # flip to make same point on back of tooth rootR = toCartesian ( Rroot , pitchAngle / 4 + pitchToFilletAngle + filletAngle ) rootNext = toCartesian ( Rroot , 3 * pitchAngle / 4 - pitchToFilletAngle - filletAngle ) filletNext = rotate ( fillet , pitchAngle ) # top of fillet, front of next tooth # Build the shapes using FreeCAD.Part t_inc = 2.0 * pi / float ( Z ) thetas = [ ( x * t_inc ) for x in range ( Z ) ] w . move ( fillet ) # start at top of fillet for theta in thetas : w . theta = theta if ( Rf < Rb ) : w . line ( inv [ 0 ] ) # line from fillet up to base circle if split : w . curve ( inv [ 1 ] , inv [ 2 ] , inv [ 3 ] ) w . curve ( inv [ 4 ] , inv [ 5 ] , inv [ 6 ] ) w . arc ( invR [ 6 ] , Ra , 1 ) # arc across addendum circle w . curve ( invR [ 5 ] , invR [ 4 ] , invR [ 3 ] ) w . curve ( invR [ 2 ] , invR [ 1 ] , invR [ 0 ] ) else : w . curve ( * inv [ 1 : ] ) w . arc ( invR [ - 1 ] , Ra , 1 ) # arc across addendum circle w . curve ( * invR [ - 2 : : - 1 ] ) if ( Rf < Rb ) : w . line ( filletR ) # line down to topof fillet if ( rootNext [ 1 ] > rootR [ 1 ] ) : # is there a section of root circle between fillets? w . arc ( rootR , fRad , 0 ) # back fillet w . arc ( rootNext , Rroot , 1 ) # root circle arc w . arc ( filletNext , fRad , 0 ) w . close ( ) return w