Class: ControlPoint
- Inherits:
-
Object
- Object
- ControlPoint
- Defined in:
- lib/curve.rb
Instance Attribute Summary collapse
-
#d1 ⇒ Object
Returns the value of attribute d1.
-
#d2 ⇒ Object
Returns the value of attribute d2.
-
#theta ⇒ Object
Returns the value of attribute theta.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #distance(point) ⇒ Object
- #flip ⇒ Object
-
#initialize(x, y, theta, d1, d2 = d1) ⇒ ControlPoint
constructor
A new instance of ControlPoint.
- #leading_point ⇒ Object
- #move_along_line(delta) ⇒ Object
- #move_away_from_line(delta) ⇒ Object
- #point ⇒ Object
- #trailing_point ⇒ Object
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
#d1 ⇒ Object
Returns the value of attribute d1.
88 89 90 |
# File 'lib/curve.rb', line 88 def d1 @d1 end |
#d2 ⇒ Object
Returns the value of attribute d2.
88 89 90 |
# File 'lib/curve.rb', line 88 def d2 @d2 end |
#theta ⇒ Object
Returns the value of attribute theta.
88 89 90 |
# File 'lib/curve.rb', line 88 def theta @theta end |
#x ⇒ Object
Returns the value of attribute x.
88 89 90 |
# File 'lib/curve.rb', line 88 def x @x end |
#y ⇒ Object
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 |
#flip ⇒ Object
109 110 111 |
# File 'lib/curve.rb', line 109 def flip ControlPoint.new(x, y, theta + 180.deg, d2, d1) end |
#leading_point ⇒ Object
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 |
#point ⇒ Object
93 94 95 |
# File 'lib/curve.rb', line 93 def point [x, y] end |
#trailing_point ⇒ Object
101 102 103 |
# File 'lib/curve.rb', line 101 def trailing_point [x - d1 * Math.cos(theta), y - d1 * Math.sin(theta)] end |