class SolidRuby::Assemblies::PrintedGear

Acts the same as Gear, but does produce printable output

Public Class Methods

new(args = {}) click to toggle source
Calls superclass method SolidRuby::Assemblies::Gear::new
# File lib/solidruby/assemblies/gear.rb, line 71
def initialize(args = {})
  super
  @pressure_angle = args[:pressure_angle] || 20
  @clearance = args[:clearance] || 0.0
  @backlash = args[:backlash] || 0.0
  @twist = args[:twist] || 0.0
  @teeth_to_hide = args[:teeth_to_hide] || 0.0

  @rotation = args[:rotation] || 0.0 # rotation in teeth
end

Public Instance Methods

iang(r1, r2) click to toggle source
# File lib/solidruby/assemblies/gear.rb, line 119
def iang(r1, r2)
  Math.sqrt((r2 / r1) * (r2 / r1) - 1) / Math::PI * 180 - degrees(Math.acos(r1 / r2)) # //unwind a string this many degrees to go from radius r1 to radius r2
end
output() click to toggle source

ported from publicDomainGearV1.1.scad

# File lib/solidruby/assemblies/gear.rb, line 87
def output
  p = @module * @teeth / 2.0
  c = p + @module - @clearance # radius of pitch circle
  b  = p * Math.cos(radians(@pressure_angle)) # radius of base circle
  r  = p - (c - p) - @clearance # radius of root circle
  t  = (@module * Math::PI) / 2.0 - @backlash / 2.0 # tooth thickness at pitch circle
  k  = -iang(b, p) - t / 2.0 / p / Math::PI * 180 # angle to where involute meets base circle on each side of tooth

  points = [
    [0, -@hub_dia / 10.0],
    polar(r, -181 / @teeth.to_f),
    polar(r, r < b ? k : -180 / @teeth.to_f),
    q7(0 / 5, r, b, c, k, 1), q7(1 / 5, r, b, c, k, 1), q7(2 / 5, r, b, c, k, 1), q7(3 / 5, r, b, c, k, 1), q7(4 / 5, r, b, c, k, 1), q7(5 / 5, r, b, c, k, 1),
    q7(5 / 5, r, b, c, k, -1), q7(4 / 5, r, b, c, k, -1), q7(3 / 5, r, b, c, k, -1), q7(2 / 5, r, b, c, k, -1), q7(1 / 5, r, b, c, k, -1), q7(0 / 5, r, b, c, k, -1),
    polar(r, r < b ? -k : 180 / @teeth.to_f),
    polar(r, 181 / @teeth.to_f)
  ]
  paths = [(0..16).to_a]

  res = SolidRubyObject.new
  (0..@teeth - @teeth_to_hide - 1).each do |i|
    res += polygon(points: points, paths: paths).linear_extrude(h: @height, convexity: 10, center: false, twist: @twist).rotate(z: i * 360 / @teeth.to_f)
  end

  res -= cylinder(h: @height + 0.2, d: @bore).translate(z: -0.1)
  res.rotate(z: @rotation * 360.0 / @teeth)
end
polar(r, theta) click to toggle source
# File lib/solidruby/assemblies/gear.rb, line 115
def polar(r, theta)
  [r * Math.sin(radians(theta)), r * Math.cos(radians(theta))] # convert polar to cartesian coordinates
end
q6(b, s, t, d) click to toggle source
# File lib/solidruby/assemblies/gear.rb, line 127
def q6(b, s, t, d)
  polar(d, s * (iang(b, d) + t)) # point at radius d on the involute curve
end
q7(f, r, b, r2, t, s) click to toggle source
# File lib/solidruby/assemblies/gear.rb, line 123
def q7(f, r, b, r2, t, s)
  q6(b, s, t, (1 - f) * [b, r].max + f * r2) # radius a fraction f up the curved side of the tooth
end
show() click to toggle source
# File lib/solidruby/assemblies/gear.rb, line 82
def show
  output
end