Change of basis, rotating an ellipse

18 ビュー (過去 30 日間)
Sebastian Daneli
Sebastian Daneli 2021 年 9 月 29 日
コメント済み: Image Analyst 2021 年 9 月 29 日
I though I knew how to do this, apperently i did not. I'm supposted to draw a confidence ellips aroud a cluster of data centered aroud the mean of said cluster. I've figured how to draw the ellipse, now i need to rotate it. I would like to change the basis that I'm working with so that the mean of the cluster becomes my new basis, I'm thinking that would solve the rotational issue? Can anyone help?
data=[191 197 208 180 180 188 210 196 191 179 202 200 192 199 186 197 201 190 209 187 207 178 202 ...
205 190 189 211 216 189 173 194 198 180 190 191 196 207 209 179 186 174 181 189 189;
284 285 273 275 280 283 288 271 257 289 285 272 282 280 266 285 295 282 305 285 297 268 271 285 ...
280 277 310 305 274 271 280 300 272 292 286 285 286 303 261 262 245 250 262 258]';
x=mean(data)'; %% Mean, and what I would like my new basis to be
S=cov(data); lambda=svd(S); n=length(data); p=size(data,2); F=3.21;
major=2*sqrt(lambda(1))*sqrt(p*(n-1)*F/(n*(n-p))); %% Major axis
minor=2*sqrt(lambda(2))*sqrt(p*(n-1)*F/(n*(n-p))); %% Minor axis
th=linspace(0,2*pi);
X=[x(1)+major*cos(th); x(2)+minor*sin(th)];
angle=atan(x(1)/x(2)); %% rotational angle
R=[cos(angle) -sin(angle); sin(angle) cos(angle)]; %% Rotational matrix, should i muliply with new basis from left?
CE1=X; CE1=CE1'; %% Ellipse (blue), not rotated
CE2=R*X; CE2=CE2'; %% Ellipse (red), rotated, but not in a correct way
figure()
hold on
plot(CE1(:,1),CE1(:,2)), %axis equal
plot(CE2(:,1),CE2(:,2))
plot(data(:,1),data(:,2),'bo')

採用された回答

Image Analyst
Image Analyst 2021 年 9 月 29 日
編集済み: Image Analyst 2021 年 9 月 29 日
Looks like you forgot to subtract the center when you rotated so it's rotating around the origin, not the center of your ellipse.
You'd need to
  1. subtract the center to put it at the origin
  2. rotate the origin-centered ellipse
  3. add the center back in to translate it to its final location.
See attached demos where I rotate ellipses. Basically you multiply the N-by-2 (x,y) points array by the rotation matrix.
  2 件のコメント
John D'Errico
John D'Errico 2021 年 9 月 29 日
編集済み: John D'Errico 2021 年 9 月 29 日
"Basically you multiply the N-by-2 (x,y) points array by the rotation matrix."
Um, not exactly. That ony applies when the ellipse center is at the origin. So if you have already subtracted off the mean, yes. But then you need to translate back for the mean.
Image Analyst
Image Analyst 2021 年 9 月 29 日
Correct John. I think you were posting when I was editing and reposting, which I needed to do after I saw where the ellipse in his attempt ended up.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by