Rotate an Ellipsoid towards a point

6 ビュー (過去 30 日間)
trailer ranger
trailer ranger 2022 年 4 月 24 日
コメント済み: Matt J 2022 年 4 月 24 日
Hello to all,
I would like to rotate an elipsoid such that the major axis points torwards a point.
Currenly I have:
theta = linspace(0, pi, 25);
phi = linspace(0, 2*pi, 25) ;
x = 10*sin(theta)'*cos(phi);
y = 1*sin(theta)'*sin(phi);
z = 1*cos(theta)'*ones(size(phi));
surf(x,y,z)
alpha 0.5
xlim([-10 10])
ylim([-10 10])
zlim([-10 10])
hold on
scatter3(5,5,5)
quiver3(0,0,0, 5,5,5)
And I would like the major axis to point towards an arbitrary point. e.g., the point (5,5,5) . Since only one of axis will have a different dimension, I am not concerned with the rotation over the ellipsoid axis. How can I achieve this?
Best regards

採用された回答

Bruno Luong
Bruno Luong 2022 年 4 月 24 日
編集済み: Bruno Luong 2022 年 4 月 24 日
axlgt = [5,1,1];
P = [5;6;7];
[~,i] = max(abs(axlgt));
ei = accumarray(i,1,[3,1]);
a=cross(P,ei);
T=makehgtform('axisrotate', a, -atan2(norm(a),P(i)));
R=T(1:3,1:3);
theta = reshape(linspace(0, pi, 25), 1, [], 1);
phi = reshape(linspace(0, 2*pi, 25), 1, 1, [] );
xyz0 = axlgt(:).*[sin(theta).*cos(phi);
sin(theta).*sin(phi);
cos(theta).*ones(size(phi))];
xyz = pagemtimes(R,xyz0);
xyz = permute(xyz,[2 3 1]);
figure;
surf(xyz(:,:,1),xyz(:,:,2),xyz(:,:,3))
shading flat
alpha 0.5
xlim([-10 10])
ylim([-10 10])
zlim([-10 10])
hold on
scatter3(P(1),P(2),P(3))
quiver3(0,0,0, P(1),P(2),P(3))
  2 件のコメント
trailer ranger
trailer ranger 2022 年 4 月 24 日
Nice! This code appears to work like a charm!
Matt J
Matt J 2022 年 4 月 24 日
@trailer ranger then you should Accept-click this, or one of the other answers, whichever works best for you.

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

その他の回答 (2 件)

DGM
DGM 2022 年 4 月 24 日
編集済み: DGM 2022 年 4 月 24 日
Try this:
theta = linspace(0, pi, 25);
phi = linspace(0, 2*pi, 25) ;
x = 10*sin(theta)'*cos(phi);
y = 1*sin(theta)'*sin(phi);
z = 1*cos(theta)'*ones(size(phi));
hs = surf(x,y,z);
pt = [5 5 5]; % this is the vector to which the ellipse should be aligned
majax = [1 0 0]; % this is the vector on which the ellipse is aligned
rotaxis = cross(majax,pt);
rotate(hs,rotaxis,90-atand(1/sqrt(2)),[0 0 0])
alpha 0.5
shading flat
xlim([-10 10])
ylim([-10 10])
zlim([-10 10])
hold on
scatter3(5,5,5)
quiver3(0,0,0, 5,5,5)
  3 件のコメント
DGM
DGM 2022 年 4 月 24 日
I edited it so that you can enter the destination point.
trailer ranger
trailer ranger 2022 年 4 月 24 日
編集済み: trailer ranger 2022 年 4 月 24 日
If I choose the point [1, 1, 0], it will look weird.
In the x-y plane looks incorrect:
In the x-z and y-z plane it look Ok.
Edit: The point [1,2,3] doest not look Okl:
theta = linspace(0, pi, 25);
phi = linspace(0, 2*pi, 25) ;
x = 10*sin(theta)'*cos(phi);
y = 1*sin(theta)'*sin(phi);
z = 1*cos(theta)'*ones(size(phi));
hs = surf(x,y,z);
pt = [1 2 3]; % this is the vector to which the ellipse should be aligned
majax = [1 0 0]; % this is the vector on which the ellipse is aligned
rotaxis = cross(majax, pt);
rotate(hs,rotaxis,90-atand(1/sqrt(2)),[0 0 0])
alpha 0.5
shading flat
hold on
scatter3(pt(1), pt(2), pt(3))
quiver3(0,0,0,pt(1), pt(2), pt(3))
xlim([-10 10])
ylim([-10 10])
zlim([-10 10])
xlabel("x")
ylabel("y")
zlabel("z")
% view ([90 0 0]) % y-z
% view ([0 90 0]) % x-z
view ([0 0 90]) % x-y

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


Matt J
Matt J 2022 年 4 月 24 日
編集済み: Matt J 2022 年 4 月 24 日
Very simple with this FEX package,
gtEllip=ellipsoidalFit.groundtruth([],[0,0,0],[10,1,1],[45,-45,0]);
plot(gtEllip)
  1 件のコメント
trailer ranger
trailer ranger 2022 年 4 月 24 日
Hi,
Thanks for the reply! But I was hopping to get a solution without 3rd party packages.

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

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by