2017-01-31 347 views
0

我想知道是否有找到一條直線和一個用極座標寫成的圓之間的交點的方法。MATLAB:圓與線之間的交點(極座標)

% Line 
x_line = 10 + r * cos(th); 
y_line = 10 + r * sin(th); 
%Circle 
circle_x = circle_r * cos(alpha); 
circle_y = circle_r * sin(alpha); 

到目前爲止,我已經使用intersect(y_line, circle_y)功能沒有任何成功嘗試。我對MATLAB相對來說比較陌生,對我來說很裸露。

回答

1

我已經概括了下面這樣其他值比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 = xcyl = 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

0

您是否需要以數字形式進行操作?這個問題將有一個簡單的解析解:點(10 + r*cos(th),10 + r*sin(th))是與半徑R圓IFF

(10+r*cos(th))^2 + (10+r*sin(th))^2 == R^2

< =>200+r^2 + 2*r*(cos(th)+sin(th)) == R^2

< =>r^2 + 2*r*sqrt(2)*sin(th+pi/4) + 200 - R^2 = 0

其是r中的二次方程。如果判別式爲正,則有兩個解(對應於兩個交點),否則沒有。

如果算出數學,交點的條件是100*(sin(2*th)-1)+circle_r^2 >= 0,根是-10*sqrt(2)*sin(th+pi/4)*[1,1] + sqrt(100*(sin(2*th)-1)+circle_r^2)*[1,-1]

下面是一個Matlab圖,作爲th = pi/3和circle_r = 15的示例。洋紅色標記是使用上面顯示的等式以閉合形式計算的。

Matlab plot for circle_r = 15, th = pi/3

+0

擊敗我的數學! – Wolfie