盡管笛卡爾和瑞典公主的故事已被證明隻是杜撰,但因這個故事出名的心形函數被廣為流傳。今天讓我們來看看各大軟體如何進行繪圖表白~
Stata
利用Stata繪制心形線的程式,代碼如下:
clearrange t 0 2*_pi 1000gen x=16*sin(t)^3gen y=13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)egen x_min=min(x)egen x_max=max(x)egen y_min=min(y)egen y_max=max(y)gen a=(x-x_min)/(x_max-x_min)gen b=(y-y_min)/(y_max-y_min)line b agr_edit yaxis1.draw_view.setstyle, style(no)gr_edit xaxis1.draw_view.setstyle, style(no)gr_edit plotregion1.AddTextBox added_text editor .7055394244311991 .2810707216715078gr_edit plotregion1.added_text_new = 1gr_edit plotregion1.added_text_rec = 1gr_edit plotregion1.added_text[1].style.editstyle angle(default) size(medsmall) color(red) horizontal(left) vertical(middle) margin(zero) linegap(zero) drawbox(no) boxmargin(zero) fillcolor(bluishgray) linestyle( width(thin) color(red) pattern(solid)) box_alignment(east) editcopygr_edit plotregion1.added_text[1].style.editstyle size(large) editcopygr_edit plotregion1.added_text[1].text = {}gr_edit plotregion1.added_text[1].text.Arrpush " I LOVE YOU"graph export "C:\Desktop\520.png", as(png) wid(800)hei(600) replace
結果為:
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5SO0QDN5MGNzETZ1MWOzU2Y2IGMzIWMhdTZyEGZlJ2Yj9CX0JXZ252bj91Ztl2Lc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
利用Stata繪制心形線的程式,代碼如下:
qui range t 0 2*_pi 1000qui gen x=16*sin(t)^3qui gen y=13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)qui egen x_min=min(x)qui egen x_max=max(x)qui egen y_min=min(y)qui egen y_max=max(y)qui gen a=(x-x_min)/(x_max-x_min)qui gen b=(y-y_min)/(y_max-y_min)line b a,color(red)
結果為:
Matlab
利用matlab代碼:
[email protected](x,y,z) x.^2.*z.^3+9*y.^2.*z.^3/80-(x.^2+9*y.^2/4+z.^2-1).^3;%心形曲面函數[x,y,z]=meshgrid(-1.5:0.1:1.5);%畫圖範圍v=f(x,y,z);%畫圖h=patch(isosurface(x,y,z,v,0));isonormals(x,y,z,v,h)set(h,'FaceColor','r','EdgeColor','none');title(Picture')alpha(0.6) grid off;axis([-1.5 1.5 -1.5 1.5 -1.5 1.5])lighting Gouraudh = camlight('left');for i = 1:180;%水準旋轉照相機 camorbit(1,0) camlight(h,'left'); drawnow;end
來源:經管之家、果殼網以及網絡等