LoginSignup
0
0

More than 3 years have passed since last update.

【JavaScript】数値

Last updated at Posted at 2019-06-01

2点間の距離をもとめる

概要

2点間の距離をもとめる。

スクリプト

var distance = function(dot1, dot2) { //2点間の距離
    var x1 = dot1[0],
        y1 = dot1[1],
        x2 = dot2[0],
        y2 = dot2[1];
    return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
};

使用方法

var d = distance([0,0], [100,100]);

2点間の角度を調べる

概要

2点間の角度を調べる

スクリプト

function getAngle(x1,y1,x2,y2){
    // p1(x1,y1)とp2(x2,y2)の差を計算
    xDis = x2-x1;
    yDis = y2-y1;
    // そこから角度(ラジアン表記)を計算
    radian = Math.atan2(yDis, xDis);
    // ラジアンを角度に変換
    angle = radian/(Math.PI/180);
    return angle;
}

使用方法

var angle = getAngle(0,0,100,100);

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0