Class: Geometry::RotationAngle

Inherits:
Rotation
  • Object
show all
Defined in:
lib/geometry/rotation.rb

Instance Attribute Summary collapse

Attributes inherited from Rotation

#dimensions, #z

Accessors collapse

Composition collapse

Instance Method Summary collapse

Methods inherited from Rotation

#identity?, new, #transform

Methods included from ClusterFactory

included

Constructor Details

#initialize(*args) ⇒ RotationAngle

Returns a new instance of RotationAngle.

Parameters:

  • options (Hash)

    a customizable set of options



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/geometry/rotation.rb', line 120

def initialize(*args)
    options, args = args.partition {|a| a.is_a? Hash}
    options = options.reduce({}, :merge)

    angle = options[:angle] || args[0]

    if angle
	@angle = angle
    elsif options.has_key? :x
	@angle = Math.atan2(*options[:x].to_a.reverse)
    else
	@angle = 0
    end
end

Instance Attribute Details

#angleRadians

Returns the planar rotation angle.

Returns:

  • (Radians)

    the planar rotation angle



116
117
118
# File 'lib/geometry/rotation.rb', line 116

def angle
  @angle
end

Instance Method Details

#+(other) ⇒ Object



172
173
174
175
176
177
178
179
# File 'lib/geometry/rotation.rb', line 172

def +(other)
    case other
	when RotationAngle
	    RotationAngle.new(angle + other.angle)
	else
	    raise TypeError, "Can't compose a #{self.class} with a #{other.class}"
    end
end

#-(other) ⇒ Object



181
182
183
184
185
186
187
188
# File 'lib/geometry/rotation.rb', line 181

def -(other)
    case other
	when RotationAngle
	    RotationAngle.new(angle - other.angle)
	else
	    raise TypeError, "Can't subtract #{other.class} from #{self.class}"
    end
end

#-@Object



168
169
170
# File 'lib/geometry/rotation.rb', line 168

def -@
    RotationAngle.new(-angle)
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


135
136
137
138
139
140
141
# File 'lib/geometry/rotation.rb', line 135

def eql?(other)
    case other
	when RotationAngle then angle.eql? other.angle
	else
	    false
    end
end

#matrixObject

!@attribute [r] matrix

@return [Matrix] the transformation {Matrix} representing the {Rotation}


147
148
149
150
151
152
# File 'lib/geometry/rotation.rb', line 147

def matrix
    return nil unless angle

    c, s = Math.cos(angle), Math.sin(angle)
    Matrix[[c, -s], [s, c]]
end

#xObject

!@attribute [r] x

@return [Point] the X-axis expressed in the parent coordinate frame


156
157
158
# File 'lib/geometry/rotation.rb', line 156

def x
    Point[Math.cos(angle), Math.sin(angle)]
end

#yObject

!@attribute [r] y

@return [Point] the Y-axis expressed in the parent coordinate frame


162
163
164
# File 'lib/geometry/rotation.rb', line 162

def y
    Point[-Math.sin(angle), Math.cos(angle)]
end