Constructor
new Angle(rac, turn)
Creates a new Angle instance.
The turn value is constrained to the rance [0,1), any value
outside is reduced back into range using a modulo operation.
new Rac.Angle(rac, 1/4) // turn is 1/4
new Rac.Angle(rac, 5/4) // turn is 1/4
new Rac.Angle(rac, -1/4) // turn is 3/4
new Rac.Angle(rac, 1) // turn is 0
new Rac.Angle(rac, 4) // turn is 0
Parameters:
| Name | Type | Description |
|---|---|---|
rac |
Rac
|
Instance to use for drawing and creating other objects |
turn |
number
|
The turn value |
Members
rac :Rac
Instance of Rac used for drawing and passed along to any created
object.
turn :number
Turn value of the angle, constrained to the range [0,1).
Methods
(static) from(rac, something) → {Rac.Angle}
Returns an Angle derived from something.
- When
somethingis an instance ofAngle, returns that same object. - When
somethingis anumber, returns a newAnglewithsomethingasturn. - When
somethingis aRac.Ray, returns its angle. - When
somethingis aRac.Segment, returns its angle. - Otherwise an error is thrown.
Parameters:
| Name | Type | Description |
|---|---|---|
rac |
Rac
|
Instance to pass along to newly created objects |
something |
Rac.Angle
|
Rac.Ray
|
Rac.Segment
|
number
|
An object to
derive an |
(static) fromDegrees(rac, degrees) → {Rac.Angle}
Returns an Angle derived from degrees.
Parameters:
| Name | Type | Description |
|---|---|---|
rac |
Rac
|
Instance to pass along to newly created objects |
degrees |
number
|
The measure of the angle, in degrees |
(static) fromRadians(rac, radians) → {Rac.Angle}
Returns an Angle derived from radians.
Parameters:
| Name | Type | Description |
|---|---|---|
rac |
Rac
|
Instance to pass along to newly created objects |
radians |
number
|
The measure of the angle, in radians |
add(angle) → {Rac.Angle}
Returns a new Angle with the sum of this and the angle derived from
angle.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
Rac.Angle
|
number
|
An |
degrees() → {number}
Returns the measure of the angle in degrees.
distance(angle, clockwiseopt) → {Rac.Angle}
Returns a new Angle that represents the distance from this to the
angle derived from angle.
rac.Angle(1/4).distance(1/2, true) // turn is 1/2
rac.Angle(1/4).distance(1/2, false) // turn in 3/4
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
angle |
Rac.Angle
|
number
|
An |
||
clockwise |
boolean
|
<optional> |
true |
The orientation of the measurement |
equals(angle) → {boolean}
Returns true when the difference with the turn value of the angle
derived from angle is under
Rac#unitaryEqualityThreshold, otherwise returns false.
For this method otherAngle can only be Angle or number, any other
type returns false.
This method will consider turn values in the oposite ends of the range
[0,1) as equals. E.g. Angle objects with turn values of 0 and
1 - rac.unitaryEqualityThreshold/2 will be considered equal.
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
Rac.Angle
|
number
|
An |
inverse() → {Rac.Angle}
Returns a new Angle pointing in the opposite direction to this.
rac.Angle(1/8).inverse() // turn is 1/8 + 1/2 = 5/8
rac.Angle(7/8).inverse() // turn is 7/8 + 1/2 = 3/8
mult(factor) → {Rac.Angle}
Returns a new Angle with turn`` set to this.turn * factor`.
Parameters:
| Name | Type | Description |
|---|---|---|
factor |
number
|
The factor to multiply |
multOne(factor) → {number}
Returns a new Angle with turn set to
this.turnOne() * factor.
Useful when doing ratio calculations where a zero angle corresponds to a complete-circle since:
rac.Angle(0).mult(0.5) // turn is 0
// whereas
rac.Angle(0).multOne(0.5) // turn is 0.5
Parameters:
| Name | Type | Description |
|---|---|---|
factor |
number
|
The factor to multiply |
negative() → {Rac.Angle}
Returns a new Angle with a turn value equivalent to -turn.
rac.Angle(1/4).negative() // -1/4 becomes turn 3/4
rac.Angle(3/8).negative() // -3/8 becomes turn 5/8
perpendicular() → {Rac.Angle}
Returns a new Angle which is perpendicular to this in the
clockwise orientation.
rac.Angle(1/8).perpendicular(true) // turn is 1/8 + 1/4 = 3/8
rac.Angle(1/8).perpendicular(false) // turn is 1/8 - 1/4 = 7/8
radians() → {number}
Returns the measure of the angle in radians.
shift(angle, clockwiseopt) → {Rac.Angle}
Returns a new Angle result of shifting the angle derived from
angle to have this as its origin.
This operation is the equivalent to
this.add(angle)when clockwisethis.subtract(angle)when counter-clockwise
rac.Angle(0.1).shift(0.3, true) // turn is 0.1 + 0.3 = 0.4
rac.Angle(0.1).shift(0.3, false) // turn is 0.1 - 0.3 = 0.8
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
angle |
Rac.Angle
|
number
|
An |
||
clockwise |
boolean
|
<optional> |
true |
The orientation of the shift |
shiftToOrigin(origin, clockwiseopt) → {Rac.Angle}
Returns a new Angle result of shifting this to have the angle
derived from origin as its origin.
The result of angle.shiftToOrigin(origin) is equivalent to
origin.shift(angle).
This operation is the equivalent to
origin.add(this)when clockwiseorigin.subtract(this)when counter-clockwise
rac.Angle(0.1).shiftToOrigin(0.3, true) // turn is 0.3 + 0.1 = 0.4
rac.Angle(0.1).shiftToOrigin(0.3, false) // turn is 0.3 - 0.1 = 0.2
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
origin |
Rac.Angle
|
number
|
An |
||
clockwise |
boolean
|
<optional> |
true |
The orientation of the shift |
subtract(angle) → {Rac.Angle}
Returns a new Angle with the angle derived from angle
subtracted to this.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
Rac.Angle
|
number
|
An |
toString(digitsopt) → {string}
Returns a string representation intended for human consumption.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
digits |
number
|
<optional> |
null |
The number of digits to print after the decimal point, when ommited all digits are printed |
turnOne() → {number}
Returns the turn value in the range (0, 1]. When turn is equal to
0 returns 1 instead.