Outils du site


wiki:asymptote:exemples:geometry

Module geometry

Cliquer sur les figures pour faire apparaitre le code asymptote associé.

Commande distance

8b08fe0539885af2b9d931a34dd7707b.png

size(6cm,0);
import geometry;
usepackage("pifont");

real a = 3, b = 4, c = 10;

point pA = (0,0);
point pB = (3.5,0);
point pC = (c,0);
point pD = (c,3);
point pE = (c,a+b);
point pF = (3.5,a+b);
point pG = (0,a+b);
point pH = (0,a);
point pI = intersectionpoint(pB--pF,pH--pD);

fill(pB--pI--pD--pC--cycle,lightgrey);
fill(pH--pI--pF--pG--cycle,lightgrey);

draw(pA--pC--pE--pG--cycle);
draw(pH--pD^^pB--pF);

distance(Label("$10~\mathrm{cm}$",align=N),pG,pE,-2mm);
distance(Label("$4~\mathrm{cm}$",align=W),pH,pG,-2mm);
distance(Label("$3~\mathrm{cm}$",align=W),pA,pH,-2mm);
distance(Label("$x~\mathrm{cm}$",align=S),pA,pB,2mm);

label(scale(1.5)*Label("\ding{172}"),intersectionpoint(pI--pG,pH--pF));
label(scale(1.5)*Label("\ding{173}"),intersectionpoint(pI--pC,pB--pD));

shipout(bbox(xmargin=1mm,invisible));

fcc329a6f1a783038fe5cf9646318eab.png

size(16cm,0);
import geometry;

real di = 29, ab = 288, eb = 48, fg = 52, dj = 72, ac = 312, bc = sqrt(ac^2-ab^2);

point pA = (0,bc);
point pB = (ab,bc);
point pC = (ab,0);
point pD = (0,0);
point pI = (di,0);
point pJ = (0,dj);
point pH = (ab-eb, 0);
point pG = (ab,eb);
point pF = (ab,eb+fg);
point pE = (ab-eb,bc);
point pX = (ab-eb,eb);

draw(pA--pJ--pI--pH{E}..{N}pG--pF--pE--pA, black+2bp);

dot(Label("$A$",align=NW),pA);
dot(Label("$B$",align=NE),pB);
dot(Label("$C$",align=SE),pC);
dot(Label("$D$",align=SW),pD);
dot(Label("$I$",align=S),pI);
dot(Label("$J$",align=W),pJ);
dot(Label("$H$",align=S),pH);
dot(Label("$G$",align=E),pG);
dot(Label("$F$",align=E),pF);
dot(Label("$E$",align=N),pE);

draw(pA--pB--pC--pD--cycle, dashed);
draw(pH--pX--pG, dashed);
draw(pA--pJ, invisible, StickIntervalMarker(1,2,angle=40,red));
draw(pE--pB, invisible, StickIntervalMarker(1,2,angle=40,red));
draw(pH--pX, invisible, StickIntervalMarker(1,2,angle=40,red));
draw(pX--pG, invisible, StickIntervalMarker(1,2,angle=40,red));

markrightangle(pA,pD,pC,blue);
markrightangle(pD,pC,pB,blue);
markrightangle(pC,pB,pA,blue);
markrightangle(pB,pA,pD,blue);
markrightangle(pG,pX,pH,blue);
markrightangle(pF,pG,pX,blue);

distance("$48$", pB, pE, offset=8mm);
distance("$288$", pB, pA, offset=14mm);
distance("$312$", pA, pC, offset=0mm);
distance("$52$", pG, pF, offset=8mm, rotated=false);
distance("$29$", pD, pI, offset=8mm);
distance("$72$", pJ, pD, offset=8mm, rotated=false);

shipout(bbox(xmargin=1mm,invisible));

9b410f26d1dfd7e727fac70593b2f6f7.png

size(0,8cm);
import geometry;
usepackage("icomma");

currentcoordsys=cartesiansystem(i=(1,0),j=rotate(30)*xscale(0.4)*(1,0));

real a = 12, b = 9, c = 4, d = c+9, k = 0.4;

point pA = (0,0), pB = (a,0), pC = (a,b), pD = (0,b);
point pE = shift(0,c)*pA/currentcoordsys;
point pF = shift(0,c)*pB/currentcoordsys;
point pG = shift(0,c)*pC/currentcoordsys;
point pH = shift(0,c)*pD/currentcoordsys;
point pS = shift(0,d)*midpoint(pA--pC)/currentcoordsys;
point pI = relpoint(pE--pS,k)/currentcoordsys;
point pJ = relpoint(pF--pS,k)/currentcoordsys;
point pK = relpoint(pG--pS,k)/currentcoordsys;
point pL = relpoint(pH--pS,k)/currentcoordsys;

