Skip to content

SamuelB2020/inclination

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

inclination

Coverage Status Build Status
A library for working with angles.

Usage

Basic Usage

const Angle = require('../index');
var angleA = new Angle("90d");
console.log(angleA.degrees);
// 90
console.log(angleA.radians);
// 1.5707963267948966

Defining an Angle

By 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");

Properties

Angle.degrees

Returns the angle in degrees

var angleBCA = new Angle("30d");
console.log(angleBCA.degrees);
// 30

Angle.radians

Returns the angle in radians

var angleBCA = new Angle("30d");
console.log(angleBCA.radians);
// 0.5235987755982988

Angle.turns

Returns the angle in turns

var angleBCA = new Angle("30d");
console.log(angleBCA.turns);
// 0.08333333333333333

Angle.gons

Returns the angle in gons/gradians

var angleBCA = new Angle("30d");
console.log(angleBCA.gons);
// 33.33333333333333

Functions

Angle.principleAngle()

Returns a new angle within the bounds -180° to 180° (-π to π).

var angleBCA = new Angle("200d");
var angleBCAPrinciple = angleBCA.principleAngle();
console.log(angleBCAPrinciple.degrees)
// -160

Angle.Normalize()

Returns 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)
// 40

Angle.sin()

Returns the sine of the angle.

var angleBCA = new Angle("90d");
console.log(angleBCA.sin())
// 1

Angle.cos()

Returns the cosine of the angle.

var angleBCA = new Angle("180d");
console.log(angleBCA.cos())
// -1

Angle.tan()

Returns the tangent of the angle.

var angleBCA = new Angle("0d");
console.log(angleBCA.tan())
// 0

Angle.quadrant()

Returns 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())
// 1

Angle.cardinalDirection()

Returns 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())
// N

Angle.IntercardinalDirection()

Returns 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())
// NE

Angle.Between(a,b)

Returns 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))
// true

Angle.fromXY(x,y)

Returns 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

About

A library for working with angles.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published