Animation improvement

조회 수: 4 (최근 30일)
Julián Francisco
Julián Francisco 2011년 12월 25일
I have written a code to create an animation: satellite movement around the Earth. When I run it, it works fine. However, when it is modified to be part of a code much more complex present in a Matlab GUI, the results produced changes (mainly because of the bigger number of points to plot). I also have noticed that if I use the OpenGL renderer the movement of the satellite is quicker than when the other renderers (Painters and Zbuffer) are used. I do not know if there are further possibilities to achieve an improvement in the rendering of the satellite movement. I think the key is, perhaps, changing the code that creates the actual position of the satellite ( handles.psat ) and its trajectory along the time ( handles.tray )
handles.tray = zeros(1,Fin);
handles.psat = line('parent',ah4,'XData',Y(1,1), 'YData',Y(1,2),...
'ZData',Y(1,3),'Marker','o', 'MarkerSize',10,'MarkerFaceColor','b');
...
while (k<Fin)
az = az + 0.01745329252;
set(hgrot,'Matrix',makehgtform('zrotate',az));
handles.tray(k) = line([Y(k-1,1) Y(k,1)],[Y(k-1,2) Y(k,2)],...
[Y(k-1,3) Y(k,3)],...
'Color','red','LineWidth',3);
set(handles.psat,'XData',Y(k,1),'YData',Y(k,2),'ZData',Y(k,3));
pause(0.02);
k = k + 1;
if (state == 1)
state = 0;
break;
end
end
...

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 25일
It might be faster to code the transform yourself as a matrix multiplication rather than calling makehgtform. The array is fairly simple: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm
( cos q sin q 0 0)
Rz (q) = (-sin q cos q 0 0)
( 0 0 1 0)
( 0 0 0 1)
Only two trig calls needed.
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 12월 26일
Use the above matrix to multiply [X(:), Y(:), Z(:), ones(numel(X),1)]
Or just strip it down to an X-Y rotation as your Z is going to stay the same.
As you are using fixed angular steps (1 degree), you could pre-calculate all of the positions and then use simple indexing.
cq = cosd(0:359);
sq = sind(0:359);
Then (mumble... bsxfun... maybe matrix multiply... mumble) and you should be able to get out the complete point list at all angles of interest.
Sorry about the (mumble), but it is quarter to 5 in the morning here and I am fading a bit.
Julián Francisco
Julián Francisco 2011년 12월 26일
@Walter Roberson: Thank you back. Excuse me for my lazy ignorance. I have just found the rotate function also can be used to rotate the sphere.

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

추가 답변 (0개)

카테고리

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