<pre code_snippet_id="1628801" snippet_file_name="blog_20160330_1_8408168" name="code" class="cpp">
<span style="font-size:18px;">>> t=[0:0.2:10*pi]; >> x=2*t; >> y=sin(t); >> z=cos(t); >> plot3(x,y,z,'bo'); >> hold on >> plot3(x,y,z,'r-','LineWidth',2);</span> |
|
<span style="font-size:18px;">x = -4:0.5:4; y = ( 4:-0.5:-4 )'; X = repmat(x,length(y),1); Y = repmat(y,1,length(x));</span>
<span style="font-size:18px;">>> x = -4:0.2:4; >> [X,Y] = meshgrid(x); >> Z = sin(sqrt(X.^2+Y.^2)); >> h = mesh(X,Y,Z); >> c1 = get(h,'FaceColor');</span> |
|
<span style="font-size:18px;">>> hidden off; >> c2 = get(h,'FaceColor');</span> |
|
<span style="font-size:18px;">>> x = -10:0.5:10 ; >> [X,Y] = meshgrid(x); >> r = sqrt(X.^2+Y.^2)+eps; >> Z = sin(r)./r; >> meshc(X,Y,Z);</span> |
|
<span style="font-size:18px;">>> x = -10:0.5:10 ; >> [X,Y] = meshgrid(x); >> r = sqrt(X.^2+Y.^2)+eps; >> Z = sin(r)./r; >> surf(X,Y,Z);</span> |
|
属性名称 |
意义 |
取值 |
EdgeColor |
网格线颜色 |
{ColorSpec} | none | flat | interp |
FaceColor |
四边形网格的填充颜色 |
ColorSpec | none | {flat} | interp | texturemap |
LineStyle |
网格线线型 |
{-} | -- | : | -. | none |
LineWidth |
网格线线宽 |
|
Marker |
标记点形状 |
none | + | o | * | . | x | s | d | p | h ….. |
MarkerEdgeColor |
标记点边界颜色 |
none | {auto} | flat | ColorSpec |
MarkerFaceColor |
闭合的标记点填充颜色 |
{none} | auto | flat | ColorSpec |
MarkerSize |
标记点大小 |
size in points |
MeshStyle |
网格类型 |
{both} | row | column |
<span style="font-size:18px;">>> x = -10:0.5:10 ; >> [X,Y] = meshgrid(x); >> r = sqrt(X.^2+Y.^2)+eps; >> Z = sin(r)./r; >> h = mesh(X,Y,Z,'EdgeColor','black'); >> set(h,'FaceColor','r'); >> set(h,'LineWidth',2);</span> |
|
<span style="font-size:18px;">>> x = -10:0.5:10 ; >> [X,Y] = meshgrid(x); >> r = sqrt(X.^2+Y.^2)+eps; >> Z = sin(r)./r; >> surf(X,Y,Z,'EdgeColor','none');</span> |
|
<span style="font-size:18px;">>> clc; >> clear all; >> close all; >> A = [1;0;2]; >> B = [3;0;3]; >> C = [1;0;0]; >> D = [3;0;0]; >> P = [A,B;C,D]; >> X = P([1,4],:); >> Y = P([2,5],:); >> Z = P([3,6],:); >> h = surf(X,Y,Z); >> set(h,'FaceColor','b'); >> axis([0,4,-1,1,0,4]);</span> |
|
<span style="font-size:18px;">>> L = rand(1); >> W = rand(1); >> H = rand(1); >> A = rand(3,1); >> B = A + [L;0;0]; >> C = B + [0;W;0]; >> D = A + [0;W;0]; >> r1 = repmat(A,1,5); >> r2 = [A,B,C,D,A]; >> r3 = r2 + repmat([0;0;H],1,5); >> r4 = repmat(r3(:,1),1,5); >> P=[r1;r2;r3;r4]; >> X = P(1:3:end,:); >> Y = P(2:3:end,:); >> Z = P(3:3:end,:); >> surf(X,Y,Z,'FaceColor','b','EdgeColor','none') >> axis vis3d >> hold on >> x = X(2:3,:); % x,y,z用来绘制线框 >> y = Y(2:3,:); >> z = Z(2:3,:); >> plot3(x,y,z,'r','LineWidth',3); >> plot3(x',y',z','r','LineWidth',3);</span> |
|
<span style="font-size:18px;">>> z1 = 0 %底面所在的平面 >> z2 = 2 ; %顶面面所在的平面 >> M = 20 ; % 纬线数目 >> N = 20; % 经线数目 >> t = linspace(0,2*pi,N); >> s = linspace(0,2*pi, M)'; >> r = (2 + sin(s)); >> h = linspace(z1,z2, M)'; >> X = r*cos(t); >> Y = r*sin(t); >> Z = h*ones(size(t)); >> surf(X,Y,Z);</span> |
|
<span style="font-size:18px;">>> z1 = 0 %底面所在的平面 >> z2 = 2 ; %顶面面所在的平面 >> M = 20 ; % 纬线数目 >> N = 20; % 经线数目 >> t = linspace(0,2*pi,N); >> s = linspace(0,2*pi, M)'; >> r = (2 + sin(s)); >> h = linspace(z1,z2, M)'; >> [T,R] = meshgrid(t,r); >> [T,H] = meshgrid(t,h); >> X = R.*cos(T); >> Y = R.*sin(T); >> Z = H; >> surf(X,Y,Z);</span> |
|
<span style="font-size:18px;">>> z1 = 0 %底面所在的平面 >> z2 = 2 ; %顶面面所在的平面 >> M = 20 ; % 纬线数目 >> N = 20; % 经线数目 >> t = linspace(0,2*pi,N); >> s = linspace(0,2*pi, M)'; >> r = (2 + cos(s)); >> h = linspace(z1,z2, M)'; >> X = r*cos(t); >> Y = r*sin(t); >> Z = h*ones(size(t)); >> surf(X,Y,Z);</span> |
|
<span style="font-size:18px;">>> z1 = 0 %底面所在的平面 >> z2 = 2 ; %顶面面所在的平面 >> M = 20 ; % 纬线数目 >> N = 20; % 经线数目 >> t = linspace(0,2*pi,N); >> s = linspace(0,2*pi, M)'; >> r =sin(s)./(s+eps); >> h = linspace(z1,z2, M)'; >> X = r*cos(t); >> Y = r*sin(t); >> Z = h*ones(size(t)); >> surf(X,Y,Z);</span> |
|
<span style="font-size:18px;">>> r = 2; %球半径 >> r = 2; %球半径 >> N = 30; %纬线数 >> phi = 0:2*pi/M:2*pi ; >> theta = linspace(0,pi,N)'; >> X = r*sin(theta)*cos(phi); >> Y = r*sin(theta)*sin(phi); >> Z = r*cos(theta)*ones(size(phi)); >> surf(X,Y,Z); >> axis square;</span> |
|
<span style="font-size:18px;">>> r = 2; >> theta = linspace(0,pi,20); >> phi = linspace(0,2*pi,21); >> [T,P]=meshgrid(theta,phi); >> X = r.*sin(T).*cos(P); >> Y = r.*sin(T).*sin(P); >> Z = r.*cos(T); >> surf(X,Y,Z); >> axis square;</span> |
|
<span style="font-size:18px;">>> t = 0:pi/10:2*pi; >> [X,Y,Z] = cylinder(2+cos(t)); >> surf(X,Y,Z); >> axis square</span> |
|
<span style="font-size:18px;">>> sphere; >> axis equal</span> |
|
<span style="font-size:18px;">>> [x, y, z] = ellipsoid(0,0,0,3,2,1,30); >> surf(x, y, z); >> axis equal</span> |
|
原文:http://blog.csdn.net/shenziheng1/article/details/51012938