Angle Class

An Angle carries the numeric value of an angle, with methods to allow (require!) callers to be clear about whether their angle is degrees or radians.

  • The numeric value is private, and callers should not know or care whether it is in degrees or radians.
  • The various access method are named so that callers can specify whether untyped numbers passed in or out are degrees or radians.

Implements

Methods

Name Description
addMultipleOf2PiInPlace(multiple: number): void Add a multiple of a full circle angle (360 degrees, 2PI) in place.  
clone(): Angle Return a new angle with the same content.  
cloneScaled(scale: number): Angle Return a (new) Angle object, with angle scaled from existing angle.  
cos(): number Return the cosine of this Angle object's angle.  
freeze(): void Freeze this instance so it can be considered read-only  
isAlmostEqual(other: Angle): boolean Test if two angle (in radians) almost equal, NOT allowing shift by full circle multiples of 2 * PI.  
isAlmostEqualAllowPeriodShift(other: Angle): boolean Test if this angle and other are equivalent, allowing shift by full circle (i.e.  
isAlmostEqualNoPeriodShift(other: Angle): boolean Test if two this angle and other are almost equal, NOT allowing shift by full circle multiples of 360 degrees.  
setDegrees(degrees: number): void Set this angle to a value given in degrees.  
setFrom(other: Angle): void Copy all contents of other to this Angle.  
setFromJSON(json?: AngleProps, defaultValRadians?: number): void set an Angle from a JSON object  
setRadians(radians: number): void Set this angle to a value given in radians.  
sin(): number Return the sine of this Angle object's angle.  
tan(): number Return the tangent of this Angle object's angle.  
toJSON(): AngleProps Convert an Angle to a JSON object as a number in degrees  
toJSONRadians(): AngleProps Return a json object with radians keyword, e.g.  
adjustDegrees0To360(degrees: number): number Static Adjust a radians value so it is positive in 0..360  
adjustDegreesSigned180(degrees: number): number Static Adjust a radians value so it is positive in -180..180  
adjustRadians0To2Pi(radians: number): number Static Adjust a radians value so it is positive in 0..2Pi  
adjustRadiansMinusPiPlusPi(radians: number): number Static Adjust a radians value so it is positive in -PI..PI  
cleanupTrigValue(value: number, tolerance: number = 1e-15): number Static If value is close to -1, -0.5, 0, 0.5, 1, adjust it to the exact value.  
create360(): Angle Static Create an angle for a full circle.  
createAtan2(numerator: number, denominator: number): Angle Static    
createDegrees(degrees: number): Angle Static Return a new Angle object for angle given in degrees.  
createDegreesAdjustPositive(degrees: number): Angle Static Create an angle object with degrees adjusted into 0..360.  
createDegreesAdjustSigned180(degrees: number): Angle Static Create an angle object with degrees adjusted into -180..180.  
createRadians(radians: number): Angle Static Return a (new) Angle object for a value given in radians.  
degreesToRadians(degrees: number): number Static Convert an angle in degrees to radians.  
dotProductsToHalfAngleTrigValues(dotUU: number, dotVV: number, dotUV: number, favorZero: boolean = true): TrigValues Static Return the half angle cosine, sine, and radians for given dot products between vectors.  
fromJSON(json?: AngleProps, defaultValRadians?: number): Angle Static Create an Angle from a JSON object  
isAlmostEqualRadiansAllowPeriodShift(radiansA: number, radiansB: number): boolean Static Test if two radians values are equivalent, allowing shift by full circle (i.e.  
isAlmostEqualRadiansNoPeriodShift(radiansA: number, radiansB: number): boolean Static Test if two angle (in radians) almost equal, NOT allowing shift by full circle multiples of 2 * PI.  
isFullCircleRadians(radians: number): boolean Static Test if a radians (absolute) value is nearly 2PI or larger (!)  
isHalfCircleRadians(radians: number): boolean Static Test if the radians value is a complete circle  
isPerpendicularDotSet(dotUU: number, dotVV: number, dotUV: number): boolean Static Test if dot product values indicate non-zero length perpendicular vectors.  
radiansBetweenVectorsXYZ(ux: number, uy: number, uz: number, vx: number, vy: number, vz: number): number Static * Returns the angle between two vectors, with the vectors given as xyz components  
radiansToDegrees(radians: number): number Static Convert an angle in radians to degrees.  
trigValuesToHalfAngleTrigValues(rCos2A: number, rSin2A: number): TrigValues Static Return cosine, sine, and radians for the half angle of a cosine,sine pair.  
zero(): Angle Static return a (newly allocated) Angle object with value 0 radians  

Properties

Name Type Description
degrees Accessor ReadOnly number Return the angle measured in degrees.  
degreesPerRadian Static number scale factor for converting degrees to radians  
isAlmostNorthOrSouthPole Accessor ReadOnly boolean Test if the angle is almost a north or south pole (within tolerance Geometry.smallAngleRadians)  
isAlmostZero Accessor ReadOnly boolean Test if the angle is almost zero (within tolerance Geometry.smallAngleRadians)  
isExactZero Accessor ReadOnly boolean Test if the angle is exactly zero.  
isFullCircle Accessor ReadOnly boolean test if the angle is aa full circle  
isHalfCircle Accessor ReadOnly boolean test if the angle is a half circle (in either direction)  
pi2Radians Static 6.283185307179586 maximal accuracy value of 2*pi (360 degrees), in radians  
piOver12Radians Static 0.26179938779914946 maximal accuracy value of pi/12 ( 15 degrees), in radians  
piOver2Radians Static 1.5707963267948966 maximal accuracy value of pi/2 ( 90 degrees), in radians  
piOver4Radians Static 0.7853981633974483 maximal accuracy value of pi/4 ( 45 degrees), in radians  
piRadians Static 3.141592653589793 maximal accuracy value of pi ( 180 degrees), in radians  
radians Accessor ReadOnly number Return the angle measured in radians.  
radiansPerDegree Static number scale factor for converting radians to degrees  

Defined in

Last Updated: 13 June, 2024