Projecting a dataset on an ellipse

2 ビュー (過去 30 日間)
Salad Box
Salad Box 2022 年 12 月 8 日
コメント済み: Matt J 2022 年 12 月 16 日
Hi,
I fit an ellipse (in green) to my dataset (white dots).
I'd like to project each data point on the ellipse (or shifting each data point onto the ellipse using the shortest distance). Those projections on the ellipse will form a new set of data. How can I achieve this?
  2 件のコメント
Jonas
Jonas 2022 年 12 月 8 日
if you have the ellipse and your x and y corrdinates, use the interp2() function with the 'nearest' interpolation method
Salad Box
Salad Box 2022 年 12 月 12 日
Thank you. I will give it a try.

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

回答 (1 件)

Matt J
Matt J 2022 年 12 月 12 日
This code requires the download of trustregprob from the file exchange
function Xp=ellipseprj(Q,xc,X0)
%Projects given 2D points onto 2D ellipse
%
% Xp=ellipseprj(Q,xc,X0)
%
%IN:
%
% Q,xc: Ellipse equation matrices. Q is 2x2 and xc is 2x1 such that
% ellipse equation is (y-xc).'*Q*(y-xc)=1
% X0: 2xN matrix of points to be projected
%
%OUT:
%
% Xp: 2xN matrix of projected points
N=size(X0,2);
xc=xc(:);
[Rt,D]=eig(Q);
Rt=real(Rt); D=real(D);
iD=diag(1./diag(D));
iDsqrt=sqrt(iD);
b=-iDsqrt*Rt.'*bsxfun(@minus,xc,X0);
Yp=nan(size(X0));
for i=1:N
Yp(:,i)=trustregprob(iD,b(:,i),1);
end
Xp=bsxfun(@plus, Rt*iDsqrt*Yp,xc);
  2 件のコメント
Salad Box
Salad Box 2022 年 12 月 16 日
Thank you for your answer.
% Q,xc: Ellipse equation matrices. Q is 2x2 and xc is 2x1 such that
% ellipse equation is (y-xc).'*Q*(y-xc)=1
I still don't fully understand what Q and xc is.
What do you mean by ellipse equation (y-xc).'*Q*(y-xc)=1?
Matt J
Matt J 2022 年 12 月 16 日
Every ellipse obeys an equation of that form. I've given an example over in your duplicate post,

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by