draw(pA--pB--pC^^pE--pF--pG^^pI--pJ--pK^^pA--pE^^pB--pF^^pC--pG);
draw(pA--pD--pC^^pE--pH--pG^^pI--pL--pK^^pD--pH, dashed);

draw(pE--pS^^pF--pS^^pG--pS);
draw(pH--pS, dashed);

dot(Label("$A$",align=W),pA);
dot(Label("$B$",align=NW),pB);
dot(Label("$C$",align=E),pC);
dot(Label("$D$",align=NW),pD);
dot(Label("$E$",align=W),pE);
dot(Label("$F$",align=SE),pF);
dot(Label("$G$",align=E),pG);
dot(Label("$H$",align=NW),pH);
dot(Label("$I$",align=NW),pI);
dot(Label("$J$",align=SW),pJ);
dot(Label("$K$",align=NE),pK);
dot(Label("$L$",align=SE),pL);
dot(Label("$S$",align=N),pS);

distance(Label("$12\,\mathrm{m}$",align=S),pA,pB,6mm);
distance(Label("$9\,\mathrm{m}$",align=S*dir(pB--pC)),pB,pC,6mm);
distance(rotate(180)*Label("$3\,\mathrm{m}$",align=W),pA,pE,-1cm);
distance(rotate(180)*Label("$6,75\,\mathrm{m}$",align=W),pE,projection(pA,pE)*pS,-1cm);
distance(rotate(180)*Label("$4,5\,\mathrm{m}$",align=W),projection(pA,pE)*pI,projection(pA,pE)*pS,0cm);

shipout(bbox(xmargin=1mm,invisible));

06d20d53e96db857462de78df9c5686c.png

size(9cm,0);
import geometry;

currentcoordsys=cartesiansystem(i=(1,0),j=rotate(30)*xscale(0.4)*(1,0));

real a = 12, b = 9, c = 3, d = 4;

point pA = (0,0), pB = (a,0), pC = (a,b), pD = (0,b);
point pE = shift(0,c)*pA/currentcoordsys;
point pM = shift(0,c)*pB/currentcoordsys;
point pN = shift(0,c)*pC/currentcoordsys;
point pH = shift(0,c)*pD/currentcoordsys;
point pI = shift(0,c)*pE/currentcoordsys;
point pJ = shift(b-a,c)*pM/currentcoordsys;
point pK = shift(b-a,c)*pN/currentcoordsys;
point pL = shift(0,c)*pH/currentcoordsys;
point pS = shift(0,d)*midpoint(pI--pK)/currentcoordsys;
point pF = projection(pE,pM)*pJ;
point pG = projection(pH,pN)*pK;

draw(pA--pB--pC^^pE--pM--pN^^pI--pJ--pK^^pA--pI^^pB--pM^^pC--pN^^pK--pG--pN^^pJ--pF--pG);
draw(pA--pD--pC^^pE--pH--pG^^pI--pL--pK^^pD--pL, dashed);

draw(pI--pS^^pJ--pS^^pK--pS);
draw(pL--pS, dashed);

distance(Label("$12\,\mathrm{m}$",align=S),pA,pB,5mm);
distance(Label("$9\,\mathrm{m}$",align=S*dir(pB--pC)),pB,pC,5mm);
distance(Label("$3\,\mathrm{m}$",align=W),pA,pE,-1cm,joinpen=dotted);
distance(Label("$3\,\mathrm{m}$",align=W),pE,pI,-1cm,joinpen=dotted);
distance(Label("$3\,\mathrm{m}$",align=N),pG,pN,-2cm,joinpen=dotted);
distance(Label("$5\,\mathrm{m}$",align=W),pI,projection(pA,pE)*pS,-1cm,joinpen=dotted);
draw(projection(pA,pE)*pS--pS,dotted);

shipout(bbox(xmargin=1mm,invisible));

Des points sur un cercle (1)

96f5a94ed0a23ba89f85652fc45d144d.png

