Class: CrystalScad::ScrewThreads::ScrewThread
- Inherits:
-
Object
- Object
- CrystalScad::ScrewThreads::ScrewThread
- Defined in:
- lib/crystalscad/ScrewThreads.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
I would name this Thread but that’s already taken by something else.
-
#face ⇒ Object
I would name this Thread but that’s already taken by something else.
-
#size ⇒ Object
I would name this Thread but that’s already taken by something else.
-
#x ⇒ Object
I would name this Thread but that’s already taken by something else.
-
#y ⇒ Object
I would name this Thread but that’s already taken by something else.
-
#z ⇒ Object
I would name this Thread but that’s already taken by something else.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ ScrewThread
constructor
A new instance of ScrewThread.
- #orientation_swap_to(coords, rotation) ⇒ Object
- #output ⇒ Object
- #position_on(other_thread, rotation = {}) ⇒ Object
- #rotation ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ ScrewThread
Returns a new instance of ScrewThread.
22 23 24 25 26 27 28 29 |
# File 'lib/crystalscad/ScrewThreads.rb', line 22 def initialize(args={}) @x = args[:x] || 0 @y = args[:y] || 0 @z = args[:z] || 0 @depth = args[:depth] @size = args[:size] @face = args[:face] || :top end |
Instance Attribute Details
#depth ⇒ Object
I would name this Thread but that’s already taken by something else
20 21 22 |
# File 'lib/crystalscad/ScrewThreads.rb', line 20 def depth @depth end |
#face ⇒ Object
I would name this Thread but that’s already taken by something else
20 21 22 |
# File 'lib/crystalscad/ScrewThreads.rb', line 20 def face @face end |
#size ⇒ Object
I would name this Thread but that’s already taken by something else
20 21 22 |
# File 'lib/crystalscad/ScrewThreads.rb', line 20 def size @size end |
#x ⇒ Object
I would name this Thread but that’s already taken by something else
20 21 22 |
# File 'lib/crystalscad/ScrewThreads.rb', line 20 def x @x end |
#y ⇒ Object
I would name this Thread but that’s already taken by something else
20 21 22 |
# File 'lib/crystalscad/ScrewThreads.rb', line 20 def y @y end |
#z ⇒ Object
I would name this Thread but that’s already taken by something else
20 21 22 |
# File 'lib/crystalscad/ScrewThreads.rb', line 20 def z @z end |
Instance Method Details
#orientation_swap_to(coords, rotation) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/crystalscad/ScrewThreads.rb', line 56 def orientation_swap_to(coords,rotation) if rotation[:x].to_i == -90 return [coords[0],coords[2],-coords[1]] end if rotation[:x].to_i == 90 return [coords[0],-coords[2],coords[1]] end if rotation[:y].to_i == -90 return [coords[2],coords[1],coords[0]] end if rotation[:y].to_i == 90 return [-coords[2],coords[1],-coords[0]] end return coords end |
#output ⇒ Object
52 53 54 |
# File 'lib/crystalscad/ScrewThreads.rb', line 52 def output show end |
#position_on(other_thread, rotation = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/crystalscad/ScrewThreads.rb', line 73 def position_on(other_thread,rotation={}) if other_thread.kind_of? Bolt # we assume that a bolt is always centered and center the object on # the screwthread position return {x:-@x,y:-@y,z:-@z} else # on a screwthread find out its position and orientation oc = other_thread.x, other_thread.y, other_thread.z oc = orientation_swap_to(oc,rotation) return {x:@x-oc[0],y:@y-oc[1],z:@z-oc[2]} end end |
#rotation ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/crystalscad/ScrewThreads.rb', line 31 def rotation case @face.to_s when "top" return {} when "bottom" return {y:180} when "left" return {y:-90} when "right" return {y:90} when "front" # checkme return {x:90} when "back" return {x:-90} end end |
#show ⇒ Object
48 49 50 |
# File 'lib/crystalscad/ScrewThreads.rb', line 48 def show cylinder(d:@size,h:@depth).rotate(rotation).translate(x:@x,y:@y,z:@z).color(r:130,g:130,b:130) end |