Class: Line

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p1, p2) ⇒ Line

Returns a new instance of Line.



2
3
4
5
6
# File 'lib/line.rb', line 2

def initialize(p1, p2)
  @a = 1.0*(p2.y-p1.y)/(p2.x-p1.x)
  @b = 1.0*p1.y - @a*p1.x
  # pp [p1, p2, @a, @b]
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



15
16
17
# File 'lib/line.rb', line 15

def a
  @a
end

#bObject

Returns the value of attribute b.



15
16
17
# File 'lib/line.rb', line 15

def b
  @b
end

Instance Method Details

#intersect(other) ⇒ Object



8
9
10
11
12
13
# File 'lib/line.rb', line 8

def intersect(other)
  x = 1.0*(b-other.b)/(other.a-a)
  y = 1.0*a*x+b
  # pp [self, other, x, y]
  Point.new(x, y)
end