最初に-あなたが何をしようとしているのかを理解するのに10分ほど費やしましたが(最終的には、回答の1つのコメントから得ました)、問題の解決には2分かかりました。そのため、今後の参考のために、最初に問題をできるだけ明確に説明してください。
今、私はあなたのサインが台無しになっていると思います。次のことを試してください。
%// difference vector
%// NOTE: these go the other way around for the atan2 to come out right
dx = px - cx;
dy = py - cy;
%// tip angle of the right triangle
a = asin( 5 / sqrt(dx*dx + dy*dy) );
%// angle between the (local) X-axis and the line of interest
b = atan2(dy, dx);
%// the third angle in the right triangle
%// NOTE: minus a here instead of plus b
g = pi/2 - a;
%// Angles of interest
%// NOTE1: signs are flipped; this automatically takes care of overshoots
%// NOTE2: don't forget to mod 360
t_1 = mod( rad2deg(b - g), 360)
t_2 = mod( rad2deg(b + g), 360)
または、代わりに をa
使用して、中間角度の計算をスキップできます。acos
asin
%// difference vector
dx = px - cx;
dy = py - cy;
%// Directly compute the third angle of the right triangle
%// (that is, the angle "at the origin")
g = acos( 5 / sqrt(dx*dx + dy*dy) );
%// angle between the (local) X-axis and the line of interest
b = atan2(dy, dx);
%// Angles of interest
t_1 = mod( rad2deg(b - g), 360)
t_2 = mod( rad2deg(b + g), 360)
三角関数の恒等式 を再発見するもう 1 つの方法acos(x) = pi/2 - asin(x)
:)