Class: CrystalScad::Gears::PrintedGear

Inherits:
Gear show all
Defined in:
lib/crystalscad/Gears.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

#color, #hardware, #skip, #transformations, #x, #y, #z

Attributes inherited from Primitive

#children

Attributes inherited from CrystalScadObject

#args, #transformations

Instance Method Summary collapse

Methods inherited from Gear

#distance_to, #ratio

Methods inherited from Assembly

#*, #+, #-, #add_to_bom, #colorize, #description, get_skip, get_views, #method_missing, #part, #scad_output, #show_hardware, skip, #threads, #transform, view, #walk_tree

Methods inherited from Primitive

#mirror, #rotate, #rotate_around, #scale, #transform, #translate, #union

Methods inherited from CrystalScadObject

#save, #to_rubyscad, #walk_tree, #walk_tree_classes

Constructor Details

#initialize(args = {}) ⇒ PrintedGear

Returns a new instance of PrintedGear.



74
75
76
77
78
79
80
81
82
83
# File 'lib/crystalscad/Gears.rb', line 74

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CrystalScad::Assembly

Instance Method Details

#degrees(a) ⇒ Object



122
123
124
# File 'lib/crystalscad/Gears.rb', line 122

def degrees(a)
  a*180 /  Math::PI
end

#iang(r1, r2) ⇒ Object



130
131
132
# File 'lib/crystalscad/Gears.rb', line 130

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

#outputObject

ported from publicDomainGearV1.1.scad



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/crystalscad/Gears.rb', line 90

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 = CrystalScadObject.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



126
127
128
# File 'lib/crystalscad/Gears.rb', line 126

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



138
139
140
# File 'lib/crystalscad/Gears.rb', line 138

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



134
135
136
# File 'lib/crystalscad/Gears.rb', line 134

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

#radians(a) ⇒ Object



118
119
120
# File 'lib/crystalscad/Gears.rb', line 118

def radians(a)
  a/180.0 * Math::PI
end

#showObject



85
86
87
# File 'lib/crystalscad/Gears.rb', line 85

def show
  output
end