Rotate an Ellipsoid towards a point

6 Ansichten (letzte 30 Tage)
trailer ranger
trailer ranger am 24 Apr. 2022
Kommentiert: Matt J am 24 Apr. 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

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 24 Apr. 2022
Bearbeitet: Bruno Luong am 24 Apr. 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 Kommentare
trailer ranger
trailer ranger am 24 Apr. 2022
Nice! This code appears to work like a charm!
Matt J
Matt J am 24 Apr. 2022
@trailer ranger then you should Accept-click this, or one of the other answers, whichever works best for you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

DGM
DGM am 24 Apr. 2022
Bearbeitet: DGM am 24 Apr. 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 Kommentare
DGM
DGM am 24 Apr. 2022
I edited it so that you can enter the destination point.
trailer ranger
trailer ranger am 24 Apr. 2022
Bearbeitet: trailer ranger am 24 Apr. 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

Melden Sie sich an, um zu kommentieren.


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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by