![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292500/image.png)
How to determine if points fall above an arbitrary line?
조회 수: 14 (최근 30일)
이전 댓글 표시
Hello all,
I am trying to find a way to determine if points are above or below an arbitrary line. For example, the code
numXY = randi([1, 19], 1);
lineXs = [0; sort(rand(numXY, 1) * numXY)];
lineYs = rand(size(lineXs));
Xs = rand([100, 1]) * max(lineXs);
Ys = rand(size(Xs));
figure
scatter(Xs, Ys, '.k')
hold on
plot(lineXs, lineYs, 'r')
axis tight
would produce something like
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292496/image.png)
How to determine which of the points in (Xs, Ys) are above or below the red line defined by (lineXs, LineYs)?
Thank you in advance!
댓글 수: 0
채택된 답변
KSSV
2020년 5월 12일
편집: KSSV
2020년 5월 12일
Read about inpolygon.
numXY = randi([1, 19], 1);
lineXs = [0; sort(rand(numXY, 1) * numXY)];
lineYs = rand(size(lineXs));
Xs = rand([100, 1]) * max(lineXs);
Ys = rand(size(Xs));
idx = inpolygon(Xs,Ys,[0 ; lineXs ; max(lineXs)],[ 0 ; lineYs ; 0]) ;
figure
% scatter(Xs, Ys, '.k')
hold on
plot(lineXs, lineYs, 'r')
plot(Xs(idx),Ys(idx),'*k')
plot(Xs(~idx),Ys(~idx),'*r')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292500/image.png)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!