Class: ControlPoint

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, theta, d1, d2 = d1) ⇒ ControlPoint

Returns a new instance of ControlPoint.



89
90
91
# File 'lib/curve.rb', line 89

def initialize(x, y, theta, d1, d2=d1)
  @x, @y, @theta, @d1, @d2 = x, y, theta, d1, d2
end

Instance Attribute Details

#d1Object

Returns the value of attribute d1.



88
89
90
# File 'lib/curve.rb', line 88

def d1
  @d1
end

#d2Object

Returns the value of attribute d2.



88
89
90
# File 'lib/curve.rb', line 88

def d2
  @d2
end

#thetaObject

Returns the value of attribute theta.



88
89
90
# File 'lib/curve.rb', line 88

def theta
  @theta
end

#xObject

Returns the value of attribute x.



88
89
90
# File 'lib/curve.rb', line 88

def x
  @x
end

#yObject

Returns the value of attribute y.



88
89
90
# File 'lib/curve.rb', line 88

def y
  @y
end

Instance Method Details

#distance(point) ⇒ Object



97
98
99
# File 'lib/curve.rb', line 97

def distance(point)
  Math.sqrt((x - point.x) ** 2 + (y - point.y) ** 2)
end

#flipObject



109
110
111
# File 'lib/curve.rb', line 109

def flip
  ControlPoint.new(x, y, theta + 180.deg, d2, d1)
end

#leading_pointObject



105
106
107
# File 'lib/curve.rb', line 105

def leading_point
  [x + d2 * Math.cos(theta), y + d2 * Math.sin(theta)]
end

#move_along_line(delta) ⇒ Object



117
118
119
# File 'lib/curve.rb', line 117

def move_along_line(delta)
  ControlPoint.new(x + delta * Math.cos(theta) * d1/d1.abs, y + delta * Math.sin(theta) * d1/d1.abs, theta, d1, d2)
end

#move_away_from_line(delta) ⇒ Object



113
114
115
# File 'lib/curve.rb', line 113

def move_away_from_line(delta)
  ControlPoint.new(x + delta * Math.cos(theta - 90.deg) * d1/d1.abs, y + delta * Math.sin(theta - 90.deg) * d1/d1.abs, theta, d1, d2)
end

#pointObject



93
94
95
# File 'lib/curve.rb', line 93

def point
  [x, y]
end

#trailing_pointObject



101
102
103
# File 'lib/curve.rb', line 101

def trailing_point
  [x - d1 * Math.cos(theta), y - d1 * Math.sin(theta)]
end