LoginSignup
11
8

More than 5 years have passed since last update.

楕円の円周上の x, y 座標を返す

Last updated at Posted at 2015-10-27

楕円の円周上の x, y 座標を返す


/**
 * 楕円の円周上の x, y 座標を返す
 *
 * @param  degree  角度
 * @param  radiusX  横半径
 * @param  radiusY  縦半径
 * @returns {}  x, y を含んだオブジェクト
 */
function getOvalPosition ( degree, radiusX, radiusY ) {
    var obj = {};

    // 0〜360未満に丸める
    degree = (degree % 360 + 360) % 360;

    // ラジアンに変換
    var radian = degree * (Math.PI / 180);
    var cos = Math.cos(radian);
    var sin = Math.sin(radian);

    obj.x = cos*radiusX;
    obj.y = sin*radiusY;

    return obj;
}

円周上の x, y 座標を返す


/**
 * 円周上の x, y 座標を返す
 *
 * @param  degree  角度
 * @param  radius  半径
 * @returns {}  x, y を含んだオブジェクト
 */
function getCirclePosition ( degree, radius ) {
    var obj = {};

    // 0〜360未満に丸める
    degree = (degree % 360 + 360) % 360;

    // ラジアンに変換
    var radian = degree * (Math.PI / 180);
    var cos = Math.cos(radian);
    var sin = Math.sin(radian);

    obj.x = cos * radius;
    obj.y = sin * radius;

    return obj;
}

角度をラジアンに変換

// ラジアン = 角度 * Math.PI / 180
var radian = degree * (Math.PI / 180);

ラジアンを角度に変換

// 角度 = ラジアン * 180 / Math.PI
var degree = radian * 180 / Math.PI
11
8
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
11
8