필터 지우기
필터 지우기

How to extract only certain points contained in a segment?

조회 수: 2 (최근 30일)
Gargolla9
Gargolla9 2022년 6월 29일
답변: Image Analyst 2022년 9월 15일
Hi everyone. I have the following problem. I have segments with a series of point.
For each segment I would like to consider only the point which is closest to a certain obstacle and then I would like to save these points in an n x 2 array where the first column of this array represents the x-coordinates of the points and the second column of the array represents the y-coordinates of the points. How can I do it?

답변 (2개)

KSSV
KSSV 2022년 6월 29일
Read about knnsearch
  댓글 수: 2
Gargolla9
Gargolla9 2022년 6월 29일
@KSSV yeah I know knnsearch, but I do not want to use it since i have to use it for another intricate application after in the same code. I was hoping for a more immediate solution
KSSV
KSSV 2022년 6월 29일
You can use it n number of times..what is restricting you?

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


Image Analyst
Image Analyst 2022년 9월 15일
Try this, assuming you have your points in x and y, and your obstacle point is in x0, y0:
distances = sqrt((x - x0) .^ 2 + (y - y0) .^ 2);
[sortedDistances, sortOrder] = sort(distances, 'ascend');
Then you can take however many of the "close" points as you want. Like let's say you want the 9 closest points:
sortedx = x(sortOrder);
sortedy = y(sortOrder);
xClosest = sortedx(1 : 9);
yClosest = sortedy(1 : 9);
Or maybe you just want a list of all distances less than 30:
distances = sqrt((x - x0) .^ 2 + (y - y0) .^ 2);
% Get logical indexes of what points are closer than 30.
closeIndexes = distances < 30;
xClosest = x(closeIndexes);
yClosest = y(closeIndexes);

카테고리

Help CenterFile Exchange에서 Computational Geometry에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by