An error while using polyxpoly for finding (xi,yi) of an intersecting line and circle

조회 수: 4 (최근 30일)
Hello,
I need to connect point 2 and point 1 and find all the intersecting points(between red line and blue line/circle), So, I used polyxpoly. My problem is why polyxpoly function generates an extra intersecting point which is not on the line or the circle (I show it in the below image)?
My data
%Data
clear variables
clc
% points
x_points=[1;3];
y_points=[1;5];
% line coordinates
x_line=[3;2];
y_line=[3;5];
% Circle coordinates
xcenter = 2;
ycenter = 2;
radius = 1;
circr = @(radius,rad_ang) [radius*cos(rad_ang)+xcenter; radius*sin(rad_ang)+ycenter];
N = 2000;
rad_ang = linspace(0, 2*pi, N);
xy_r = circr(radius,rad_ang);
x_circle= radius * cos(rad_ang) + xcenter;
y_circle= radius * sin(rad_ang) + ycenter;
circle=round([x_circle',y_circle'],2);
% all points
All(:,1)=[x_points;x_line];
All(:,2)=[y_points;y_line];
% I want to calculate the intersection coordinates between a line contacting curret point/next point and
% circle/line
current_point=2
next_point=1
[xi,yi]=polyxpoly(All([next_point;current_point],1),...
All([next_point;current_point],2),[x_line;circle(:,1)], [y_line;circle(:,2)])

채택된 답변

Pratyush Roy
Pratyush Roy 2020년 10월 1일
Hi,
The x co-ordinates as well as the y co-ordinates of the line and the circle should not be combined as this generates a complicated polygon and a new solution is found other than the expected ones.
As a workaround one can use the polyxpoly function twice to generate two sets of solutions which together will provide the expected solution.
[xi,yi]= polyxpoly(All([next_point;current_point],1),...
All([next_point;current_point],2),circle(:,1),circle(:,2));
[xj,yj]=polyxpoly(All([next_point;current_point],1),...
All([next_point;current_point],2),x_line,y_line);
Here [xi,yi] will give us the points of intersection between the line and the circle and [xj,yj] will give us the point of intersection between the two lines.
Hope this helps!
  댓글 수: 1
Zarak kh
Zarak kh 2020년 10월 9일
Dear Pratyush,
Thanks a lot for your help, it is indeed helpfull. According to your explanation is it okay to also add "NaN" in polyxpoly function like below?
[xi,yi]=polyxpoly(All([next_point;current_point],1),...
All([next_point;current_point],2),[x_line;NaN;circle(:,1)], [y_line;NaN;circle(:,2)])

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by