How do I plot a sphere along an elliptical path

조회 수: 4 (최근 30일)
Mahmoud
Mahmoud 2013년 12월 4일
댓글: Walter Roberson 2013년 12월 4일
Hi all,
I am trying to plot a spherical object along an elliptical path, I found this code that plots the path, but I need to get the sphere to move along this path
ellipse = fncmb(circle,[2 0;0 1]);
s45 = 1/sqrt(2);
rtellipse = fncmb(fncmb(ellipse, [s45 -s45;s45 s45]), [1;1] );
hold on, fnplt(rtellipse), hold off
Regards,
Jobe
  댓글 수: 4
Walter Roberson
Walter Roberson 2013년 12월 4일
The code you show doesn't really rotate the sphere: it rotates the viewpoint leaving the sphere fixed in place. My guess is that you will want to keep your viewpoint in place and have the object move within the fixed view, right?
Mahmoud
Mahmoud 2013년 12월 4일
Exactly Walter!
I want the sphere to be rotating, while the viewpoint remains constant.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2013년 12월 4일
Have a look at hgtransform()

추가 답변 (1개)

Mahmoud
Mahmoud 2013년 12월 4일
편집: Walter Roberson 2013년 12월 4일
Thank you,
But I still have a little problem, I used the tutorial and inserted the code for a sphere into it, but the sphere is not rotating. This is the code:
Create an axes and adjust the view.
Set the axes limits to prevent auto limit selection during scaling
ax = axes('XLim',[-1.5 1.5],'YLim',[-1.5 1.5],...
'ZLim',[-1.5 1.5]);
view(3); grid on; axis equal
load topo;
[x, y, z] = sphere;
s = surface(x,y,z,'facecolor','texturemap','cdata',topo);
axis off
set (gcf,'color','k')
%%Create an hgtransform object and parent the surface objects to it.
%%The figure should not change from the image above.
t = hgtransform('Parent',ax);
% set(h,'Parent',t)
%%Select a renderer and show the objects.
set(gcf,'Renderer','opengl')
drawnow
%%Initialize the rotation and scaling matrix to the identity matrix (eye).
%%Again, the image should not change.
Rz = eye(4);
Sxy = Rz;
%%Form the z-axis rotation matrix and the scaling matrix.
%%Rotate 360 degrees (2*pi radians) and scale by using the increasing values of r.
for r = 1:.1:2*pi
% Z-axis rotation matrix
Rz = makehgtform('zrotate',r);
% Scaling matrix
Sxy = makehgtform('scale',r/4);
% Concatenate the transforms and
% set the hgtransform Matrix property
set(t,'Matrix',Rz*Sxy)
drawnow
end
pause(1)
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 12월 4일
You probably don't want the scaling portion going on, just
Rz = makehgtform('zrotate',r);
set(t, 'Matrix', Rz);
drawnow()
I am not sure at the moment why the rotation might not be happening. Are you seeing the scaling going on? With the code you have, is the sphere growing over time?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by