我已經概括了下面這樣其他值比a=10
可用於...
a = 10; % constant line offset
th = 0; % constant angle of line
% rl = ?? - variable to find
% Coordinates of line:
% [xl, yl] = [ a + rl * cos(th), a + rl * sin(th) ];
rc = 1; % constant radius of circle
% alpha = ?? - variable to find
% Coordinates of circle:
% [xc, yc] = [ rc * cos(alpha), rc * sin(alpha) ];
我們想要的交集,所以xl = xc
,yl = yc
% a + rl * cos(th) = rc * cos(alpha)
% a + rl * sin(th) = rc * sin(alpha)
廣場兩個等式的兩邊並將它們相加。簡化sin(a)^2 + cos(a)^2 = 1
。擴展支架和進一步簡化給
% rl^2 + 2 * a * rl * (cos(th) + sin(th)) + 2 * a - rc^2 = 0
現在你可以使用二次公式得到的rl
值。
測試判別:
dsc = (2 * a * (cos(th) + sin(th)))^2 - 4 * (2 * a - rc^2);
rl = [];
if dsc < 0
% no intersection
elseif dsc == 0
% one intersection at
rl = - cos(th) - sin(th);
else
% two intersection points
rl = -cos(th) - sin(th) + [ sqrt(dsc)/2, -sqrt(dsc)/2];
end
% Get alpha from an earlier equation
alpha = acos((a + rl .* cos(th)) ./ rc);
現在你有與圓線的交叉點,約每行某些已知和未知值的0,1或2分。本質上,這只是聯立方程式,請參閱本文的開始部分,作爲數學基礎 https://en.wikipedia.org/wiki/System_of_linear_equations
擊敗我的數學! – Wolfie