Retour

Source : outilssyr.mp

outilssyr.mp
%%--------------------------------------
%%outilssyr.mp
%%(Adaptation du fichier outilspoint.mp)
%%Création : Jeudi 13 Mars 2003
%%Dernière modification : 24/03/2008
%%--------------------------------------
 
%%Nécessaire pour les graduations
def position(suffix pos)=
  if str pos="n" : top
  elseif str pos="s" :bot
  elseif str pos="o" :lft
  elseif str pos="e" :rt
  elseif str pos="se" :lrt
  elseif str pos="so" :llft
  elseif str pos="ne" :urt
  elseif str pos="no" :ulft
  fi
enddef;
 
vardef affixe@#(expr a) text pos =
  x@#:=xpart a;
  y@#:=ypart a;
  label.position(pos)( str @#,z@#);
enddef;
%%Equerre
vardef equerre(expr dte,drte,perpe,sens,lo)=
  save $;
  picture $,fig;
  fig=currentpicture;
  pair ww,t[];
  picture grad[],gradu[];
  numeric long;
  path intermede;
  pair perpen,ptt,pttt;
  perpen:=projection(perpe,dte,drte);
  if sens=1 :
    ptt:=lo*(drte-dte) rotated 90 shifted perpen;
  else :
    ptt:=lo*(drte-dte) rotated (-90) shifted perpen;
  fi;
  ww=unitvector(drte-dte);
  intermede=ptt--(10[ptt,(perpen rotatedabout(ptt,30))]);
  pttt:=intermede intersectionpoint (10[dte,drte]--10[drte,dte]);
  long=floor(abs(perpen+7*unitvector(ptt-perpen)-ptt)*2.54/72);
  gradu1=image(
    for j=0 upto (2*long-1) :
      for k=1 upto 4:
	t[5*j+k]=(perpen+7*unitvector(ptt-perpen)) shifted (1mm*(5*j+k)*unitvector(ptt-perpen));
	t[400+5*j+k]=t[5*j+k] shifted (2*sens*ww);
	draw t[5*j+k]--t[400+5*j+k];
      endfor;
    endfor
    );
  gradu2=image(
    for j=0 upto (long-1):
      t[5*(2*j+1)]=(perpen+7*unitvector(ptt-perpen)) shifted (1mm*5*(2*j+1)*unitvector(ptt-perpen));
      t[400+5*(2*j+1)]=t[5*(2*j+1)] shifted (4*sens*ww);
      draw t[5*(2*j+1)]--t[400+5*(2*j+1)];
    endfor
    );
  gradu3=image(
    for j=0 upto long:
      t[10*j]=(perpen+7*unitvector(ptt-perpen)) shifted (1mm*10*j*unitvector(ptt-perpen));
      t[400+10*j]=t[10*j] shifted (7*sens*ww);
      if abs(ptt-t[10*j])>5mm:
	draw t[10*j]--t[400+10*j];
      fi
    endfor
    );
  for j=0 upto long:
    grad[j]=image(
      affixe[j](t[400+10*j])s;
      currentpicture:=currentpicture rotatedabout(t[400+10*j],90+angle(t[400+10*j]-t[10*j]));
      );
  endfor;
  $=image(
    path ouverture;
    ouverture:=buildcycle(droite(1/5[perpen,pttt] shifted (10mm*unitvector(ptt-perpen)),1/5[pttt,perpen] shifted (10mm*unitvector(ptt-perpen))),droite(1/5[perpen,ptt] shifted (10mm*unitvector(pttt-perpen)),1/5[ptt,perpen] shifted (10mm*unitvector(pttt-perpen))),droite((1/5[pttt,ptt] shifted (10mm*unitvector(ptt-pttt))) rotatedabout(1/5[pttt,ptt],90),(1/5[ptt,pttt] shifted (10mm*unitvector(ptt-pttt))) rotatedabout(1/5[ptt,pttt],90)));
    draw ouverture;
    draw perpen--ptt--pttt--cycle;
    draw codeperp(ptt,perpen,pttt,5);
    for j=0 upto long:
      if abs(z.[j]-ptt)>1cm :
	draw grad[j];
      fi
    endfor;
    for j=1 upto 3:
      draw gradu[j];
    endfor;
    draw fig;
    fig:=currentpicture;
    currentpicture:=nullpicture;
    fill (perpen--ptt--pttt--cycle) withcolor 0.9*white;
    fill ouverture withcolor white;
    draw fig;
    );
  $
enddef;
%%Règle
vardef regle(expr depart,arrivee,rr)=
  save $;
  picture $,grad[],gradu[],final;
  pair t[];
  path reduit;
  t1000=depart shifted (5*unitvector(depart-arrivee));
  t1003=arrivee shifted (20*unitvector(arrivee-depart));
  t1004=(unitvector(arrivee-depart) rotated (-90)) shifted t1000;
  t1001=t1000 shifted (50*(t1004-t1000));
  t1002=t1001 shifted (t1003-t1000);
  reduit=t1000--t1001--t1002..(t1002 shifted(5*unitvector(t1001-t1002)+1/4(t1003-t1002)))..(t1002 shifted(5*unitvector(t1002-t1001)+2/4(t1003-t1002)))..(t1002 shifted(5*unitvector(t1001-t1002)+3/4(t1003-t1002)))..t1003--cycle;
  gradu1=image(
    for k=0 upto 59:
      for j=1 upto 4:
	t[5*k+j]=depart shifted (1mm*(5*k+j)*unitvector(arrivee-depart));
	t[400+5*k+j]=t[5*k+j] shifted (2*(t1004-t1000));
	draw t[5*k+j]--t[400+5*k+j];
      endfor;
    endfor
    );
  gradu2=image(
    for k=0 upto 29:
      t[5*(2*k+1)]=depart shifted (1mm*5*(2*k+1)*unitvector(arrivee-depart));
      t[400+5*(2*k+1)]=t[5*(2*k+1)] shifted (5*(t1004-t1000));
      draw t[5*(2*k+1)]--t[400+5*(2*k+1)];
    endfor
    );
  gradu3=image(
    for k=0 upto 30:
      t[10*k]=depart shifted(1mm*10*k*unitvector(arrivee-depart));
      t[400+10*k]=t[10*k] shifted (10*(t1004-t1000));
      draw t[10*k]--t[400+10*k];
    endfor
    );
  for j=0 upto 30:
    grad[j]=image(
      affixe[j](t[400+10*j])s;
      currentpicture:=currentpicture rotatedabout(t[400+10*j],90+angle(t[400+10*j]-t[10*j]));
      );
  endfor
  final=image(
    for k=0 upto 30:
      draw grad[k];
    endfor
    for k=1 upto 3:
      draw gradu[k];
    endfor
    clip currentpicture to reduit;
    draw reduit;
    );
  if rr=-1:
    $=image(
      draw final rotatedabout(1/2[depart,arrivee],180);
      );
  else:
    $=image(
      draw final;
      );
  fi
  $
enddef;
%%Crayon
vardef crayon(expr depart,arrive,l,m)=
  save $;
  picture $,crayolat;
  pair w[];
  w0=(0,0);
  w1=(1,2)*u/2;
  w2=(-1,2)*u/2;
  w3=(0,2)*u/2;
  w4=(0,7)*m*u/2;
  path ccc,ccd;
  ccc=cercles(w0,abs(w3-w2));
  ccd=ccc yscaled 0.25 shifted w3;
  crayolat=image(
    draw subpath((length ccd)/2,length ccd) of ccd;
    draw ccd shifted (w4-w3);
    draw w2--w0--w1;
    draw w1--((1,7*m)*u/2);
    draw w2--((-1,7*m)*u/2);
    );
  $=(crayolat rotated(angle(arrive-depart)-30)) shifted l[depart,arrive];
  $
enddef;
%%Rapporteur
vardef rapporteurdouble(expr centre,segment,rr)=
  save $,cc,cd,v,w,t,ww,vv;
  picture $;
  path cc,cd;
  pair a[],b[],v,w,t,ww,vv,rap[],rapp[];
  cc=cercle(centre,0.75*abs(centre-segment));
  t=cc intersectionpoint (centre--segment);
  w=t-2*unitvector(segment-centre);v=symetrie(w,t);
  ww=t-5*unitvector(segment-centre);vv=symetrie(ww,t);
  a0=(ww-centre) shifted centre;
  b0=(vv-centre) shifted centre;
  for i=0 upto 35 :
    for j=1 upto 4 :
      a[5*i+j]=(w-centre) rotated (rr*(5*i+j)) shifted centre;
      b[5*i+j]=(v-centre) rotated (rr*(5*i+j)) shifted centre;
    endfor;
    a[5*(i+1)]=(ww-centre) rotated (rr*(5*(i+1))) shifted centre;
    b[5*(i+1)]=(vv-centre) rotated (rr*(5*(i+1))) shifted centre;
  endfor
  picture nomb[],nombre[];
  if rr=1:
    for j=0 upto 18:
      nombre[10*j]=image(
	affixe.[10*j](a[10*j])s;
	currentpicture:=currentpicture rotatedabout(a[10*j],angle(a[10*j]-centre)-90);
	);
    endfor
    for j=0 upto 18:
      nombre[10*j+1]=image(
	affixe.[180-10*j](b[10*j])n;
	currentpicture:=currentpicture rotatedabout(b[10*j],angle(b[10*j]-centre)-90);
	);
    endfor
  else:
    for j=0 upto 18:
      nombre[10*j]=image(
	affixe.[180-10*j](a[10*j])s;
	currentpicture:=currentpicture rotatedabout(a[10*j],angle(a[10*j]-centre)-90);
	);
    endfor
    for j=18 downto 0:
      nombre[10*j+1]=image(
	affixe.[10*j](b[10*j])n;
	currentpicture:=currentpicture rotatedabout(b[10*j],angle(b[10*j]-centre)-90);
	);
    endfor
  fi
  $=image(
    for i=0 upto 18 :
      draw nombre[10*i];
      draw nombre[10*i+1];
    endfor
    path cerc;
    cerc=subpath((angle(segment-centre)*(length cc))/360,((length cc)/2)+(angle(segment-centre)*(length cc))/360) of cc;
    if rr=-1:
      draw cerc reflectedabout(segment,centre);
    else:
      draw cerc;
    fi
    draw a0--b0 withpen pencircle scaled 1.25bp;
    for i=0 upto 35 :
      for j=1 upto 4 :
	draw a[5*i+j]--b[5*i+j];
      endfor;
    endfor
    for i=1 upto 36:
      draw a[5*i]--b[5i] withpen pencircle scaled 1.25bp;
    endfor
    draw a0--a180;
    path cent;
    cent=cercle(centre,0.05*u);
    fill cent withcolor red;
    );
  $
enddef;
 
vardef rapporteurequerre(expr centre,segmt,rr)=
  save $,cc,cd,v,w,t,ww,vv;
  picture $;
  path cc,cd;
  pair a[],b[],v,w,t,ww,vv,rap[],rapp[];
  cc=cercles(centre,abs(centre-segmt));
  t=segmt;
  w=t-10*unitvector(segmt-centre);
  %ww=t-5*unitvector(segmt-centre);vv=symetrie(ww,t);
  a0=segmt;
  b0=w;
  $=image(
    path cd;
    cd=segmt--rotation(segmt,centre,90)--symetrie(segmt,centre);
    trace cd--cycle;
    for i=0 upto 35 :
      for j=1 upto 4 :
	a[5*i+j]=demidroite(centre,pointarc(cc,angle(segmt-centre)+5*i+j)) intersectionpoint cd;
	b[5*i+j]-a[5*i+j]=5*unitvector(centre-a[5*i+j]);
      endfor;
      a[5*(i+1)]=demidroite(centre,pointarc(cc,angle(segmt-centre)+5*(i+1))) intersectionpoint cd;
      b[5*(i+1)]-a[5*(i+1)]=10*unitvector(centre-a[5*(i+1)]);
    endfor;
    for i=0 upto 35 :
      for j=1 upto 4 :
	draw a[5*i+j]--b[5*i+j];
      endfor;
    endfor;
    for i=0 upto 36:
      draw a[5*i]--b[5i] withpen pencircle scaled 1.25bp;
    endfor
    trace cotationmilrap(centre,a10,0,15,btex 10 etex);
    trace cotationmilrap(centre,a20,0,15,btex 20 etex);
    trace cotationmilrap(centre,a30,0,15,btex 30 etex);
    trace cotationmilrap(centre,a40,0,15,btex 40 etex);
    trace cotationmilrap(centre,a50,0,15,btex 50 etex);
    trace cotationmilrap(centre,a60,0,15,btex 60 etex);
    trace cotationmilrap(centre,a70,0,15,btex 70 etex);
    trace cotationmilrap(centre,a80,0,15,btex 80 etex);
    trace cotationmilrap(centre,a90,0,15,btex 90 etex);
    trace cotationmilrap(centre,a100,0,15,btex 100 etex);
    trace cotationmilrap(centre,a110,0,15,btex 110 etex);
    trace cotationmilrap(centre,a120,0,15,btex 120 etex);
    trace cotationmilrap(centre,a130,0,15,btex 130 etex);
    trace cotationmilrap(centre,a140,0,15,btex 140 etex);
    trace cotationmilrap(centre,a150,0,15,btex 150 etex);
    trace cotationmilrap(centre,a160,0,15,btex 160 etex);
    trace cotationmilrap(centre,a170,0,15,btex 170 etex);
    );
  $
enddef;
 
%%Compas
vardef compas(expr centre,extre,n)=
  save $;
  picture $;
  pair r,s,t,a,b,c,d,e,f;
  if (abs(centre-extre)<10*u):
    r=((extre-1/2[centre,extre]) rotated (n*90)) shifted (1/2[centre,extre]);
  else:
    r=0.25[1/2[centre,extre],((extre-1/2[centre,extre]) rotated (n*90)) shifted (1/2[centre,extre])];
  fi
  s=(1+50/abs(centre-extre))[1/2[centre,extre],r];
  t=10*unitvector(extre-centre) rotated (n*90);
  a=centre shifted t;
  b=s shifted (5*unitvector(centre-extre)+10*unitvector(s-r));
  c=b shifted (30*unitvector(s-r));
  d=c reflectedabout(r,s);
  e=b reflectedabout(r,s);
  f=a reflectedabout(r,s);
  path comp;
  comp=a--b--c--d--e--f--s--a--cycle;
  $=image(
    fill comp withcolor black;
    draw centre--a withpen pencircle scaled 1.5bp;
    draw f--extre withpen pencircle scaled 1.5bp withcolor 0.25[red,blue];
    );
  $
enddef;
endinput