سه شنبه, ۲۱ تیر ۱۴۰۱، ۰۸:۳۹ ب.ظ
حرکت انمیشن وار چند ضلعی روی یک صفحه دلخواه.
در این پست یک صفحه که فرمول آن در سطر 30 قرار دارد(و شما می توانید فرمول آن را تغییر دهید، فقط ضریب z غیر صفر باشد)، و یک چند ضلعی (دایره) روی آن به شکل تصادفی گردش میکند، به عبارتی هدف ما این بود که بتوانیم چند ضلعی یا هر تابع دیگری را روی صفحه به سمت راست یا چپ نسبی یا بالا و پایین نسبی صفحه گردش بدهیم.
کد اجرایی:
%%%%%%%%%%%%%%%%%%%%%%%%%%-----------software details-----------%%%%%%%%%%%%%%%%%%%%%% %devloped in Iran(ardebil) % %Copyright (C) 2017(1396) by moussa hasanzadeh as the head devloper %% %All rights reserved. % %programed in mathlab 2016 %gmail:mo30no@gmail.com %phone 09147082079 %% clear and close all child forms delete(allchild(0));close all; clear; clc; %% plot coordinates system in 3D area and labeling plot3([-5;5],[-5;5]*0,[-5;5]*0,'k');hold on; plot3([-5;5]*0,[-5;5],[-5;5]*0,'k');hold on plot3([-5;5]*0,[-5;5]*0,[-5;5],'k');hold on text([-6;6],[-6;6]*0,[-6;6]*0,{'-X','X'});hold on; text([-6;6]*0,[-6;6],[-6;6]*0,{'-Y','Y'});hold on text([-6;6]*0,[-6;6]*0,[-6;6],{'-Z','Z'});hold on xlabel('X'); ylabel('Y'); zlabel('Z'); %% convert implicit plan formula as parametric form syms x y z scalerVal t; plan='20*x+3*y+2*z+1';%% plan as inplicit form x=[-3:3]; y=[-3:3]; z=[-3:3]; %function to draw on the plan side=50; t=linspace(0,2*pi,side+1); p=cos(t) ;%x coordinate q=sin(t) ;% y coordinate pluIdex=strfind(plan,'+');%% find plus index in plan formula scalerIndex=strsplit(plan,'+'); for s=1:length(scalerIndex) scalerVal=str2num(scalerIndex{s}); if ~isempty(scalerVal) break; else scalerVal=0; end end %% extract z coff zIndex=strfind(plan,'z'); if ~isempty(zIndex) pluIZ=pluIdex(pluIdex<zIndex); if ( pluIZ) pluIZ=pluIZ(end); cofZIndex=pluIZ+1:zIndex-2; cofZ=str2double(plan(cofZIndex)); else if (zIndex>1) pluIZ=1; cofZIndex=pluIZ:zIndex-2; cofZ=str2double(plan(cofZIndex)); else cofZ=1; end end else cofZ=0; end %% extract y coff yIndex=strfind(plan,'y'); if ~isempty(yIndex) pluIY=pluIdex(pluIdex<yIndex); if ( pluIY) pluIY=pluIY(end); cofYIndex=pluIY+1:yIndex-2; cofY=str2double(plan(cofYIndex)); else if (yIndex>1) pluIY=1; cofYIndex=pluIY:yIndex-2; cofY=str2double(plan(cofYIndex)); else cofY=1; end end else cofY=0; end %% extract x coff xIndex=strfind(plan,'x'); if ~isempty(xIndex) pluIX=pluIdex(pluIdex<xIndex); if ( pluIX) pluIX=pluIX(end); cofXIndex=pluIX+1:xIndex-2; cofX=str2double(plan(cofXIndex)); else if (xIndex>1) pluIX=1; cofXIndex=pluIX:xIndex-2; cofX=str2double(plan(cofXIndex)); else cofX=1; end end else cofX=0; end coff=[cofX,cofY,cofZ]; funcIndex=find(coff);funcIndex=funcIndex(end); switch funcIndex case 1 [y,z]=meshgrid(y,z); x=-(coff(2)/coff(1))*y -(coff(3)/coff(1))*z-scalerVal/coff(1); ft=(coff(2)/coff(1))*p +(coff(3)/coff(1))*q+scalerVal/coff(1); plot3(ft,p,q) case 2 [x,z]=meshgrid(x,z); y=(coff(1)/coff(2))*x +(coff(3)/coff(2))*z+scalerVal/coff(2); ft=(coff(1)/coff(2))*p +(coff(3)/coff(2))*q+scalerVal/coff(2); plot3(p,ft,q) case 3 [x,y]=meshgrid(x,y); z=(coff(1)/coff(3))*x +(coff(2)/coff(3))*y+scalerVal/coff(3); for s=1:50 p=cos(t)+cos(rand*2-1) ;%x coordinate q=sin(t)+sin(rand*2-1) ;% y coordinate ft=(coff(1)/coff(3))*p +(coff(2)/coff(3))*q+scalerVal/coff(3); surf(x,y,z,'FaceColor','g') h=plot3(p ,q ,ft,'k'); pause(.5) delete(h); end end %%%%%%%%%%%%%%%%%%%%%%%%%%-----------software details-----------%%%%%%%%%%%%%%%%%%%%%% %devloped in Iran(ardebil) % %Copyright (C) 2017(1396) by moussa hasanzadeh as the head devloper %% %All rights reserved. % %programed in mathlab 2016 %gmail:mo30no@gmail.com %phone 09147082079
نمونه ویدئوی خروجی:
۰۱/۰۴/۲۱