Rotate an Ellipsoid towards a point

조회 수: 5 (최근 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 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