0

2Dグラフィックスについて学習していて、円を描画しようとしていますが、奇妙な曲線が表示されます。

function rotatePoint (point, centerPoint, theta) {
    point[0] = point[0] - centerPoint[0];
    point[1] = point[1] - centerPoint[1];
    point[0] = point[0]*Math.cos(theta)-point[1]*Math.sin(theta);
    point[1] = point[0]*Math.sin(theta)+point[1]*Math.cos(theta);
    point[0] = point[0] + centerPoint[0];
    point[1] = point[1] + centerPoint[1];
}

数式は問題ないようですが...わかりません、理解できません:/...助けてくれてありがとう。 http://jsfiddle.net/nQvGT/173/

4

1 に答える 1

1

一方の値を変更し、それをもう一方の値の計算に使用します。最初に元の値を使用して両方の値を計算してから、それらを設定する必要があります。

var p0 = point[0]*Math.cos(theta)-point[1]*Math.sin(theta);
var p1 = point[0]*Math.sin(theta)+point[1]*Math.cos(theta);
point[0] = p0;
point[1] = p1;

デモ: http: //jsfiddle.net/Guffa/nQvGT/174/

于 2013-03-25T13:33:43.383 に答える