[問題] 如何正確製作動畫

看板MATLAB作者 (me)時間11年前 (2014/05/06 07:29), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
如果標題下的不好請多包涵 OrZ 大家好~小弟剛開始學用Movie 寫了一點code有一些問題如下: 1.在圖中要畫兩台車,若用rectangle畫車,程式可以跑但是車子移動過程 其中一台會有殘影。請問如何可以消掉殘影呢? 2.如果直接讀取車子的圖片則有一台無法顯示,好像跟讀取順序有關。 要怎麼做才能使兩台車同時顯現呢? 3.動畫好像會重複跑兩次,而且第二次的座標完全跑掉了。要怎麼做才能只跑一次? 4.應該如何正確uistack呢?我一直出現'Invalid or deleted object.' 錯誤 問題有點多,還請版上高手解惑~謝謝 以下附上程式碼: % Car Information l = 4.91; % vehicle length (Hyundai grandeur specs) [m] l_r = 3; % length rear end - cg [m] l_f = l-l_r; % length front end - cg [m] w = 1.86; % width of vehicle (Hyundai grandeur specs) [m] car_size=[l_r l_f w/2 w/2]; % car size array v1 = 60*1000/3600; % constant speed of car1 = 60 km/h v2 = 65*1000/3600; % constant speed of car2 = 80 km/h % Road Information % 1000m in total distance rl = 1000; % road length rw = 10; % road width % Trajectory Information % [x,y,phi] (left lower corner of the car box) x1 = [0:v1:rl]'; y1 = 2.5-0.5*w*ones(length(x1),1); x2 = [0:v2:rl]'; y2 = 7.5-0.5*w*ones(length(x2),1); phi1 = zeros(length(x1),1); phi2 = zeros(length(x2),1); traj1 = [x1,y1,phi1]; traj2 = [x2,y2,phi2]; leng_traj2 = length(traj2); % Drawing picture frame = 100; for i=1:leng_traj2 % read a car uniquebgcolor = [0 0 0]; % background color car1 = imread('car.png','BackgroundColor',uniquebgcolor); car2 = imread('car2.png','BackgroundColor',uniquebgcolor); % car rotation with yaw angle car1 = imrotate(car1,traj1(i,3),'bilinear','loose'); car2 = imrotate(car2,traj2(i,3),'bilinear','loose'); % mask1 = bsxfun(@eq,car1,reshape(uniquebgcolor,1,1,3)); % mask2 = bsxfun(@eq,car2,reshape(uniquebgcolor,1,1,3)); % display image % rec1=rectangle('position',[traj1(i,1) traj1(i,2) l w],'FaceColor','r'); % rec2=rectangle('position',[traj2(i,1) traj2(i,2) l w],'FaceColor','b'); % set(rec1,'erasemode','non'); % set(rec2,'erasemode','non'); car1_im = image(car1,'Xdata',[traj1(i,1),traj1(i,1)+l],... 'Ydata',[traj1(i,2),traj1(i,2)+w]); car2_im = image(car2,'Xdata',[traj2(i,1),traj2(i,1)+l],... 'Ydata',[traj2(i,2),traj2(i,2)+w]); % drawing road image line([0,rl],[0,0],'LineWidth',2,'Color','k'); line([0,rl],[rw,rw],'LineWidth',2,'Color','k'); line([0,rl],[rw/2,rw/2],'LineWidth',2,'Color','y'); % moving axes axis xy % cartesian convention axis([traj1(i,1)-5 traj1(i,1)+50 traj1(i,2)-10 traj1(i,2)+10]); % keep car image on the top uistack(car1_im,'top'); uistack(car2_im,'top'); % recording each movie frame M(i) = getframe(gcf); % get current frame end movie(M) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 128.32.164.86 ※ 文章網址: http://www.ptt.cc/bbs/MATLAB/M.1399332573.A.403.html
文章代碼(AID): #1JQ1xTG3 (MATLAB)
文章代碼(AID): #1JQ1xTG3 (MATLAB)