/ (プラスand )で始まり、回転先/を計算するこの優れた質問と回答を見つけました。この計算は完全に機能しますが、逆方向に実行したいと思います。/とから始めて、元の/とを計算したいと思います。x
y
center x/y
degrees/radians
x'
y'
x'
y'
degrees/radians
x
y
center x/y
(x', y') = new position
(xc, yc) = center point things rotate around
(x, y) = initial point
theta = counterclockwise rotation in radians (radians = degrees * Pi / 180)
dx = x - xc
dy = y - yc
x' = xc + dx cos(theta) - dy sin(theta)
y' = yc + dx sin(theta) + dy cos(theta)
または、JavaScript/jQuery では:
XYRotatesTo = function($element, iDegrees, iX, iY, iCenterXPercent, iCenterYPercent) {
var oPos = $element.position(),
iCenterX = ($element.outerWidth() * iCenterXPercent / 100),
iCenterY = ($element.outerHeight() * iCenterYPercent / 100),
iRadians = (iDegrees * Math.PI / 180),
iDX = (oPos.left - iCenterX),
iDY = (oPos.top - iCenterY)
;
return {
x: iCenterX + (iDX * Math.cos(iRadians)) - (iDY * Math.sin(iRadians)),
y: iCenterY + (iDX * Math.sin(iRadians)) + (iDY * Math.cos(iRadians))
};
};
上記の数学/コードは、図 A の状況を解決します。/ (赤い円)、(青い星)、および の既知の値に基づいて、目的地x'
/ (緑の円)の位置を計算します。y'
x
y
center x/y
degrees/radians
しかし、図 B を解くには数学/コードが必要です。ここで、目的地x
/ y
(緑色の円) だけでなく、目的地center x/y
(緑色の星) も、開始x
/ y
(灰色の円、おそらく必要ではありません)、目的地x'
/ y'
(赤い円)、および の既知の値から見つけることができますdegrees/radians
。
上記のコードは、宛先x
/ y
(緑色の円) を介して解決します ( iDegrees * -1
@andrew cook の回答のおかげで、彼によって削除されました) が、それを行うには、宛先の場所center x/y
(緑色の星) を入力する必要があります) であり、以下の図 C でわかるように、これが現在不足している計算です。
では、座標?
/ ?
(緑の星) n
、A
(角度) およびx'
/ y'
(赤い円) をどのように見つけるのでしょうか?