Skip to content

Instantly share code, notes, and snippets.

@turusuke
Created June 16, 2013 05:32
Show Gist options
  • Save turusuke/5790883 to your computer and use it in GitHub Desktop.
Save turusuke/5790883 to your computer and use it in GitHub Desktop.
CreateJSのPointクラスでオブジェクト間の角度を取得できるメソッド getDigree(度数法)とgetRadian(ラジアン)を利用できるようにしたプラグイン。
/**
* User: turusuke
* Date: 13/06/16
* version: 0.1
*/
(function(window) {
if (!createjs || !createjs.Point) {
return;
}
var toDigree = 180 / Math.PI;
/* オブジェクト間の角度を度数法で返す */
createjs.Point.getDigree = function(pt1, pt2){
return Math.atan2( (pt2.y - pt1.y),(pt2.x - pt1.x) ) * toDigree;
}
/* オブジェクト間の角度をラジアンで返す */
createjs.Point.getRadian = function(pt1, pt2){
return Math.atan2( (pt2.y - pt1.y),(pt2.x - pt1.x) );
}
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment