简体   繁体   English

在曲线上找到最接近给定点的点

[英]Find the point on a curve which is closest to a given point

在此处输入图片说明

I have a curve cutting through my mesh in 2D. 我在2D中有一条曲线贯穿我的网格。 It is a moving to the front with time. 随着时间的流逝,这是向前迈进的一步。 I have set of points on this curve (front) and my nodes on the mesh. 我在这条曲线(前面)上有一组点,在网格上有我的节点。 At each time step I need to find which point on the curve (front) is closest to the nodes on my mesh. 在每个时间步骤中,我需要找到曲线上的哪个点(前面)最接近我的网格上的节点。 In other words for each node in my mesh I would like to know which point on the curve is closest to it. 换句话说,对于网格中的每个节点,我想知道曲线上的哪个点最接近它。 Is there a built in MATLAB function to search for this ? 是否有内置的MATLAB函数来搜索? (I am using MATLAB environment) (我正在使用MATLAB环境)

In the figure the question would be which one is the closest black circle to any of the yellow squares. 在图中,问题是哪个圆圈是最接近任何黄色正方形的黑色圆圈。

Here is an efficient function to calculate pairwise distances: 是计算成对距离的有效函数:

function D = sqDistance(X, Y)
    D = bsxfun(@plus,dot(X,X,1)',dot(Y,Y,1))-2*(X'*Y);
end

Assuming circles are the coordinates of the black circles and squares the coordinates of the yellow squares as you described, you can do the following: 假设circles是黑色圆圈和坐标squares如你所说,你可以做以下的黄色方格坐标:

% example matrices
circles = rand(5,2);
squares = rand(8,2);

D = sqDistance(squares', circles');    
[~,idx] = sort(D, 2)

closest_points = circles(idx(:,1),:)

closest_points has the same dimension as squares and stores the coordinates of the closest circle for every yellow square. closest_points的点与squares具有相同的尺寸,并为每个黄色正方形存储最近的圆的坐标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM