JSでの簡易的な座標計算用メモ

function Point(x,y){ //座標(set/get, sum)
    this.x = x; this.y = y;
    this.setPoint=function(x,y){this.x = x;this.y = y;}
    this.getPoint=function(){return this;}
    this.sumPoint=function(point1){this.x+=point1.x; this.y+=point1.y;}
}
//2点の距離
function disPoint(point1,point2){var distance=0;var distance=Math.sqrt(Math.pow(point2.x-point1.x,2)+Math.pow(point2.y-point1.y,2));return distance;}
//2点の角度
function radPoint(point1,point2){var rad;rad=Math.atan2(point1.y-point2.y,point1.x-point2.x);return rad;}
//角度と距離から円周上の座標
function disRotPoint(point1,distance,rotate){var rot_point=new Point(0,0);rot_point.x=point1.x+distance*Math.cos(rotate*Math.PI/180);rot_point.y=point1.y+distance*Math.sin(rotate*Math.PI/180);return rot_point;}
//描画用のcanvas.context回転
function drawRotate(_context,rad,point){_context.setTransform(Math.cos(rad),Math.sin(rad),-Math.sin(rad),Math.cos(rad),point.x,point.y);_context.translate(-1*point.x,-1*point.y);}
//弧度法/度数法 変換
function rad_enc(rot){return (rot*Math.PI/180);}
function rot_enc(rad){return (rad*180/Math.PI);}