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.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/geometry/rotation.rb', line 122 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.
118 119 120 |
# File 'lib/geometry/rotation.rb', line 118 def angle @angle end |
Instance Method Details
#+(other) ⇒ Object
174 175 176 177 178 179 180 181 |
# File 'lib/geometry/rotation.rb', line 174 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
183 184 185 186 187 188 189 190 |
# File 'lib/geometry/rotation.rb', line 183 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
170 171 172 |
# File 'lib/geometry/rotation.rb', line 170 def -@ RotationAngle.new(-angle) end |
#eql?(other) ⇒ Boolean Also known as: ==
137 138 139 140 141 142 143 |
# File 'lib/geometry/rotation.rb', line 137 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}
149 150 151 152 153 154 |
# File 'lib/geometry/rotation.rb', line 149 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
158 159 160 |
# File 'lib/geometry/rotation.rb', line 158 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
164 165 166 |
# File 'lib/geometry/rotation.rb', line 164 def y Point[-Math.sin(angle), Math.cos(angle)] end |