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



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

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



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

def angle
  @angle
end

Instance Method Details

#+(other) ⇒ Object



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

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



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

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



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

def -@
    RotationAngle.new(-angle)
end

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

Returns:

  • (Boolean)


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

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}


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

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


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

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


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

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