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.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/geometry/rotation.rb', line 119 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.
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: ==
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 |
#matrix ⇒ Object
!@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 |
#x ⇒ Object
!@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 |
#y ⇒ Object
!@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 |