[英]Intersection point between circle and line (Polar coordinates)
我想知道是否有一种方法可以找到用极坐标表示的直线和圆之间的交点。
% 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比较陌生,请耐心等待。
我对以下内容进行了概括,以便可以使用a=10
以外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
您需要数字进行吗? 这个问题将有一个简单的解析解决方案:点(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为例。洋红色标记是使用上述方程式以封闭形式计算的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.