Does anyone know how to use the matlab to calculate the minimu distance between a point outside oval and the oval surface?

16 ビュー (過去 30 日間)
Does anyone know how to use the matlab to calculate the minimu distance between a point outside oval and the oval surface?
  3 件のコメント
Image Analyst
Image Analyst 2020 年 6 月 28 日
編集済み: Image Analyst 2020 年 6 月 28 日
bwdist() perhaps?
huazai2020
huazai2020 2020 年 6 月 29 日
The oual can be both given in the form of an equation or data points. How to use the bwdist(), could you share me the code?

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

採用された回答

Matt J
Matt J 2020 年 6 月 30 日
編集済み: Matt J 2020 年 6 月 30 日
You can use trustregprob from the File Exchange
For example, consider the following ellipse and external point y,
A=[2 1;1,2]; %Ellipse equation matrix
y=[1;0.5]; %External point
z=[0.584808315593597 ; 0.201052451754066]; %Closest point
ellipsefun=@(p,q) sum([p;q].*(A*[p;q]))-1 ;
hold on
fimplicit(ellipsefun, [-1 1.3 -1 1.3])
plot(y(1),y(2),'rx',z(1),z(2),'bo');
axis equal
hold off
I found the closest point z using the code below,
Aroot=chol(A);
L=Aroot\eye(2);
z=Aroot\trustregprob(L.'*L, L.'*y,1);
and the minimum distance is just,
>> distance=norm(z-y)
distance =
0.5116
  20 件のコメント
huazai2020
huazai2020 2020 年 7 月 7 日
What is FEX AND H1? Are they these?
Find the projection of point P in R^n on the ellipsoid
E = { x = x0 + U*(z.*radii) : |z| = 1 }, where U is orthogonal matrix of the orientation of E, radii are the axis lengths, and x0 is the center.
Or on generalized conic E = { x : x'*A*x + b'*x + c = 0 }.
The projection is the minimization problem:
min | x - P | (or max | x - P|) for x in E.
Method: solve the Euler Lagrange equation with respect to the Lagrange multiplier, which can be written as polynomial equation (from an idea by Roger Stafford)
Bruno Luong
Bruno Luong 2020 年 7 月 8 日
FEX short word for File Exchange. Click on it I put the link on my message.
H1: https://www.mathworks.com/help/matlab/matlab_prog/add-help-for-your-program.html

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

その他の回答 (2 件)

Image Analyst
Image Analyst 2020 年 7 月 4 日
"The oual can be both given in the form of an equation or data points." <== if you have data points (xb, yb) on the boundary of an ellipse/oval, you can use sqrt() to find the distances to some other point (xp, yp). Then use in() to find the minimum distance.
distances = sqrt(xb-xp).^2 + (yb-yp).^2);
minDistance = min(distances)
If you have an image then you need to get the boundary points first:
boundaries = bwboundaries(binaryImageOfEllipse);
boundaries = boundaries{1}; % Extract double array from cell array.
xb = boundaries(:, 2);
yb = boundaries(:, 1);
  10 件のコメント
Image Analyst
Image Analyst 2020 年 7 月 18 日
No, you shouldn't use an inner loop because your minDistance will just be the distance between (x1,y1) and xwoint(Num2) and ywoint(Num2) instead of the whole array. Do it like this:
clc;
clear all;
A = xlsread('data1.xlsx');
xpoint=A(:,1);
ypoint=A(:,2);
Num1=length(xpoint);
xwoint=A(:,3);
ywoint=A(:,4);
Num2=length(xwoint);
for k=1:1:Num1
x1 = xpoint(k);
y1 = ypoint(k);
distances = sqrt((xwoint-x1).^2 + (ywoint-y1).^2);
minDistance(k) = min(distances)*1000;
end
plot(minDistance, 'b-');
% xlswrite('thick.xlsx',minDistance,'sheet1');
Not sure why you wanted to multiply by 1000 though.
huazai2020
huazai2020 2020 年 7 月 18 日
編集済み: huazai2020 2020 年 7 月 18 日
1000 is only for the unit changing. Thank you so much for your help.

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


Bruno Luong
Bruno Luong 2020 年 7 月 5 日

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2012b

Community Treasure Hunt

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

Start Hunting!

Translated by