Class: SolidRuby::ScrewThreads::ScrewThread

Inherits:
Object
  • Object
show all
Defined in:
lib/solidruby/screw_thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ScrewThread

Returns a new instance of ScrewThread.



22
23
24
25
26
27
28
29
# File 'lib/solidruby/screw_thread.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

#depthObject

I would name this Thread but that’s already taken by something else



20
21
22
# File 'lib/solidruby/screw_thread.rb', line 20

def depth
  @depth
end

#faceObject

I would name this Thread but that’s already taken by something else



20
21
22
# File 'lib/solidruby/screw_thread.rb', line 20

def face
  @face
end

#sizeObject

I would name this Thread but that’s already taken by something else



20
21
22
# File 'lib/solidruby/screw_thread.rb', line 20

def size
  @size
end

#xObject

I would name this Thread but that’s already taken by something else



20
21
22
# File 'lib/solidruby/screw_thread.rb', line 20

def x
  @x
end

#yObject

I would name this Thread but that’s already taken by something else



20
21
22
# File 'lib/solidruby/screw_thread.rb', line 20

def y
  @y
end

#zObject

I would name this Thread but that’s already taken by something else



20
21
22
# File 'lib/solidruby/screw_thread.rb', line 20

def z
  @z
end

Instance Method Details

#orientation_swap_to(coords, rotation) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/solidruby/screw_thread.rb', line 56

def orientation_swap_to(coords, rotation)
  return [coords[0], coords[2], -coords[1]] if rotation[:x].to_i == -90
  return [coords[0], -coords[2], coords[1]] if rotation[:x].to_i == 90
  return [coords[2], coords[1], coords[0]] if rotation[:y].to_i == -90
  return [-coords[2], coords[1], -coords[0]] if rotation[:y].to_i == 90

  coords
end

#outputObject



52
53
54
# File 'lib/solidruby/screw_thread.rb', line 52

def output
  show
end

#position_on(other_thread, rotation = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/solidruby/screw_thread.rb', line 65

def position_on(other_thread, rotation = {})
  if other_thread.is_a? Bolt
    # we assume that a bolt is always centered and center the object on
    # the screwthread position
    { 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)
    { x: @x - oc[0], y: @y - oc[1], z: @z - oc[2] }
  end
end

#rotationObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/solidruby/screw_thread.rb', line 31

def rotation
  case @face.to_s
  when 'top'
    {}
  when 'bottom'
    { y: 180 }
  when 'left'
    { y: -90 }
  when 'right'
    { y: 90 }
  when 'front' # checkme
    { x: 90 }
  when 'back'
    { x: -90 }
  end
end

#showObject



48
49
50
# File 'lib/solidruby/screw_thread.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