Class: Geometry::Arc

Inherits:
Object
  • Object
show all
Includes:
ClusterFactory
Defined in:
lib/aurora-geometry/arc.rb

Overview

) Arcs are Circles that don’t quite go all the way around

Usage

An Arc with its center at [1,1] and a radius of 2 that starts at the X-axis and goes to the Y-axis (counter-clockwise)

arc = Geometry::Arc.new center:[1,1], radius:2, start:0, end:90

Direct Known Subclasses

ThreePointArc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClusterFactory

included

Constructor Details

#initialize(center, radius, start_angle, end_angle) ⇒ Arc

Construct a new Geometry::Arc

Parameters:

  • center (Point)

    The Point at the center of it all

  • radius (Numeric)

    Radius

  • start_angle (Numeric)

    Starting angle

  • end_angle (Numeric)

    Ending angle



52
53
54
55
56
57
# File 'lib/aurora-geometry/arc.rb', line 52

def initialize(center, radius, start_angle, end_angle)
    @center = Point[center]
    @radius = radius
    @start_angle = start_angle
    @end_angle = end_angle
end

Instance Attribute Details

#centerObject (readonly)

Returns the value of attribute center.



19
20
21
# File 'lib/aurora-geometry/arc.rb', line 19

def center
  @center
end

#end_angleObject (readonly)

Returns the value of attribute end_angle.



21
22
23
# File 'lib/aurora-geometry/arc.rb', line 21

def end_angle
  @end_angle
end

#radiusObject (readonly)

Returns the value of attribute radius.



20
21
22
# File 'lib/aurora-geometry/arc.rb', line 20

def radius
  @radius
end

#start_angleObject (readonly)

Returns the value of attribute start_angle.



21
22
23
# File 'lib/aurora-geometry/arc.rb', line 21

def start_angle
  @start_angle
end

Class Method Details

.new(center, start, end) ⇒ Arc, ThreePointArc .new(center, radius, start, end) ⇒ Arc, ThreePointArc

Overloads:

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :center (Point) — default: PointZero

    The Point at the center

  • :start (Point)

    The Geometry::Arc starts at the start Point

  • :end (Point)

    The Point where it all ends

  • :center (Point) — default: PointZero

    The Point at the center of it all

  • :radius (Numeric)

    Radius

  • :start (Numeric)

    Starting angle

  • :end (Numeric)

    Ending angle

Returns:



36
37
38
39
40
41
42
43
44
# File 'lib/aurora-geometry/arc.rb', line 36

def self.new(options={})
    center = options.delete(:center) || PointZero.new

    if options.has_key?(:radius)
	original_new(center, options[:radius], options[:start], options[:end])
    else
	ThreePointArc.new(center, options[:start], options[:end])
    end
end

Instance Method Details

#firstPoint

Returns The starting point of the Geometry::Arc.

Returns:



60
61
62
# File 'lib/aurora-geometry/arc.rb', line 60

def first
    @center + @radius * Vector[Math.cos(@start_angle), Math.sin(@start_angle)]
end

#lastPoint

Returns The end point of the Geometry::Arc.

Returns:



65
66
67
# File 'lib/aurora-geometry/arc.rb', line 65

def last
    @center + @radius * Vector[Math.cos(@end_angle), Math.sin(@end_angle)]
end