Asymptote using three.asy – fig0040

Category: Asymptote,Examples 3D,three.asyPh. Ivaldi @ 17 h 50 min

Figure 0004
(Compiled with Asymptote version 2.14svn-r5318)
    
import three;
size(8cm,0);
real radius=1, theta=37, phi=60;

currentprojection=perspective(4,1,2);

// Planes
pen bg=gray(0.9)+opacity(0.5);
draw(surface((1.2,0,0)--(1.2,0,1.2)--(0,0,1.2)--(0,0,0)--cycle),bg,bg);
draw(surface((0,1.2,0)--(0,1.2,1.2)--(0,0,1.2)--(0,0,0)--cycle),bg,bg);
draw(surface((1.2,0,0)--(1.2,1.2,0)--(0,1.2,0)--(0,0,0)--cycle),bg,bg);

real r=1.5;
draw(Label("$x$",1), O--r*X, Arrow3(HookHead3));
draw(Label("$y$",1), O--r*Y, Arrow3(HookHead3));
draw(Label("$z$",1), O--r*Z, Arrow3(HookHead3));
label("$\rm O$", (0,0,0), W);

triple pQ=radius*dir(theta,phi); // Point Q
// triple pQ=radius*expi(radians(theta),radians(phi)); // Point Q
draw(O--radius*dir(90,phi)^^O--pQ, dashed);
dot("$R*\mathrm{dir}\left(\theta,\phi\right)$",pQ);

// Arcs
draw("$\theta$", reverse(arc(O,0.5*pQ,0.5*Z)), N+0.3E, Arrow3(HookHead2));
draw("$\phi$", arc(O,0.5*X,0.5*(pQ.x,pQ.y,0)), N+0.3E, Arrow3(HookHead2));

path3 p3=O--arc(O,radius,0,phi,90,phi)--cycle;
draw(surface(p3), blue+opacity(0.5));

Étiquettes : , , , ,


Asymptote using three.asy – fig0060

Category: Asymptote,Examples 3D,three.asyPh. Ivaldi @ 19 h 50 min

Figure 0006
(Compiled with Asymptote version 2.14svn-r5318)
    
settings.render=0;
import three;
size(4cm,0);

currentprojection=perspective((45,45,30));
path3 YZ=plane((0,4,0),(0,0,4));

draw("$x$",project(O--X),Arrow);
draw("$y$",project(O--Y),Arrow);
draw("$z$",project(O--Z),Arrow);
draw(YZ);

label(scale(5)*project("A",Y,Z,(0,1,1)));

Étiquettes : , ,


Asymptote using three.asy – fig0070

Category: Asymptote,Examples 3D,three.asyPh. Ivaldi @ 20 h 50 min

Figure 0007
(Compiled with Asymptote version 2.14svn-r5318)
    
// From the Asymptote forum
import bsp;

typedef path3[] shape;

shape operator *(transform3 T, shape p){
  shape os;
  for(path3 g:p) os.push(T*g);
  return os;
}


path3 path(triple[] T){
  path3 P;
  for(triple i:T) P=P--i;
  return P;
}

void addshapes(face[] F, shape[] shp, pen drawpen=currentpen, pen fillpen=white)
{
  for(int i=0; i < shp.length; ++i)
    for(int j=0; j < shp[i].length; ++j) {
      path3 g=shp[i][j];
      picture pic=F.push(g);
      filldraw(pic,project(g),fillpen, drawpen);
      // filldraw(pic,g,currentlight.intensity(F[F.length-1].point)*fillpen, drawpen);
    }
}

shape cylinder(real R=1, real H=1, int n=18){
  shape Cyl;
  triple[] CTop;
  triple[] CBot;
  for(int i=0; i <= n; ++i)
    CBot.push((R*cos(2pi*i/n), R*sin(2pi*i/n),0));
  CTop = CBot+(0,0,H);
  for(int i=0; i < n; ++i)
    Cyl.push(CBot[i]--CBot[i+1]--CTop[i+1]--CTop[i]--cycle);

  path3 P=path(CBot)--cycle;
  Cyl.push(P);
  Cyl.push(shift(H*Z)*P);

  return Cyl;
}

shape rightslab(real x=1, real y=1, real z=1){
  shape slab;
  slab[0] = (0,0,0)--(1,0,0)--(1,1,0)--(0,1,0)--cycle;
  slab[1] = (0,0,0)--(1,0,0)--(1,0,1)--(0,0,1)--cycle;
  slab[2] = (1,0,0)--(1,1,0)--(1,1,1)--(1,0,1)--cycle;
  slab[3] = (1,1,0)--(0,1,0)--(0,1,1)--(1,1,1)--cycle;
  slab[4] = (0,1,0)--(0,0,0)--(0,0,1)--(0,1,1)--cycle;
  slab[5] = (0,0,1)--(1,0,1)--(1,1,1)--(0,1,1)--cycle;
  return scale(x,y,z)*slab;
}

size(10cm,0);
triple cam=(1600,200,150);
//currentprojection=orthographic(1600,800,400);
currentprojection=perspective(cam); //Far away!
currentlight=rotate(-45,Z)*(cam+(0,0,1000));

real Blen = 180;
real Bwdt = 30;
real Bhgt = 3;
real Clen = 130;
real Cwdt = 50;
real Chgt = 50;
real cylr = 7.5;
real cylh = 37.0 ;

shape slab1 = shift(-Bwdt/2*Y-Bhgt/2*Z+Clen/2*X)*rightslab(Blen,Bwdt,Bhgt);
shape slab2 = shift(-Cwdt/2*Y-Chgt/2*Z-Clen/2*X)*rightslab(Clen,Cwdt,Chgt);
shape cyl1 = shift((Blen+Clen/2-2*cylr)*X-(cylh/2)*Z)*cylinder(R=cylr, H=cylh);

shape[] group1={slab1};
shape[] group2={slab2};
shape[] group3={cyl1};

face[] faces;
addshapes(faces, group1, drawpen=linewidth(0.25bp), fillpen=opacity(0.35)+red);
addshapes(faces, group2, drawpen=linewidth(0.25bp), fillpen=opacity(0.5)+lightblue);
addshapes(faces, group3, drawpen=linewidth(0.25bp), fillpen=opacity(0.5)+lightyellow);
add(faces);

shipout(format="pdf", bbox(3mm,white));

Étiquettes : , ,


Asymptote using three.asy – fig0080

Category: Asymptote,Examples 3D,three.asyPh. Ivaldi @ 21 h 50 min

Figure 0008
(Compiled with Asymptote version 2.14svn-r5318)
    
import bsp;

typedef path3[] shape;

shape operator *(transform3 T, shape p){
  shape os;
  for(path3 g:p) os.push(T*g);
  return os;
}


path3 path(triple[] T){
  path3 P;
  for(triple i:T) P=P--i;
  return P;
}

void addshapes(face[] F, shape[] shp, pen drawpen=currentpen, pen fillpen=white)
{
  for(int i=0; i < shp.length; ++i)
    for(int j=0; j < shp[i].length; ++j) {
      path3 g=shp[i][j];
      picture pic=F.push(g);
      if(fillpen != nullpen) filldraw(pic,project(g),fillpen, drawpen);
      else draw(pic,project(g),drawpen);
      // filldraw(pic,g,currentlight.intensity(F[F.length-1].point)*fillpen, drawpen);
    }
}

shape cylinder(real R=1, real H=1, int n=18){
  shape Cyl;
  triple[] CTop;
  triple[] CBot;
  for(int i=0; i <= n; ++i)
    CBot.push((R*cos(2pi*i/n), R*sin(2pi*i/n),0));
  CTop = CBot+(0,0,H);
  for(int i=0; i < n; ++i)
    Cyl.push(CBot[i]--CBot[i+1]--CTop[i+1]--CTop[i]--cycle);

  path3 P=path(CBot)--cycle;
  Cyl.push(P);
  Cyl.push(shift(H*Z)*P);

  return Cyl;
}


size(10cm,0);

