フィルターのクリア

How to find point closest to multiple circles?

11 ビュー (過去 30 日間)
Bas Wagemaker
Bas Wagemaker 2019 年 1 月 31 日
コメント済み: Bas Wagemaker 2019 年 1 月 31 日
Hi!
I want to solve the following problem using Matlab:
In the xy-plane, I have multiple circles, defined by their midpoint and their radius. Some of the circles overlap, others dont.
Now, I want to find a point A in the xy-plane that is closest to all circles.
So in other words: I want to find the point A for which the sum of distances to a point (it does not matter which) on each of the circles is minimal.
Does anyone know how to do this?
Edit:
To clarify my question: the circles can also be completely inside another circle. I added two images of two example situations. In both situations, I want to find point A. Question2.jpg
Question1.jpg
Thanks!
Bas
  4 件のコメント
Image Analyst
Image Analyst 2019 年 1 月 31 日
I have the same question as Jan. And your latest comment did not answer his or my questions.
What does distance of your point to a circle mean?
  1. Distance to the center?
  2. Or the perimeter points?
If it's the center, maybe just averaging the centers will be where you want it. If it's to the perimeter points, then be aware that the radii will affect the answer since there will be more perimeter points on a larger circle, so their distances will give a greater sum than for a small circle.
Bas Wagemaker
Bas Wagemaker 2019 年 1 月 31 日
Hi!
I defined the distance that we are talking about as the distance between the point and one of the perimeter points of each circle. The distance to the center would be easier, since this is one single point per circle, instead of a set.
Since all of you have helped me a lot, I think you deserve some background information. The question is related to my Mechanical Engineering Masters thesis. In fact, the centers of the circles represent points at which one end of a mechanical spring is attached, for different positions of a lever arm. The length of the spring is determined by the required energy in the spring per position. The radius of each circle is equal to the required spring length in each position.
Ideally, all circles intersect in one point, which would be the optimal attachment point of the other end spring (this is why I defined the distance to be the distance between the point and the perimeter). However, in most cases, this ideal point does not exist, and I was therefore looking for the point that is closest to the non-existing intersection point.
Thanks again for your help!

サインインしてコメントする。

採用された回答

Matt J
Matt J 2019 年 1 月 31 日
編集済み: Matt J 2019 年 1 月 31 日
Let C be a 1x2xN matrix of the circle centers and R an 1x1xN vector of their radii. It is a low-dimensional, non-smooth minimization problem so, I would use fminsearch:
rownorm=@(z) sqrt( sum(z.^2,2) );
fun=@(A) sum( rownorm( (A-C) - (A-C).*R./rownorm(A-C)) , 3 ); %edited
A = fminsearch(fun,A0(:).');
Luckily, it is only a 2D problem, so you can come up with a decent initial guess A0 using a brute force grid search, e.g.,
[X,Y]=ndgrid(linspace(-1,1,100)); %adjust grid limits depending on C and R
Agrid=[X(:),Y(:)];
[~,gridmin]=min( fun(Agrid) );
A0=Agrid(gridmin,:);
  10 件のコメント
Bas Wagemaker
Bas Wagemaker 2019 年 1 月 31 日
Thanks, it works like a charm!
Could you please explain what the fun function does?
Matt J
Matt J 2019 年 1 月 31 日
You're welcome. Please Accept-click the answer, though, to certify that it addresses the problem.
fun is the thing you are trying to minimize. It computes the sum of the distances from A to your circles.
Capture.PNG

サインインしてコメントする。

その他の回答 (2 件)

Jim Riggs
Jim Riggs 2019 年 1 月 31 日
Personally, I would use a numerical searcing algorithm.
Overlay a grid on the problem space, then compute the distance function (sum of distance to all circles) from each grid point.
Select the minimum value, then refine the grid and search from the minimum point.
Continue until the desired numerical precision is schieved.
Distance function is the sum of distance from Point P, to each circle. If P is outside the circle, then the distance to that circle is the distance from P to the circle center, minus the circle radius, but if P is inside the circle (Distance from P to the center is less than the radius) then the distance to the circle is the radius minus the distance from P to the center.
  2 件のコメント
Jan
Jan 2019 年 1 月 31 日
The grid search will fail for a set of concentric circles, because you will get a circle as solution, not a single point.
Bas Wagemaker
Bas Wagemaker 2019 年 1 月 31 日
Hi!
Thanks for your reply.
Indeed, while I was writing this question, I thought about the same solution. However, imagine that I define each circle by 100 points. And I have a grid of 10x10 points. Supposing I have six circles and I want to evaluate every point in my grid, I have to calculate the distance between each of the grid points and each point on the six circles. This results in 100*6*100=60.000 calculations, without any refinement steps. I do not know how fast Matlab can do this..
Do you know any efficient way to do this?
Thanks!

サインインしてコメントする。


Jan
Jan 2019 年 1 月 31 日
編集済み: Jan 2019 年 1 月 31 日
A simple grid search with loops - just for demonstration:
% Define circles:
nCircle = 10;
Center = rand(nCircle, 2);
Radius = rand(nCircle, 1) / 5;
% To show that result is not unique:
% nCircle = 3;
% Center = repmat(0.5, nCircle, 2);
% Radius = [0.5, 1, 1.5];
% Get distances on a 50x50 grid:
nGrid = 50;
gridv = linspace(0, 1, nGrid);
Dist = zeros(nGrid, nGrid);
axes('NextPlot', 'add');
view(3)
for ix = 1:nGrid
x = gridv(ix);
for iy = 1:nGrid
y = gridv(iy);
D = 0;
for iC = 1:nCircle
D = D + abs(sqrt((x - C(iC, 1))^2 + (y - C(iC, 2))^2) - R(iC));
end
Dist(ix, iy) = D;
end
end
% Draw sum of distances:
surf(gridv, gridv, Dist.' - min(Dist(:)), 'FaceAlpha', 0.5);
% Draw the circles
v = linspace(0, 2*pi, 50);
for iC = 1:nCircle
line(C(iC, 1) + sin(v) * R(iC), C(iC, 2) + cos(v) * R(iC));
end
Grafics for 3 concentric circles:
Clipboard-1.png
  1 件のコメント
Bas Wagemaker
Bas Wagemaker 2019 年 1 月 31 日
Thanks!
I like the visual representation of the distance! I will certainly look into your example code to implement it in mine.
Have a nice evening!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by