import geometry;
size(5cm);
point pM=(0,1), pK=(3,-1);
circle c=circle(pM,pK);
point[] pL=intersectionpoints(rotate(28,pK)*line(pK,pM),c);
draw(c,bp+purple);
dot("$M$",pM,NW);dot("$L$",pL[1],SW);dot("$K$",pK,SE);
draw(pM--pL[1]--pK--cycle,bp+.8blue);
dot("$O$",c.C,NE); // c.C : centre du cercle c
markangle("$28^\circ$",pM,pK,pL[1]);

Des points sur un cercle (2)

Utilisation de angpoint.

5452f589c3222e191f681b6af8ea5eed.png

import geometry;
size(5cm);
real ang=46;
point pS=(0,0);
circle c=circle(pS,1);
point pE=angpoint(c,120), pC=angpoint(c,220);
point pN=angpoint(c,40), pO=angpoint(c,80);
point[] pA=intersectionpoints(rotate(ang,pE)*line(pE,pC),c);
draw(c); draw(pE--pC^^pE--pA[0],dashed);
draw(c.C--pA[0]^^pC--pN^^pO--pN^^pO--pA[0]);
markangle(format("$%0g^\circ$",ang),radius=.75*cm,pC,pE,pA[0]);
markangle("?",radius=.75*cm,pA[0],pO,pN);
label("$C$",pC,SW);label("$N$",pN,NE);
label("$S$",c.C,S+.2W);label("$A$",pA[0],SE);
label("$E$",pE,N);label("$O$",pO,N);

Encore des cercles

On notera la conversion du type circle en type path afin d'utiliser radialshade.

b91d172d190c483bed3652c38984807c.png

import geometry;
size(9cm);
real rs=2, rl=.7, sl=5;
point sol=(0,0), L=(sl,0);
circle cs=circle(sol,rs), cl=circle(L,rl);
point M=angpoint(cs,80), P=angpoint(cl,80); // (SM)//(LP)
point T=intersectionpoint(line(M,P),line(sol,L));
circle ct1=circle(sol,T), ct2=circle(L,T);
point[] O=intersectionpoints(cs,ct1), U=intersectionpoints(cl,ct2); // des tableaux de points car il y a deux points d'intersection
radialshade((path)cl,white,L,.1,grey,L,rl); // radialshade n'accepte que le type "path"
radialshade((path)cs,white,sol,.3,yellow+orange,sol,rs);
draw(cs,.5yellow); draw(cl);
draw(T--sol--O[1]--cycle^^O[1]--sol^^U[1]--L);
label("$S$",sol,S); label("$L$",L,S); label("$T$",T,S);
label("$O$",O[1],unit(O[1]-sol)); label("$U$",U[1],unit(U[1]-L));
markrightangle(L,U[1],T,3mm,red);
markrightangle(sol,O[1],T,3mm,red);
clip(box((-.75,-.75),(T.x+5mm,O[1].y+5mm))); //accès aux coordonnées de T (abscisse) et O[1] (ordonnée)

Un exemple de programmation

Utilisation de void pour la création d'une fonction.

0769c405e5bd9e05dc8b4fee914c5345.png

import geometry;
size(6cm);

void demidN(picture pic=currentpicture, real n){
	pen pint;
	point C=((n+1)/2,0);
	circle c=circle(C,(n+1)/2);
	arc DC=arc(c,0,180);
	path surf=DC--cycle;
	if (n%2==0){pint=mediumyellow;}
	else {pint=heavygreen;}
	filldraw(surf,pint,linewidth(bp));
	if (n==1) {label("$u_1$",(1,0),N);}
	else {label(format("$u_%f$",n),(n+.5,0),N);}
}

for(int i=5; i>0; --i) {demidN(i);}
draw((0,0)--(6.3,0));
for(int i=0; i<7; ++i) {dot(format("$%i$",i),(i,0),S);}

Cercles de Ford

Utilisation d'une boucle while.

1fe039c9ec87e9c9e698c23a28160ca2.png

unitsize(5cm);
int N = 7;
int A = 0, B = 1, C = 1, D = N;

void draw_circle(int a, int b, int d)
{
real r = 1/(2*b^2);
draw(circle((a/b,r),r),blue);
}

void ford_iterate()
{
int K = floor((N+B)/D);
int E = K*C-A;
int F = K*D-B;
A = C;
B = D;
C = E;
D = F;
}

draw_circle(A, B, D);
while (C < N)
{
ford_iterate();
draw_circle(A, B, D);
}

shipout(bbox(xmargin=1mm,invisible));

wiki/asymptote/exemples/geometry.txt · Dernière modification: 2017/04/17 15:16 par MB