Class: Geometry::Arc

Inherits:
Object
  • Object
show all
Includes:
ClusterFactory
Defined in:
lib/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



57
58
59
60
61
62
# File 'lib/geometry/arc.rb', line 57

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/geometry/arc.rb', line 19

def center
  @center
end

#end_angleObject (readonly)

Returns the value of attribute end_angle.



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

def end_angle
  @end_angle
end

#optionsObject



23
24
25
26
# File 'lib/geometry/arc.rb', line 23

def options
	@options = {} if !@options
	@options
end

#radiusObject (readonly)

Returns the value of attribute radius.



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

def radius
  @radius
end

#start_angleObject (readonly)

Returns the value of attribute start_angle.



21
22
23
# File 'lib/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:

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



41
42
43
44
45
46
47
48
49
# File 'lib/geometry/arc.rb', line 41

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



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

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

#lastPoint



70
71
72
# File 'lib/geometry/arc.rb', line 70

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