I want to animate a ball travelling in 3-D space along a parametrized curve, say a helix. In 2-D space, I use the 'viscircles' function to draw a circle at a specific point and fixed radius. This is very easy to loop:
%ball travelling in 2-D space along a circle of radius 1
t = 0:0.01:2*pi;
x = cos(t);
y = sin(t);
for i=1:length(t)
ballpoint = [x(i) y(i)];
ball = viscircles(ballpoint,0.05) %draws circle of radius 0.05 at point 'ballpoint'
drawnow
if i<length(t) %deletes ball at position (x(i),y(i)) when ball is at position (x(i+1),y(i+1))
delete(ball);
end
end
the code above is very simple and straightforward. I thought there would be an analogous function of the same sort as 'viscircles' that would draw a sphere about a point and fixed radius, but there isn't. How could I make a similar animation as the one above, only in 3-D space with a sphere travelling on a helix?

 채택된 답변

KSSV
KSSV 2016년 11월 10일

0 개 추천

t = linspace(0,6*pi,100);
r = 1. ; % radius of spiral path
c = 2 ;
x = r*cos(t) ;
y = r*sin(t) ;
z = c*t ;
for i = 1:length(x)
plot3(x,y,z,'Color','k','Linewidth',1) ;
hold on
plot3(x(i),y(i),z(i),'Or','Markersize',10) ;
hold off
drawnow
end

댓글 수: 2

Denis Kartachov
Denis Kartachov 2016년 11월 10일
Thank you! So does 'O' draw a sphere at the point x(i) y(i) z(i)? is 'r' the radius?
KSSV
KSSV 2016년 11월 11일
Yes 'r' is radius. 'O' this draws circle. Check sphere to draw a sphere. Read Jan Simon advice.

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

추가 답변 (1개)

Jan
Jan 2016년 11월 10일

0 개 추천

The command sphere draws a sphere. For a smooth animation you can create the sphere outside the loop or in the first iteration only, and set the 'XData', 'YData', and 'ZData' properties afterwards only.

카테고리

도움말 센터File Exchange에서 Animation에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2016년 11월 10일

댓글:

2016년 11월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by