Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created June 7, 2020 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netsi1964/5a719bc9e993cce6cd40b1e12f2507d1 to your computer and use it in GitHub Desktop.
Save netsi1964/5a719bc9e993cce6cd40b1e12f2507d1 to your computer and use it in GitHub Desktop.
Some useful extenstions to javascript
Object.prototype.rad = (deg) => Math.PI/180 * deg;
Object.prototype.deg = (rad) => 180/Math.PI * rad;
Object.prototype.getAngle = (point1, point2) => Math.atan2(point1.y - point2.y, point1.x - point2.x);
Object.prototype.getDistance = (point1, point2) => Math.sqrt(Math.pow(point1.x-point2.x, 2) + Math.pow(point1.y-point2.y, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment