Class: Geometry::RightTriangle

Inherits:
Triangle
  • Object
show all
Defined in:
lib/geometry/triangle.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Triangle

new

Methods included from ClusterFactory

included

Constructor Details

#initialize(origin, base, height) ⇒ RightTriangle

Construct a Right Triangle given a Point and the leg lengths



58
59
60
61
# File 'lib/geometry/triangle.rb', line 58

def initialize(origin, base, height)
    @origin = Point[origin]
    @base, @height = base, height
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



55
56
57
# File 'lib/geometry/triangle.rb', line 55

def base
  @base
end

#heightObject (readonly)

Returns the value of attribute height.



55
56
57
# File 'lib/geometry/triangle.rb', line 55

def height
  @height
end

#originObject (readonly)

Returns the value of attribute origin.



55
56
57
# File 'lib/geometry/triangle.rb', line 55

def origin
  @origin
end

Instance Method Details

#pointsArray<Point>

An array of points corresponding to the vertices of the Triangle (clockwise)

Returns:

  • (Array<Point>)

    Vertices



65
66
67
# File 'lib/geometry/triangle.rb', line 65

def points
    [@origin, @origin + Point[0,@height], @origin + Point[@base,0]]
end