Skip to content
y-lohse edited this page Jan 2, 2013 · 3 revisions

Contains a couple of utility math functions.

List of functions

Functions

randomIn:Float

Parameters

  • min:Number : lower treshhold to use
  • max:Number : upper treshhold to use

Description

Computes a random value between 2 values (included)

hexToDec:Integer

Parameters

  • value:Number : hexadecimal value to convert

Description

Converts a hexadecimal value into a decimal one

decToHex:Integer

Parameters

  • value:Number : decimal value to convert

Description

Converts a decimal value into a hexadecimal one

radiansToDegrees:Float

Parameters

  • value:Number : value to be converted

Description

Converts a radian value into degrees

degreesToRadians:Float

Parameters

  • value:Number : value to be converted

Description

Converts a value in degrees into radians

distance:Float

Parameters #1

  • x1:Number
  • y1:Number
  • x2:Number
  • y2:Number

Parameters #2

  • a:Point
  • b:Point

Description

Computes the distance between two points using Pythagora. Alternatively, the 2 first arguments can be points with x and y properties.

Examples

Both work :

Cannon.Utils.distance(0, 0, 10, 10);

and

Cannon.Utils.distance({x: 0, y: 0], {x: 10, y: 10});