Geode::Angle(T)
Inherits Comparable < Steppable < Struct < Value < Object
Base unit class for all rotation measurements.
The T type parameter is the type used to store the angle's value.
It should be a numerical type, preferably Float32 or Float64.
Constructors
Instance methods
Computes the remainder after dividing the angle by the specified amount.
25.degrees % 10 # => 5°
Computes the remainder after dividing the angle by another.
30.degrees % 4.degrees # => 2
Computes the remainder after dividing the angle by another of a different type.
200.degrees % (Math::PI.radians / 3) # => 20
Multiplies the angle by the specified amount.
Values will wrap instead of overflowing and raising an error.
15.degrees &* 5 # => 75°
Adds two angles together.
Values will wrap instead of overflowing and raising an error.
30.degrees &+ 45.degrees # => 75°
Subtracts another angle from this one.
Values will wrap instead of overflowing and raising an error.
90.degrees &- 30.degrees # => 60°
Multiplies the angle by the specified amount.
15.degrees * 5 # => 75°
Adds two angles of different types together.
30.degrees + Math::PI.radians / 2 # => 120.0°
Subtracts another angle from this one.
90.degrees - 30.degrees # => 60°
Subtracts another angle of a different type from this one.
180.degrees - Math::PI.radians / 2 # => 90.0°
Divides the angle by the specified amount.
90.degrees / 4 # => 22.5°
Divides the angle by another of a different type.
180.degrees / (Math::PI.radians / 3) # => 3.0
Divides the angle by the specified amount.
Uses integer division.
25.degrees // 10 # => 2°
Divides the angle by another.
Uses integer division.
30.degrees // 4.degrees # => 7
Divides the angle by another of a different type.
Uses integer division.
200.degrees // (Math::PI.radians / 3) # => 3
Compares this angle to another.
The return value will be:
- -1 if this angle is less than other.
- 0 if the angles are equal.
- 1 if this angle is greater than other.
45.degrees <=> 90.degrees # => -1
60.degrees <=> 60.degrees # => 0
90.degrees <=> 45.degrees # => 1
Compares this angle to another of a different type.
The return value will be:
- -1 if this angle is less than other.
- 0 if the angles are equal.
- 1 if this angle is greater than other.
45.degrees <=> (Math::PI).radians # => -1
180.degrees <=> (Math::PI).radians # => 0
90.degrees <=> (Math::PI / 4).radians # => 1
Returns true if the angle is greater than zero and less than a right-angle (quarter revolution).
0.degrees.acute? # => false
45.degrees.acute? # => true
90.degrees.acute? # => false
Returns the fraction portion of the angle's value.
This is effectively equal to:
fraction(v) = v - floor(v)
1.2.degrees.fraction # => 0.2°
Returns true if the angle is a full angle (one revolution).
Multiples of full revolutions are not considered full angles.
0.degrees.full? # => false
360.degrees.full? # => true
720.degrees.full? # => false
Calculates the linear interpolation between two angles.
t is a value from 0 to 1, where 0 represents this angle and 1 represents other. Any value between 0 and 1 will result in a proportional amount of this angle and other.
This method uses the precise calculation that does not suffer precision loss from high exponential differences.
Checks if the angle is close to zero.
The value must be within tolerance of zero.
0.degrees.near_zero?(1.degrees) # => true
1.degrees.near_zero?(1.degrees) # => true
30.degrees.near_zero?(1.degrees) # => false
Checks if the angle is close to zero.
The value must be within tolerance of zero.
0.radians.near_zero?(1.degrees) # => true
0.01.radians.near_zero?(1.degrees) # => true
Math::PI.radians.near_zero?(1.degrees) # => false
Checks if the angle is close to zero.
The value must be within tolerance of zero.
0.degrees.near_zero?(1) # => true
1.degrees.near_zero?(1) # => true
30.degrees.near_zero?(1) # => false
Checks if the angle is negative.
-5.degrees.negative? # => true
5.degrees.negative? # => false
Returns an angle corrected to be between zero and one revolution.
30.degrees.normalize # => 30°
-90.degrees.normalize # => 270°
360.degrees.normalize # => 0°
540.degrees.normalize # => 180°
Returns true if the angle isn't a multiple of a right angle.
45.degrees.oblique? # => true
90.degrees.oblique? # => false
180.degrees.oblique? # => false
360.degrees.oblique? # => false
Returns true if the angle is greater than a right angle and less than a straight angle.
90.degrees.obtuse? # => false
135.degrees.obtuse? # => true
180.degrees.obtuse? # => false
Checks if the angle is positive.
5.degrees.positive? # => true
-5.degrees.positive? # => false
Returns true if the angle is greater than a straight angle and less than a full angle.
180.degrees.reflex? # => false
270.degrees.reflex? # => true
360.degrees.reflex? # => false
Returns true if the angle is a right angle (quarter revolution).
Multiples of quarter revolutions are not considered right angles.
0.degrees.right? # => false
90.degrees.right? # => true
180.degrees.right? # => false
270.degrees.right? # => false
Returns a rounded angle.
See Number#round for details.
90.1.degrees.round # => 90.0°
Returns a rounded angle.
See Number#round for details.
12.34.degrees.round(1) # => 12.3°
Returns a value equal to its original sign.
1 is used for positive values, -1 for negative values, and 0 for zero.
-5.degrees.sign # => -1
Returns an angle corrected to be between negative half a revolution to positive half a revolution.
30.degrees.normalize # => 30°
-45.degrees.normalize # => -45°
360.degrees.normalize # => 0°
270.degrees.normalize # => -90°
-225.degrees.normalize # => 135°
Returns true if the angle is a straight angle (half revolution).
Multiples of half revolutions are not considered straight angles.
0.degrees.straight? # => false
180.degrees.straight? # => true
360.degrees.straight? # => false