A library for working with angles.
const Angle = require('../index');
var angleA = new Angle("90d");
console.log(angleA.degrees);
// 90
console.log(angleA.radians);
// 1.5707963267948966By default an angle is defined in degrees for example the below code defines an angle of 70°
var angleABC = new Angle(70);Angles can be defined though as a string with a letter denoting their units.
Degrees
var angleABC = new Angle("70d");Radians
var angleABC = new Angle("3r");Note.
Exact values with radians can be achieved with the following
var exact = Math.PI/2;
var angleABC = new Angle(exact+"r");Turns
var angleABC = new Angle("0.5t");Gons/Gradians
var angleABC = new Angle("300g");Returns the angle in degrees
var angleBCA = new Angle("30d");
console.log(angleBCA.degrees);
// 30Returns the angle in radians
var angleBCA = new Angle("30d");
console.log(angleBCA.radians);
// 0.5235987755982988Returns the angle in turns
var angleBCA = new Angle("30d");
console.log(angleBCA.turns);
// 0.08333333333333333Returns the angle in gons/gradians
var angleBCA = new Angle("30d");
console.log(angleBCA.gons);
// 33.33333333333333Returns a new angle within the bounds -180° to 180° (-π to π).
var angleBCA = new Angle("200d");
var angleBCAPrinciple = angleBCA.principleAngle();
console.log(angleBCAPrinciple.degrees)
// -160Returns a new angle within the bounds 0° to 360° (0 to 2π).
var angleBCA = new Angle("400d");
var angleBCAPrinciple = angleBCA.Normalize();
console.log(angleBCAPrinciple.degrees)
// 40Returns the sine of the angle.
var angleBCA = new Angle("90d");
console.log(angleBCA.sin())
// 1Returns the cosine of the angle.
var angleBCA = new Angle("180d");
console.log(angleBCA.cos())
// -1Returns the tangent of the angle.
var angleBCA = new Angle("0d");
console.log(angleBCA.tan())
// 0Returns the quadrant number of the angle. If the angle is a boundary angle e.g. 90°, -1 will be returned.
var angleBCA = new Angle("45d");
console.log(angleBCA.quadrant())
// 1Returns the cardinal direction (N, S, E, W) of an angle. If the angle is not a cardinal direction -1 will be returned.
var angleBCA = new Angle("0d");
console.log(angleBCA.cardinalDirection())
// NReturns the Intercardinal direction (N, S, E, W, NE, NW, SE, SW) of an angle. If the angle is not a intercardinal direction -1 will be returned.
var angleBCA = new Angle("45d");
console.log(angleBCA.IntercardinalDirection())
// NEReturns a boolean if the angle lies between two other angles a and b. Note if the angles are equal it will return true.
var angleBCA = new Angle("45d");
var angleABC = new Angle("0d");
var angleDCA = new Angle("90d")
console.log(angleBCA.between(angleABC,angleDCA))
// trueReturns the angle formed by the right triangle with base x and height y
var angleBCA = new Angle().fromXY(3,3)
console.log(angleBCA.degrees)
// 45