currentprojection=orthographic(1,1,1);

shape cyl1 = cylinder(R=1, H=2);

shape[] group={cyl1};

face[] hidden, visible;
addshapes(hidden, group, drawpen=linewidth(bp));
addshapes(visible, group, drawpen=dotted, fillpen=nullpen);
add(hidden);
add(visible);

shipout(format="pdf");

Étiquettes : , , ,


Asymptote using three.asy – fig0090

Category: Asymptote,Examples 3D,three.asyPh. Ivaldi @ 22 h 50 min

Figure 0009
(Compiled with Asymptote version 2.14svn-r5318)
    
size(10cm,0);
import three;

currentprojection=obliqueX;

triple v1=(4,0,0),
       v2=(0,6,0),
       p0=(-2,-3,0);
path3 pl1=plane(v1,v2,p0);

path ph=transform(v1,v2,p0,currentprojection)*((0,-2){W}..(0,2){W}..cycle);
filldraw(project(pl1)^^ph,evenodd+lightgrey);

Étiquettes : , , , , ,


Asymptote using three.asy – fig0100

Category: Asymptote,Examples 3D,three.asyPh. Ivaldi @ 23 h 50 min

Figure 0010
(Compiled with Asymptote version 2.14svn-r5318)
    
size(12cm,0);
import bsp;

currentprojection=orthographic(1,1.5,1);

path3 xy=plane((1,0,0),(0,1,0),(0,0,0));
path3 xz=rotate(90,X)*xy;
path3 yz=rotate(-90,Y)*xy;

face[] f;
filldraw(f.push(xy),project(xy),grey);
filldraw(f.push(xz),project(xz),grey);
filldraw(f.push(yz),project(yz),grey);
add(f);

draw(Label("$x$",EndPoint), O--(1,0,0), Arrow3);
draw(Label("$y$",EndPoint), O--(0,1,0), Arrow3);
draw(Label("$z$",EndPoint), O--(0,0,1), Arrow3);
dot(O);

