%@AUTEUR:Guillaume Connan
prologues:=2;

verbatimtex
%&latex
\documentclass{article}
\begin{document}
etex

input courbes;
input geo;

color vert_e, turquoise, orange, vert_fonce, rose, vert_mer, bleu_ciel, or, rouge_v,bleu_m,bleu,bleu_f;
vert_e:=(0,0.790002,0.340007);
turquoise:=(0.250999,0.878399,0.815699);
orange:=(0.589999,0.269997,0.080004);
vert_fonce:=(0,1.4*0.392193,0);
rose:=(1.0, 0.752907, 0.796106);
bleu_ciel:=(1.2*0.529405,1.2*0.807794,1);%.2*0.921598);
or:=(1,0.843104,0);
rouge_v:=(0.829997,0.099994,0.119999);
bleu_m:=(0.7*0.529405,0.7*0.807794,0.7);%*0.921598);
bleu_f:=(0.211762,0.3231176,0.3686392);
bleu:=(0.529405,0.807794,1);

%CENTRE D'INERTIE

vardef axes =
  drawarrow (ux*xmin,0) -- (ux*xmax,0); % axe des x
  drawarrow ((0,uy*ymin) -- (0,uy*ymax))  ; % axe des y
  label.rt(btex $x$ etex,(xmax*ux,0)); % label de l'axe des x
  label.urt(btex $y$ etex,(0,ymax*uy)); % label de l'axe des y
enddef;

numeric xmin, xmax, ymin, ymax, N;

ux:=1cm;  uy:=1cm;
xmin := -.5 ; xmax := 9;
ymin := -1.5 ; ymax := 3;

pair d,h;
d:=(.1*ux,0);
h:=(0,.1*uy);


beginfig(1);
  pair A,B; A:=(1*ux,0); B:=(7*ux,3*uy);
  
  path C; C:=A{dir10}..B{dir10};
  
  pair a,b; a:=A yscaled 0; b:=B yscaled 0;
  
  pair M,m; M:= point .7 of C; m:=M yscaled 0;
  pair N,n; N:= point .78 of C; n:=N yscaled 0;
  
  path U; U:=N--n; path V; V:=M--(M shifted (6*ux,0));
  
  pair X; X:= V intersectionpoint U;
  
  path W; W:=M--X--n--m--cycle;
  
  path r; r:=N--X--M;
  path Z; Z:=buildcycle(C,r);
  
  fill Z withcolor .2white;
  
  fill W withcolor bleu;
  
  path UU; UU:=(0,0)--(8*ux,0);
  
  pair XX; XX:= C intersectionpoint UU;
  
  path VV,K,WW; VV:=M--m; K:=m--XX; WW:=buildcycle(C,VV,K);
  path Y,ZZ; Y:=A--a--XX; ZZ:=buildcycle(C,reverse Y);
  path ZZZ,ZZZZ; ZZZ:=B--b--n--N; ZZZZ:=buildcycle(C,ZZZ);
  fill ZZZZ withcolor bleu_ciel;
  fill WW withcolor bleu_ciel; fill ZZ withcolor bleu_ciel;
  
% tracés
  
  axes;
  pickup  pencircle scaled 1.3bp;
  draw C withcolor bleu_f; label.rt(btex $y=f(x)$ etex,B shifted d)withcolor 0.3white;
  
  draw (A--a)  withcolor 0.3white; draw (B--b)  withcolor 0.3white;
  
  draw a--(a shifted h); label.top(btex $a$ etex,a shifted h);
  draw (b shifted h)--(b shifted -h); label.bot(btex $b$ etex,b shifted -h);
  
  draw (M--m)  withcolor 0.3white;
  
  draw (m shifted h)--(m shifted -h); label.bot(btex $x$ etex,m shifted -2h);
  
  draw (N--n) ; draw (n shifted h)--(n shifted -h);
  label.bot(btex {$x\!+\!\d x$} etex,n shifted -h +(0.3*ux,0));
  draw (X--(X xscaled 0)) withpen pencircle scaled 1bp;
  draw ((X xscaled 0)shifted d)--((X xscaled 0)shifted -d);
  label.lft(btex $f(x)$ etex,(X xscaled 0)shifted -d);
  dotlabel.top(btex $\mathbf{G_x}$ etex, ((M+N)/2) yscaled 0.5); 
endfig;
end