第六章 三維空間繪圖
DESCRIPTION
第六章 三維空間繪圖. 本章學習目標 學習三維繪圖的基本技巧 學習 peaks() 函數的用法 學習二維與三維等高線圖的繪製 學習三維圖形的編修. 基本三維繪圖. 對於函數 f ( x , y ) 而言,每給一組 ( x , y ) ,便能計算 z=f ( x , y ) 只要給予 ( x , y ) 的組數夠多,即可繪出三維曲面圖. 繪製三維的網格圖. 利用 mesh() 繪製三維的網格圖. mesh() 的使用範例. >> mesh(xx,yy,zz). >> mesh(zz). meshgrid() 函數. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/1.jpg)
第六章 三維空間繪圖
本章學習目標 • 學習三維繪圖的基本技巧• 學習 peaks() 函數的用法• 學習二維與三維等高線圖的繪製• 學習三維圖形的編修
1
![Page 2: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/2.jpg)
基本三維繪圖 • 對於函數 f(x,y) 而言,每給一組 (x,y) ,便能計算z=f(x,y)
• 只要給予 (x,y) 的組數夠多,即可繪出三維曲面圖
2
![Page 3: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/3.jpg)
3
繪製三維的網格圖
![Page 4: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/4.jpg)
4
利用 mesh() 繪製三維的網格圖
![Page 5: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/5.jpg)
5
>> xx=[2 3 4;2 3 4;2 3 4;2 3 4]xx = 2 3 4 2 3 4 2 3 4 2 3 4
>> yy=[3 3 3;2 2 2;1 1 1;0 0 0]yy = 3 3 3 2 2 2 1 1 1 0 0 0
>> zz=[8 8 9;8 8 9;7 7 7;7 7 6]zz = 8 8 9 8 8 9 7 7 7 7 7 6
>> mesh(xx,yy,zz)
>> mesh(zz)
mesh() 的使用範例
![Page 6: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/6.jpg)
6
meshgrid() 函數
>> vx=2:4vx = 2 3 4
>> vy=0:3vy = 0 1 2 3
>> [xx,yy]=meshgrid(vx,vy)xx = 2 3 4 2 3 4 2 3 4 2 3 4yy = 0 0 0 1 1 1 2 2 2 3 3 3
>> zz=sqrt(xx.*yy)zz = 0 0 0 1.4142 1.7321 2.0000 2.0000 2.4495 2.8284 2.4495 3.0000 3.4641
>> mesh(xx,yy,zz)
![Page 7: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/7.jpg)
7
>> x=linspace(-2,2,30);>> y=linspace(-2,2,30);>> [xx,yy]=meshgrid(x,y);>> zz=xx.*exp(-xx.^2-yy.^2);>> mesh(xx,yy,zz)
• Matlab 提供了 meshgrid 函數,可以建立 xx與 yy矩陣:
![Page 8: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/8.jpg)
8
meshc() 與 waterfall() 函數
>> x=linspace(-8,8,30);
>> y=x;
>> [xx,yy]=meshgrid(x,y);
>> expr=sqrt(xx.^2+yy.^2);
>> zz=sin(expr)./(expr+eps);
>> meshc(xx,yy,zz) >> waterfall(xx,yy,zz)
• Matlab內建常數: eps=2.2x10-16
![Page 9: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/9.jpg)
9
三維曲面圖 -surf() 與 surfc()
>> x=linspace(-7,7,32);
>> y=linspace(-6,6,32);
>> [xx,yy]=meshgrid(x,y);
>> zz=xx./(xx.^2+yy.^2+1);
>> surf(xx,yy,zz); >> surfc(xx,yy,zz); axis tight;
![Page 10: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/10.jpg)
簡易的三維繪圖函數 • 只要給予繪圖的函數與範圍, ezmesh() 與 ezsurf() 函數
便可快速的繪出三維的圖形
10
![Page 11: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/11.jpg)
11
ezmesh() 與 ezsurf() 的使用範例>> ezmesh('exp(-0.2*x)*cos(t)')
>> ezmesh('exp(-0.2*x)*cos(t)',... [-pi,2*pi,-2,12],36)
>> ezsurf('y/(x^2+y^2+1)',36)
>> ezsurfc('y/(x^2+y^2+1)',36)
![Page 12: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/12.jpg)
12
三維圖形展示函數— peaks
2 2 2 2 2 22 ( 1) 3 5 ( 1)1( , ) 3(1 ) 10
5 3x y x y x yx
f x y x e x y e e
![Page 13: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/13.jpg)
13
Peaks 的語法>> peaks;z=3*(1-x).^2.*exp(-(x.^2)-(y+1).^2)... -10*(x/5-x.^3-y.^5).*exp(-x.^2-y.^2)... -1/3*exp(-(x+1).^2-y.^2)
>> peaks(24);
>> [xx,yy,zz]=peaks(32);
>> surfc(xx,yy,zz);
![Page 14: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/14.jpg)
14
空間曲線繪圖
>> t=linspace(0,30,120);
>> plot3(t.*sin(t),t.*cos(t),t,'-ro');
>> plot3(t.*sin(t),t.*cos(t),t,'-ro',
t.*sin(t),t.*cos(t),-t,'-bd');
![Page 15: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/15.jpg)
15
等高線繪圖 • 等高線圖( contour plot )是把三維的圖中,高度相等的
點連接起來,即成等高線圖
![Page 16: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/16.jpg)
等高線繪圖的範例
16
>> [xx,yy,zz]=peaks;
>> contour(xx,yy,zz) >> contourf(xx,yy,zz,20) >> contourf(zz,[-2,0,3,7])
![Page 17: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/17.jpg)
17
標註等高線的值
>> [xx,yy,zz]=peaks;
>> cmat=contour(xx,yy,zz); >> clabel(cmat)
![Page 18: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/18.jpg)
18
三維的等高線圖
>> zz=peaks; >> contour3(zz); >> contour3(zz,[2]); >> contour3(zz,[2,2]);
![Page 19: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/19.jpg)
19
三維圖形的基本編修
>> zz=peaks;
>> hidden off; >> axis off;>> box on;>> mesh(zz);axis tight;
![Page 20: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/20.jpg)
改變三維圖形的視角
20
方位角是從 x軸數起,逆時針方向為正
仰角是從 x-y平面上數起,往上為正,往下為負
![Page 21: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/21.jpg)
21
view() 的使用範例>> peaks;
>> view(60,30);
![Page 22: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/22.jpg)
22
修改三維圖形的曲面顏色 >> peaks;
>> colorbar;
>> colormapans = 0 0 0.5625 0 0 0.6250 0 0 0.6875 0 0 0.7500 0 0 0.8125 0 0 0.8750 0 0 0.9375 : : : 0.5625 0 0 0.5000 0
![Page 23: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/23.jpg)
23
colormap() 函數的使用
![Page 24: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/24.jpg)
24
>> peaks;
>> cm=[1 0 0;1 1 0;0 1 1; 0 0 1;1 0 1]cm = 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1
>> colormap(cm);colorbar;
colormap() 的使用
![Page 25: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/25.jpg)
25
產生顏色對應表的函數
![Page 26: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/26.jpg)
26
顏色對應表函數的使用>> colormap(hot(32));colorbar;
>> colormap('default');colorbar;
>> colormap spring; colorbar;
>> size(spring)ans =3
>> size(colormap)ans =
64 3
![Page 27: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/27.jpg)
27
Colormap Editor 對話方塊 • 從 Edit 選單中選擇 Colormap 來編輯顏色對應表
![Page 28: 第六章 三維空間繪圖](https://reader038.vdocuments.site/reader038/viewer/2022102516/56813287550346895d992166/html5/thumbnails/28.jpg)
28
Exercises(1/1)• 請分別以 mesh 與 surf 函數繪製下列函數的圖形。
• 請分別以 ezmesh 與 ezsurf 函數繪製下列函數的圖形。
• 請以實線、紅色、圓形 200 個資料點繪製下列函數的圖形。
22,22,)sin(
22
yx
yx
yxz
55,55,)(2222 yxeyxz yx
60],,1
3sin,
12
4cos[
tt
t
t
t
t