【问题标题】:Intersection point between circle and line (Polar coordinates)圆与直线的交点(极坐标)
【发布时间】:2018-05-30 02:47:52
【问题描述】:

我想知道是否有一种方法可以找到用极坐标书写的直线和圆之间的交点。

% 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 比较陌生,所以请耐心等待。

【问题讨论】:

    标签: matlab line geometry intersection


    【解决方案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

    【讨论】:

      【解决方案2】:

      你需要用数字来做吗?这个问题有一个简单的解析解:点(10 + r*cos(th),10 + r*sin(th))在一个半径为Riff的圆上

      (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 &gt;= 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 的示例。洋红色标记是使用上面显示的公式以封闭形式计算的。

      【讨论】:

      • 用数学打败我!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多