- subtract the center to put it at the origin
- rotate the origin-centered ellipse
- add the center back in to translate it to its final location.
Change of basis, rotating an ellipse
13 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
采纳的回答
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
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
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
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 Exchange 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!