Rotate an Ellipsoid towards a point

6 vues (au cours des 30 derniers jours)
trailer ranger
trailer ranger le 24 Avr 2022
Commenté : Matt J le 24 Avr 2022
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

Réponse acceptée

Bruno Luong
Bruno Luong le 24 Avr 2022
Modifié(e) : Bruno Luong le 24 Avr 2022
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 commentaires
trailer ranger
trailer ranger le 24 Avr 2022
Nice! This code appears to work like a charm!
Matt J
Matt J le 24 Avr 2022
@trailer ranger then you should Accept-click this, or one of the other answers, whichever works best for you.

Connectez-vous pour commenter.

Plus de réponses (2)

DGM
DGM le 24 Avr 2022
Modifié(e) : DGM le 24 Avr 2022
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 commentaires
DGM
DGM le 24 Avr 2022
I edited it so that you can enter the destination point.
trailer ranger
trailer ranger le 24 Avr 2022
Modifié(e) : trailer ranger le 24 Avr 2022
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

Connectez-vous pour commenter.


Matt J
Matt J le 24 Avr 2022
Modifié(e) : Matt J le 24 Avr 2022
Very simple with this FEX package,
gtEllip=ellipsoidalFit.groundtruth([],[0,0,0],[10,1,1],[45,-45,0]);
plot(gtEllip)
  1 commentaire
trailer ranger
trailer ranger le 24 Avr 2022
Hi,
Thanks for the reply! But I was hopping to get a solution without 3rd party packages.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by