Math

Math Functions

- Angle Math Functions

These functions convert between angles and rectangular components. All angles are measured in degrees. Positive angles indicate counter-clockwise rotation. A heading angle of 0 degrees points straight right (east) along the positive X axis.

convertToComponents

Converts an angle and length into rectangular vector components.

Returns

array An array [x, y] containing the two vector components

let [x, y] = convertToComponents(45, 2)

convertToAngle

Converts rectangular vector components into an angle in degrees.

Returns

number The heading angle defined by the given vector, in degrees.

let angle = convertToAngle(3,4)

- Other Math Functions

pointInPolygon

Draws a single pixel.

Returns

boolean true if the point is inside the polygon, and false otherwise.

let polygon = [[10, 20], [100, 40], [50, 90]]
if (pointInPolygon(mousex, mousey, polygon)) {
  console.log("mouse is inside the polygon")
}

Last updated