Asymptote using three.asy – fig0050

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
import three; import math;
size(8cm,0);
currentprojection=obliqueX;

real h=2;
triple A =(0,0,h), B=(h,0,0), C=(0,h,0), D=(0,0,0);
triple Ip=midpoint(A--C), J=midpoint(A--B);
triple K=shift((0,0,-0.25*h))*A;

triple M=interp(K,J,intersect(K,J,normal(new triple[]{B,C,D}),D));
triple Np=interp(K,Ip,intersect(K,Ip,normal(new triple[]{B,C,D}),D));

dot("\$A\$", A, align=Z);  dot("\$B\$", B, align=S);
dot("\$C\$", C, align=S);  dot("\$D\$", D, align=W);
dot("\$I\$", Ip, align=N); dot("\$J\$", J, align=W);
dot("\$K\$", K, align=NE); dot("\$M\$", M, align=SE);
dot("\$N\$", Np, align=S);

draw(A--B--C--cycle^^B--M^^C--Np^^J--M^^Ip--Np);
draw(A--D--C^^D--B^^J--K^^K--Ip, dashed);

```

Étiquettes : , , , ,

Asymptote using three.asy – fig0070

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

 (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;

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

```

Étiquettes : , ,

Asymptote using three.asy – fig0080

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

 (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;

shipout(format="pdf");

```

Étiquettes : , , ,

Asymptote using solids.asy – fig0030

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
// Author: John Bowman.
size(6cm,0);
import solids;
currentprojection=orthographic(0,10,5);

nslice=4*nslice;

revolution r=sphere(O,1);
draw(surface(r), lightgrey+opacity(0.75));

skeleton s;
r.transverse(s,reltime(r.g,0.6));
r.transverse(s,reltime(r.g,0.5));
draw(s.transverse.back,linetype("8 8",8));
draw(s.transverse.front);

r.longitudinal(s);
draw(s.longitudinal.front);
draw(s.longitudinal.back,linetype("8 8",8));

```

Étiquettes : , , , , , ,

Asymptote using solids.asy – fig0100

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
unitsize(1cm);
import solids;

currentprojection=orthographic(0,100,25);

real r=4, h=7;
triple O=(0,0,0);
triple Oprime=(0,0,3);
triple pS=(0,0,h);
triple pA=(r*sqrt(2)/2,r*sqrt(2)/2,0);
revolution rC=cone(O,r,h,axis=Z,n=1);

draw(surface(rC),blue+opacity(0.5));

skeleton s;
real tOprime=abs(Oprime)/h;
rC.transverse(s,reltime(rC.g,tOprime));
triple pAprime=relpoint(pA--pS,tOprime);
draw(s.transverse.back,dashed);
draw(s.transverse.front);

label("\$S\$",pS,N);
dot(Label("\$O\$",align=SE),O);
dot(Label("\$O'\$",align=SE),Oprime);
dot(Label("\$A\$",align=Z),pA);
dot(Label("\$A'\$",align=Z),pAprime);

draw(pS--O^^O--pA^^Oprime--pAprime,dashed);

```

Étiquettes : , , ,

Asymptote using solids.asy – fig0110

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
import solids;
unitsize(4cm);

currentprojection=orthographic(2,2,1);

draw(cylinder(c=(0,0,-1.5),r=1,h=3), m=3);
draw(sphere(r=1), m=2, frontpen=defaultbackpen);

```

Étiquettes : , , ,

Asymptote using solids.asy – fig0120

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
import solids;

size(10cm,0);
currentprojection=orthographic(-50,100,40);

//Draw right angle (MA,MB) in 3D
void drawrightangle(picture pic=currentpicture,
triple M, triple A, triple B,
pen p=currentpen,
pen fillpen=nullpen,
projection P=currentprojection)
{
p=linejoin(0)+linecap(0)+p;
transform3 T=shift(-M);
OC=OA+OB;
path3 _p=OA--OC--OB;
picture pic_;
draw(pic_, _p, p=p);
if (fillpen!=nullpen) draw(pic_, surface(O--_p--cycle), fillpen);
}

// *...............Construction starts here................*

real r=1, h=.75;
real gle=60;
real gleA=20;
transform3 tR=rotate(gle,Z);
transform3 tT=shift((0,0,-h));

triple H=(0,0,h),//the label is O in the picture.
A=rotate(gleA,Z)*(0,r,h),
F=tR*A,
B=tR*F,
D=tT*A,
C=tT*B,
Ei=intersectionpoint(H--F,A--B);

revolution r=cylinder(O,r,h,Z);
// draw(surface(r));
draw(r);

draw(O--H, dashed);
draw(O--D--C--cycle^^O--H^^B--C, dashed);

drawrightangle(Ei,H,B,fillpen=black);

dot(Label("\$O'\$",align=invert(NE+E,O)), O);
// layer();
draw(surface(A--B--C--D--cycle),lightgrey+opacity(.5));

dot(Label("\$A\$",align=NW), A);
dot(Label("\$B\$",align=N),B);
dot(Label("\$C\$",align=S), C);
dot(Label("\$D\$",align=NW), D);
dot(Label("\$E\$",align=S), Ei);
dot(Label("\$F\$",align=S), F);
dot(Label("\$O\$",align=N), H);

draw(H--B--F--A--cycle^^H--F^^A--B^^A--D);

```

Étiquettes : , , , ,

Official Asymptote example – spheresilhouette

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

 (Compiled with Asymptote version 2.14svn-r5318)
```/* This code comes from The Official Asymptote Gallery */

import solids;
settings.render=0;
settings.prc=false;

size(200);

revolution r=sphere(O,1);
draw(r,1,longitudinalpen=nullpen);
draw(r.silhouette());

```

Étiquettes : , , , ,

Official Asymptote example – sphereskeleton

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

 (Compiled with Asymptote version 2.14svn-r5318)
```/* This code comes from The Official Asymptote Gallery */

size(100);
import solids;

currentprojection=orthographic(5,4,2);

revolution sphere=sphere(1);
draw(surface(sphere),green+opacity(0.2));
draw(sphere,m=7,blue);

```

Étiquettes : , , , ,