Class: Geometry::RightTriangle

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

Overview

Instance Attribute Summary collapse

Attributes inherited from Triangle

#closed?

Instance Method Summary collapse

Methods inherited from Triangle

#max, #min, #minmax, new

Methods included from ClusterFactory

included

Constructor Details

#initialize(origin, base, height) ⇒ RightTriangle

Construct a Right Triangle given a Point and the leg lengths



79
80
81
82
# File 'lib/geometry/triangle.rb', line 79

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

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



76
77
78
# File 'lib/geometry/triangle.rb', line 76

def base
  @base
end

#heightObject (readonly)

Returns the value of attribute height.



76
77
78
# File 'lib/geometry/triangle.rb', line 76

def height
  @height
end

#originObject (readonly)

Returns the value of attribute origin.



76
77
78
# File 'lib/geometry/triangle.rb', line 76

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



86
87
88
# File 'lib/geometry/triangle.rb', line 86

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