path[] ph=texpath("$\displaystyle\int_{-\infty}^{+\infty}e^{-\alpha x^2}\,dx=
\sqrt{\frac{\pi}{\alpha}}$");
ph =shift((0.5,0.5))*rotate(-45)*scale(1/abs(min(ph)-max(ph)))*ph;

filldraw(project(path3(ph,XYplane)),0.8*yellow);
filldraw(project(path3(ph,ZXplane)),0.8*yellow);
filldraw(project(path3(ph,YZplane)),0.8*yellow);

Étiquettes : , , , , ,


Asymptote using three.asy – fig0110

Category: Asymptote,Examples 3D,three.asyPh. Ivaldi @ 0 h 50 min

Figure 0011
(Compiled with Asymptote version 2.14svn-r5318)
    
import three;
size(10cm,0);
currentprojection=orthographic(1,1.5,1);

path3 xy=XY*unitsquare3, xz=ZX*unitsquare3, yz=YZ*unitsquare3;

draw(xy^^xz^^yz, grey);
path3 p3xy=path3(texpath("$\pi$")[0],XYplane);
p3xy=shift((0.5,0.5,0))*scale3(1/abs(min(p3xy)-max(p3xy)))*p3xy;

surface s=surface(p3xy,planar=true);
draw(s, surfacepen=blue, meshpen=orange+3pt);

transform3 Txz=planeproject(xz,(0,-1,1));
draw(Txz*s, red);

transform3 Tyz=planeproject(yz,(-1,0,1));
draw(Tyz*s, green);

path3 p3xz=Txz*p3xy;
path3 p3yz=Tyz*p3xy;

int lg=length(p3xy);
triple p;
for(int i=0;i<=lg;++i) {
  p=point(p3xy,i);
  draw(p--point(p3xz,i), yellow);
  draw(p--point(p3yz,i), orange);
}

Étiquettes : , , , ,


Asymptote using solids.asy – fig0080

Category: Asymptote,Examples 3D,solids.asyPh. Ivaldi @ 9 h 56 min

Figure 0008
(Compiled with Asymptote version 2.14svn-r5318)
    
import solids;
import palette;
size(14cm,0);
currentlight=light(gray(0.4),specularfactor=3,viewport=false,
                   (-0.5,-0.25,0.45),
                   (0.5,-0.5,0.5),(0.5,0.5,0.75));

nslice=4*nslice;
surface s=surface(sphere(O,1));
draw(s,lightgrey);

path3 pl=plane((1,0,0),(0,1,0),(0,0,-1));
surface pls=shift(3,3,-1e-3)*scale(-6,-6,1)*surface(pl);
draw(pls,0.7*red);

real dist(triple z){return abs(z-Z);}

surface shade;
for (int i=0; i < currentlight.position.length; ++i) {
  shade=planeproject(pl,currentlight.position[i])*s;
  draw(shade,mean(palette((shade.map(dist)),
                          Gradient(black,gray(0.6)))),
       nolight);
}

Étiquettes : , , , , , ,


Official Asymptote example – unitcircle3

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 14 h 57 min

Figure 0247
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import three;

size(100);

path3 g=(1,0,0)..(0,1,0)..(-1,0,0)..(0,-1,0)..cycle;
draw(g);
draw(O--Z,red+dashed,Arrow3);
draw(((-1,-1,0)--(1,-1,0)--(1,1,0)--(-1,1,0)--cycle));
dot(g,red);

Étiquettes : , ,


Animation with Asymptote – fig0090

Category: Animation,AsymptotePh. Ivaldi @ 16 h 20 min

Figure 0009
(Compiled with Asymptote version 1.86svn-r4626)
    
size(0,10cm);
import graph3;
import animation;
import solids;

currentlight.background=black;
settings.render=0;
animation A;
A.global=false;

int nbpts=500;
real q=2/5;
real pas=5*2*pi/nbpts;
int angle=4;
real R=0.5;
pen p=rgb(0.1,0.1,0.58);
triple center=(1,1,1);
transform3 T=rotate(angle,center,center+X+0.25*Y+0.3*Z);

real x(real t){return center.x+R*cos(q*t)*cos(t);}
real y(real t){return center.y+R*cos(q*t)*sin(t);}
real z(real t){return center.z+R*sin(q*t);}

currentprojection=orthographic(1,1,1);
currentlight=(0,center.y-0.5,2*(center.z+R));

triple U=(center.x+1.1*R,0,0), V=(0,center.y+1.1*R,0);
path3 xy=plane(U,V,(0,0,0));
path3 xz=rotate(90,X)*xy;
path3 yz=rotate(-90,Y)*xy;

triple[] P;
path3 curve;
real t=-pi;
for (int i=0; i < nbpts; ++i) {
  t+=pas;
  triple M=(x(t),y(t),z(t));
  P.push(M);
  curve = curve..M;
}

curve=curve..cycle;

draw(surface(xy), grey);
draw(surface(xz), grey);
draw(surface(yz), grey);

triple xyc=(center.x,center.y,0);
path3 cle=shift(xyc)*scale3(R)*unitcircle3;
surface scle=surface(cle);
draw(scle, black);
draw(rotate(90,X)*scle, black);
draw(rotate(-90,Y)*scle, black);

draw(surface(sphere(center,R)), p);

triple vcam=1e5*currentprojection.camera-center;
for (int phi=0; phi<360; phi+=angle) {
  bool[] back,front;
  save();

  for (int i=0; i<nbpts; ++i) {
    P[i]=T*P[i];
    bool test=dot(P[i]-center,vcam) > 0;
    front.push(test);
  }

  curve=T*curve;
  draw(segment(P,front,operator ..), paleyellow);
  draw(segment(P,!front,operator ..),0.5*(paleyellow+p));
  draw((planeproject(xy)*curve)^^
       (planeproject(xz)*curve)^^
       (planeproject(yz)*curve), paleyellow);

  A.add();
  restore();
}

A.movie(options="-density 350 -resample 96 -quality 100 -depth 8 -strip");

Étiquettes : , , , , , , , ,