Class: Geometry::RotationAngle
- Defined in:
- lib/geometry/rotation.rb
Instance Attribute Summary collapse
-
#angle ⇒ Radians
The planar rotation angle.
Attributes inherited from Rotation
Accessors collapse
-
#matrix ⇒ Object
!@attribute [r] matrix @return [Matrix] the transformation Matrix representing the Rotation.
-
#x ⇒ Object
!@attribute [r] x @return [Point] the X-axis expressed in the parent coordinate frame.
-
#y ⇒ Object
!@attribute [r] y @return [Point] the Y-axis expressed in the parent coordinate frame.
Composition collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(*args) ⇒ RotationAngle
constructor
A new instance of RotationAngle.
Methods inherited from Rotation
Methods included from ClusterFactory
Constructor Details
#initialize(*args) ⇒ RotationAngle
Returns a new instance of RotationAngle.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/geometry/rotation.rb', line 120 def initialize(*args) , args = args.partition {|a| a.is_a? Hash} = .reduce({}, :merge) angle = [:angle] || args[0] if angle @angle = angle elsif .has_key? :x @angle = Math.atan2(*[:x].to_a.reverse) else @angle = 0 end end |
Instance Attribute Details
#angle ⇒ Radians
Returns 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: ==
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 |
#matrix ⇒ Object
!@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 |
#x ⇒ Object
!@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 |
#y ⇒ Object
!@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 |