plot3d

“msharpmath”, The Simple is the Best

[100] 002 Tutorial plot                   plot

Click the above button for full-text tutorial of   ‘plot’ .

//==================================================================================
//   Umbrella ‘plot’  for drawing 3D figures
//==================================================================================
In most cases, ‘plot’ is also used to draw 3D figures as well as 2D figures.

//————————————————————————————————————
// 3D curve (only a single curve)
//————————————————————————————————————
plot . @ u[n=51,g=1](a,b) ( <<opt>>, x(u),y(u),z(u) )  //  3 functions for 3D curve
plot . @ u[n=51,g=1](a,b) ( <<opt>>, r(u),t(u),z(u) ) .cyl
plot . @ u[n=51,g=1](a,b) ( <<opt>>, r(u),p(u),t(u) ) .sph

%> curve in 3D (r,t,z)
#> plot  .@ t[501](0,5) ( exp(0.6*t), 30*t, 10*t ) .cyl .move(0,30,0) .yrot(pi/6); // (r,t,z)
#> plot+ .@ t[501](0,5) ( exp(0.6*t), 30*t, 10*t ) .cyl .yrot(-pi/6); // (r,t,z)

%> Tchebyshev polynomials in 3D
#> N = [0,2,4,10,20,40,60];
.hold;
for.i(1,7) {
n = N(i);
plot .@ t[1001](-1,1) ( 4*t, 0,  .T_n(t) ).move(0,2*i,0);
}
plot;

//————————————————————————————————————
// built-in 3D geometry
//————————————————————————————————————
.sphere    [np=31,nt=31, gp=1,gt=1]   (R            )
.ellipsoid [np=31,nt=31, gp=1,gt=1]   (a,b,c        )
.torus     [np=31,nt=31, gp=1,gt=1]   (a,b          )
.disk      [nr= 2,nt=31, gr=1,gt=1]   (R            )
.plane     [nx= 2,ny= 2, gx=1,gy=1]   (a,b,c, side=1)
.frustum   [nr=3,nt=21,nz=4, gr=1,gt=1,gz=1]  (a,b,h)
.vector    [scale=1,headscale=1,headangle=30] (a,b,c)
.line      (x1,y1,z1, x2,y2,z2)

.klein(size)
.mobius(size)
.trefoil(size)
.toroid(size)

#> plot .torus(3,1) ;

#>plot.klein(1) ;

#> plot .frustum[3,6,4] (5,2,4);  // plot .frustum[ nr, nt, nz ] ( a, b, h)

%>  solid sphere inside a wired-sphere
#{
n = 21;;  r = 1;;
.hold;
plot .sphere[n,n](r);  // 21 x 21 uniform mesh
plot .@ t[1001](0,30*pi) ( 0.2, t, t/60 ) .cyl.move(0,0,1);  // (r,t,z)
plot .@ t[1001](0,30*pi) ( 1.1, t/30, t ) .sph;              // (R,P,T)
plot;
#}

%> a group of spheres
#{
n = 21;;  r = 1;;
.hold;
for.i(0,9)
plot .sphere[n,n](r) .move(4*cos(i*2*pi/10),4*sin(i*2*pi/10),0) ;  // 21 x 21 uniform mesh
plot;
#}


//————————————————————————————————————
// 3D surface (only a sinlge surface)
//————————————————————————————————————
plot .x[n=31,g=1](a,b) .y[n=31,g=1](c(x),d(x)) ( <<opt>>, z )
plot .u[n=31,g=1](a,b) .v[n=31,g=1](c(u),d(u)) ( <<opt>>, x,y,z )
plot .u[n=31,g=1](a,b) .v[n=31,g=1](c(u),d(u)) ( <<opt>>, r,t,z ) .cyl
plot .u[n=31,g=1](a,b) .v[n=31,g=1](c(u),d(u)) ( <<opt>>, r,p,t ) .sph

where

x=x(u,v), y=y(u,v), z=z(u,v)
r=r(u,v), t=t(u,v), z=z(u,v)
r=r(u,v), p=p(u,v), t=t(u,v)

%> irregular boundary
#> plot .x[21](-3,3).y[21](-sqrt(10-x*x),3+x) (  (x^2+y^2)*exp(1-x^2-y^2)  );


%> Mobius strip
#{
(a,b) = (4,2);;
plot .u(0,pi).v(-1,1) ( (a-v*sin(u))*cos(b*u), (a-v*sin(u))*sin(b*u), v*cos(u) );
#}
Mobius strip
%> Klein bottle
#{
plot .u(0,2*pi).v(0,2*pi) (
<< a = 2-cos(u), b = a*cos(v),
xu = 3*cos(u)*(1+sin(u)), yu = -8*sin(u) >>,
u < pi ? xu + b*cos(u) : xu-b,
u < pi ? yu – b*sin(u) : yu,
-a*sin(v)
);
#}

Klein bottle

