Rotate an Ellipsoid towards a point

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by