Class: SolidRuby::Assemblies::PrintedGear
- Inherits:
-
Gear
- Object
- SolidRubyObject
- Assembly
- Gear
- SolidRuby::Assemblies::PrintedGear
- Defined in:
- lib/solidruby/assemblies/gear.rb
Overview
Acts the same as Gear, but does produce printable output
Instance Attribute Summary
Attributes inherited from Gear
#height, #hub_dia, #hub_height, #module, #teeth
Attributes inherited from Assembly
#hardware, #skip, #transformations, #x, #y, #z
Attributes inherited from SolidRubyObject
#attributes, #children, #siblings, #transformations
Instance Method Summary collapse
- #iang(r1, r2) ⇒ Object
-
#initialize(args = {}) ⇒ PrintedGear
constructor
A new instance of PrintedGear.
-
#output ⇒ Object
ported from publicDomainGearV1.1.scad.
- #polar(r, theta) ⇒ Object
- #q6(b, s, t, d) ⇒ Object
- #q7(f, r, b, r2, t, s) ⇒ Object
- #show ⇒ Object
Methods inherited from Gear
Methods inherited from Assembly
#*, #+, #-, #add_to_bom, #color, #colorize, #description, get_skip, get_views, #part, #scad_output, #show_hardware, skip, #threads, #transform, view, #walk_tree
Methods inherited from SolidRubyObject
#&, alias_attr, #debug, #debug?, #mirror, #place, #rotate, #rotate_around, #save, #scale, #to_rubyscad, #translate, #union, #walk_tree, #walk_tree_classes
Constructor Details
#initialize(args = {}) ⇒ PrintedGear
Returns a new instance of PrintedGear.
71 72 73 74 75 76 77 78 79 80 |
# 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 |
Instance Method Details
#iang(r1, r2) ⇒ Object
119 120 121 |
# 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 ⇒ Object
ported from publicDomainGearV1.1.scad
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# 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) ⇒ Object
115 116 117 |
# 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) ⇒ Object
127 128 129 |
# 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) ⇒ Object
123 124 125 |
# 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 ⇒ Object
82 83 84 |
# File 'lib/solidruby/assemblies/gear.rb', line 82 def show output end |