%> Trefoil knot
#{
(a,b,c,d) = (0.5, 0.3, 0.5, 0.1);;
plot .u[51](0,2*pi).v[7](0,2*pi) (
<<
r = a + b*cos(3*u),
vp = < r*cos(2*u), r*sin(2*u), c*sin(3*u) >,
vq = < -1.5*b*sin(3*u)*cos(2*u) – vp.y,
-1.5*b*sin(3*u)*sin(2*u) + vp.x,
1.5*c*cos(3*u) > .unit,
vn = < vq.y, -vq.x, 0 > .unit,
vq ^= vn
>>,
vp + d*( vn*cos(v) + vq*sin(v) ) // vertex
);
#}

trefoil knot

//————————————————————————————————————
//  2D plots upgrade to 3D
//————————————————————————————————————
.xrev  [nt=21,gt=1](t1=0,t2=2*pi, a=0)
.yrev  [nt=21,gt=1](t1=0,t2=2*pi, b=0)
.zrev  [nt=21,gt=1](t1=0,t2=2*pi, c=0)
.lrev  [nt=21,gt=1](t1,t2 a,b,c)  line ax+by+c=0
.zpop  [nz= 3,gz=1](h,ratio=1) &&[nr=3,gr=1](Rb=0,Rt=0){bottom=1,top=1,inside=0}
.fill  [nf=21,gf=1]

%> revolution around the x-axis :  .xrev
#> plot .x[2](-2,2)(1).xrev;
#> plot+.x[2](-2,2)(1).xrev .zrot(pi/2);
#> plot+.x[2](-2,2)(1).xrev .yrot(pi/2);

three intersecting pipes

%> .side1 : close the starting side, x = a
%> .side2 : close the ending side, x = b
#> plot.x[13](-pi,2*pi) ( 3+cos(x) ) .ustep .xrev .side1.side2;

%> Spoke ‘.zpop’  : popping up from the 2D curve
.zpop  [nz= 3,gz=1](h,ratio=1) &&[nr=3,gr=1](Rb=0,Rt=0){bottom=1,top=1,inside=0}

void fpop(double ra,rb, bot,top,side, x,y,z) {
plot.@ t(0,1.5*pi)( 3*cos(t),2*sin(t) ).zpop[6](3,0.5) &&(ra,rb){bot,top,side}.move(x,y,z);
}
plot.hold;
fpop(0,0, 1,1,0, 0,0,10);
fpop(0,0, 0,1,0, 8,0,10);
fpop(0,0, 1,0,0, 16,0,10);
fpop(0,0, 0,0,1, 0,0,5);
fpop(0,0, 1,0,1, 8,0,5);
fpop(0,0, 0,0,0, 16,0,5);
fpop(0.2,0.2, 1,1,1, 0,0,0);
fpop(0.2,0.2, 0,1,1, 8,0,0);
fpop(0.2,0.2, 1,1,0, 16,0,0);
plot;

#> plot   .t[31](0,2*pi) ( 1+cos(t) ) .cyl .zpop[6](0.5)&&[21](0.5,0.5){1,1,1};
#> plot+.t[31](0,2*pi) ( 1+cos(t) ) .cyl .zpop(0.5)&&[21] .ymove(3);

//————————————————————————————————————
//  Spokes
//————————————————————————————————————

//—————
// 2D plots upgrade to 3D
//—————
.xrev  [nt=21,gt=1](t1=0,t2=2*pi, a=0)
.yrev  [nt=21,gt=1](t1=0,t2=2*pi, b=0)
.zrev  [nt=21,gt=1](t1=0,t2=2*pi, c=0)
.lrev  [nt=21,gt=1](t1,t2 a,b,c)  line ax+by+c=0
.zpop  [nz= 3,gz=1](h,ratio=1) &&[nr=3,gr=1](Rb=0,Rt=0){bottom=1,top=1,inside=0}
.fill  [nf=21,gf=1]

//————————————————————————————————————
// integration properties
//————————————————————————————————————
.int1da (f(x,y)) (fscalar)
.intxda (f(x,y)) (fscalar)
.intyda (f(x,y)) (fscalar)
.intxxda(f(x,y)) (fscalar)
.intxyda(f(x,y)) (fscalar)
.intyyda(f(x,y)) (fscalar)

.intdl   (f(x,y,z), … )                 (fscalar, …)
.intda   (f(x,y,z), … )                 (fscalar, …)
.intdL * (Fx(x,y,z),Fy(x,y,z),Fz(x,y,z)) (fscalar)
.intdL ^ (Fx(x,y,z),Fy(x,y,z),Fz(x,y,z)) (Fmatrix)
.intdL   (f(x,y,z))                      (Fmatrix)
.intdA * (Fx(x,y,z),Fy(x,y,z),Fz(x,y,z)) (fscalar)
.intdA ^ (Fx(x,y,z),Fy(x,y,z),Fz(x,y,z)) (Fmatrix)
.intdA   (f(x,y,z))                      (Fmatrix)
.area(area)
.volume(vol)

Comments are closed.