Class: CrystalScad::Gears::Gear
- Inherits:
-
Assembly
- Object
- CrystalScadObject
- Primitive
- Assembly
- CrystalScad::Gears::Gear
- Defined in:
- lib/crystalscad/Gears.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
this library is to be used to easily work with gears and their distances to each other.
-
#hub_dia ⇒ Object
readonly
this library is to be used to easily work with gears and their distances to each other.
-
#hub_height ⇒ Object
readonly
this library is to be used to easily work with gears and their distances to each other.
-
#module ⇒ Object
readonly
this library is to be used to easily work with gears and their distances to each other.
-
#teeth ⇒ Object
readonly
this library is to be used to easily work with gears and their distances to each other.
Attributes inherited from Assembly
#color, #hardware, #skip, #transformations, #x, #y, #z
Attributes inherited from Primitive
Attributes inherited from CrystalScadObject
Instance Method Summary collapse
- #distance_to(other_gear) ⇒ Object
-
#initialize(args = {}) ⇒ Gear
constructor
A new instance of Gear.
- #output ⇒ Object
- #ratio(other_gear) ⇒ Object
- #show ⇒ Object
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 = {}) ⇒ Gear
Returns a new instance of Gear.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/crystalscad/Gears.rb', line 24 def initialize(args={}) @module = args[:module] || 1.0 @teeth = args[:teeth] || 1.0 @bore = args[:bore] || 0.0 @height = args[:height] || 3.0 @hub_dia = args[:hub_dia] || 0.0 @hub_height = args[:hub_height] || 0.0 @output_margin_dia = args[:output_margin_dia] || 2 @output_margin_height = args[:output_margin_height] || 1 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CrystalScad::Assembly
Instance Attribute Details
#height ⇒ Object (readonly)
this library is to be used to easily work with gears and their distances to each other
22 23 24 |
# File 'lib/crystalscad/Gears.rb', line 22 def height @height end |
#hub_dia ⇒ Object (readonly)
this library is to be used to easily work with gears and their distances to each other
22 23 24 |
# File 'lib/crystalscad/Gears.rb', line 22 def hub_dia @hub_dia end |
#hub_height ⇒ Object (readonly)
this library is to be used to easily work with gears and their distances to each other
22 23 24 |
# File 'lib/crystalscad/Gears.rb', line 22 def hub_height @hub_height end |
#module ⇒ Object (readonly)
this library is to be used to easily work with gears and their distances to each other
22 23 24 |
# File 'lib/crystalscad/Gears.rb', line 22 def module @module end |
#teeth ⇒ Object (readonly)
this library is to be used to easily work with gears and their distances to each other
22 23 24 |
# File 'lib/crystalscad/Gears.rb', line 22 def teeth @teeth end |
Instance Method Details
#distance_to(other_gear) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/crystalscad/Gears.rb', line 57 def distance_to(other_gear) if @module != other_gear.module raise "You cannot use two gears with different gear modules." return end return (@module.to_f * (@teeth.to_f + other_gear.teeth.to_f))/2.0 end |
#output ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/crystalscad/Gears.rb', line 48 def output res = cylinder(d:@module*@teeth+@output_margin_dia,h:@height+@output_margin_height) if @hub_height.to_f > 0 && @hub_dia.to_f > 0 res += cylinder(d:@hub_dia+@output_margin_dia,h:@hub_height+@output_margin_height).translate(z:@height) end res end |
#ratio(other_gear) ⇒ Object
65 66 67 |
# File 'lib/crystalscad/Gears.rb', line 65 def ratio(other_gear) @teeth.to_f / other_gear.teeth.to_f end |
#show ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/crystalscad/Gears.rb', line 35 def show res = cylinder(d:@module*@teeth,h:@height) if @hub_height.to_f > 0 && @hub_dia.to_f > 0 res += cylinder(d:@hub_dia,h:@hub_height).translate(z:@height) end if @bore.to_f > 0.0 res -= cylinder(d:@bore,h:@height+@hub_height+0.2).translate(z:-0.1) end res.color("darkgray") end |