knnsearch but with a constraint
1 次查看(过去 30 天)
显示 更早的评论
I have an 11,000x3 array representing x,y,z coordinates of points in 3D space. I want to find the nearest neighbor using knnsearch but with this constraint that the normal vector associated with any pair of points should form an angle larger than 170 degree (I have already calculated the normals).
How can I include this constraint in my knnsearch?
Here's the code so far and I'm trying to use a while loop until the condition is met, but pretty sure, this is not the right way of doing it:
[Idx] =knnsearch (points,points,'K',2, 'Distance',"chebychev"); % find the second nearest point (first point is the point itself)
Idx2=Idx(:,2) %take the index from the second point
sortedN=N(Idx2,:) %sort the normals based on the new inex
angle = transpose (rad2deg (atan2(vecnorm(cross(N',sortedN')), dot(N',sortedN')))) %calculate the angle between the original normal and the sorted normal
% and this is clearly not how one should do a while loop because it doesn't do anything when I run it.... but basically
% I'm trying to tell it to search for the next nearest point until the
% condition is met.
while angle < 170
[Idx, distance] =knnsearch (points,points,'K',i, 'Distance',"chebychev");
i+1
end
% I want to update new index and distance value at the end
0 个评论
回答(1 个)
KSSV
2021-10-29
You can specify the number of points you want from knnsearch. Get as many number of points you want. After calculate the angle and pick the points you want.
I would suggest you to have a look on rangesearch as well.
3 个评论
KSSV
2021-10-29
You have placed the angle outside the loop, you need to update the angle inside the loop after getting each point right?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!