<?php
 # définition image 
#header("content-type:image/jpeg");
$nomimag="yoan.JPG";
 # dimensions de l'image en pixels
$im=imagecreate(640,480);
 # la première couleur est celle du fond
$fond=imagecolorallocate($im,255,245,255);
$blanc=imagecolorallocate($im, 255, 255, 255);
$gris=imagecolorallocate($im, 192, 192, 192);
$bleu=imagecolorallocate($im, 0, 0, 255);
$noir=imagecolorallocate($im,0, 0, 0);
$vert=imagecolorallocate($im, 0, 150, 0);   
$rouge=imagecolorallocate($im,255,0,0);
$orange=imagecolorallocate($im,220,210,60);
$marron=imagecolorallocate($im,200,150,50);
$rose=imagecolorallocate($im,250,50,200);

  # sortie des titres courbes

imagestring($im,5,0,5,"Cycle Pédalage Assisté",$noir);
imagestring($im,5,215,5,"%rendement ",$marron);
imagestring($im,5,310,5,"%pwm ",$bleu);
imagestring($im,5,350,5,"wh/km",$vert);
imagestring($im,5,400,5,"Wtot",$noir);
imagestring($im,5,445,5,"WPéd",$gris);
imagestring($im,5,490,5,"Amp(batterie)",$rouge);
imagestring($im,5,0,20,"Température moteur degC (accélération)",$rose);
imagestring($im,5,350,20,"durée maxi minutes (croisiere)",$rose);

  # unités en ordonnée
imagestring($im,5,0,45,"Watts meca ",$noir);
imagestring($im,5,580,45,"wh/km",$vert);
imagestring($im,5,545,45,"%",$marron);
imagestring($im,5,545,70,"%",$bleu);
imagestring($im,5,580,75,"Amperes",$rouge);
imagestring($im,5,580,100,"minutes",$rose);
imagestring($im,5,530,100,"degC",$rose);

 #Tracé de la grille
 # origine ox,oy pixels(H,D).Nx,Ny carreaux de px,py pixels #37
$ox=10;$oy=40;$Nx=20;$px=28;$Ny=10;$py=28;
 for($nx=0;$nx<$Nx+0.5;$nx++){
imageline($im,$ox+$nx*$px,$oy,$ox+$nx*$px,$oy+$Ny*$py,$gris);
} 
 for($ny=0;$ny<$Ny+0.5;$ny++){
imageline($im,$ox,$oy+$ny*$py,$ox+$Nx*$px,$oy+$ny*$py,$gris);
} 
$oy=$oy+$Ny*$py;#origine en y bas gauche du graphique

  #  nombre d'unités par carreau
$nux=2;$dix=10;$nuy=10;
   # graduation des axes 
for($i=0;$i<($Ny+0.5);$i++){$xx=$ox+$Nx*$px-15;$yy=$oy-$i*$py-8;
$leg=$i*$nuy;imagestring($im,4,$xx,$yy,$leg,$noir);}
for($i=0;$i<($Nx+0.5);$i++){$yy=$oy+5;$xx=$ox+$i*$px-2;
$leg=$i*$nux;imagestring($im,4,$xx,$yy,$leg,$noir);}
imagestring($im,4,50,($oy+20),"<-----Accélération",$noir);   
imagestring($im,5,250,($oy+20),"Vitesse kmh ",$noir);
imagestring($im,4,400,($oy+20)," Croisiere--->",$noir);
for($i=0;$i<($Ny+0.5);$i++){$xx=$xx+20;$yy=$oy-$i*$py-8;
$leg=$i*$nuy/2;$leg=sprintf("%02.1f",$leg);
imagestring($im,4,590,$yy,$leg,$noir);
}
for($i=0;$i<($Ny+0.5);$i++){$xx=0;$yy=$oy-$i*$py-8;
$leg=$i*$nuy*$dix;$leg=sprintf("%02.0f",$leg);
imagestring($im,4,0,$yy,$leg,$noir);}

  # données
/*
$m=100;$SCx=0.40;$d=1.225;$Kmh=1;$R=1;$g=9.81;
$vv=0;
$pr=1;$pac=3;$ptr=1;

$pdal=120;$pdalc=70;
$vv=1;
$Un=48;$r=0.5;$R=0.5;
#$Un=36;
*/
#73
$m=$_POST['m'];$Tair=$_POST['Tair'];
$SCx=$_POST['SCx'];$wmaxnom=$_POST['wmaxnom'];
$d=$_POST['d'];$rendnom=$_POST['rendnom'];
$Kmh=$_POST['Kmh'];$Tempmaxi=$_POST['Tempmaxi'];
$R=$_POST['R'];$Taumot=$_POST['Taumot'];
$vv=$_POST['vv'];$red=$_POST['red'];
$pr=$_POST['pr'];$vlow=$_POST['vlow'];
$pac=$_POST['pac'];
$ptr=$_POST['ptr'];$vhigh=$_POST['vhigh'];
$pdal=$_POST['pdal'];#if($pdal<1){$pdal=1;}
$pdalc=$_POST['pdalc'];
$Un=$_POST['Un'];
$r=$_POST['r'];
$vfac=$_POST['vfac'];

#echo $m.$SCx.$d.$Kmh.$R.$g.$vv.$pr.$pac.$ptr.$pdal.$pdalc.$r;exit();
# sortie des données
imagestring($im,4,0,355,"m=".$m."kg,SCx=".$SCx."m2,proul=".$pr."%,K=".$Kmh."V/kmh,Rm=".$R."ohm,rb=".$r."ohm,red=".$red."%,V1V2:".$vlow."-".$vhigh."kmh",$noir);
$svv=$vv*3.6;
imagestring($im,4,0,370,"Ubatt=".$Un."V, pterrain=".$ptr."%, paccel=".$pac."%, vent=".$svv."km/h, pedalacc<".$pdal."W, Pedalcruse=".$pdalc."W  ",$noir);
imagestring($im,4,0,385,"Tair=".$Tair."degC, Wnomin=".$wmaxnom."watts, rnom=".$rendnom."%, Tmaxi=".$Tempmaxi."degC, refroidissement=".$Taumot."minutes",$noir);

  # calculs initiaux
$p=($pr+$pac+$ptr)/100;
$rs2scx=$d/2*$SCx;
$K=$Kmh*3.6;$g=9.81;$Kl=$K;
$pwm=0;$incal=36;$fin=0;
$incal=40;
$Tmot=$Tair;

  # boucle de calcul
$fin=0;$acc=1;
imagesetthickness($im,3);
$xm=$ox;$ym=$oy;
$itm=$oy;$ctm=$oy;$I=0;
 for($i=0;$i<$incal;$i++)
{
$zm=$oy-$py*$pdal/$nuy/$dix;$Vkmh=$i;$V=$Vkmh/3.6;
if($Vkmh>$vfac or $pwm > 1) {$p=($pr+$ptr)/100;$pdal=$pdalc;$acc=0;}# fin accél
$F=$m*$g*$p+$rs2scx*($V+$vv)*($V+$vv);$F=$F/$red*100;
$wmc=$F*$V;#puissance mécanique totale de propulsion
$xt=$ox+$px*$Vkmh/$nux;
$yt=$oy-$py*$wmc/$nuy/$dix;
#if($wmc<$pdal and $acc>0.5 ) # pédalage seul
if($wmc<$pdal) # pédalage seul
 {
imageline($im,$xm,$ym,$xt,$yt,$gris);$ym=$yt;$xm=$xt;
$utm=$K*$V;$utm=$oy-$utm*$py/$nuy;$wtm=$oy-$py*$pdal/$nuy/$dix;
$rtm=$oy-$py*100/$nuy;
$dmax=30;$etm=$oy-$py*$Tair/$nuy;
 }
else   #76 mise en route assistance
{
if($fin<0.5)
{
if($Vkmh<$vlow){$K=$Kl*$vhigh/$vlow;}else{$K=$Kl*$vhigh/$Vkmh;}
if($Vkmh>$vhigh){$K=$Kl;}
$I=($wmc-$pdal)/$V/$K;
$U=$K*$V+$R*$I;
if($r<($R/50) or $R<0.01){$pwm=$U/$Un;}else
{$pwm=($Un-sqrt($Un*$Un-4*$r*$U*$I))/(2*$r*$I);}
$Ub=$U/$pwm;$Ib=$I*$pwm;
$ren=($wmc-$pdal)/$Un/$Ib*100;
$Cs=$Un*$Ib/$Vkmh;

$ak=(100-$rendnom)*$wmaxnom/($Tempmaxi-$Tair)/100;$qm=$Taumot*$ak;$wthenom=$wmaxnom*(100-$rendnom)/100;
if($acc!=0){$dt=1/3.6/$acc;$Tmot=$Tmot+$dt/$qm*($R*$I*$I-$ak*($Tmot-$Tair));$dmax=$Tmot/2;}
else{ $xw=$R*$I*$I/$wthenom;if($xw>1.1){$dmax=$Taumot*log($xw/($xw-1));}else{$dmax=50;} }

if($pwm <1.1)
{
$it=$oy-$py*$Ib/$nuy*2;
$ut=$oy-$py*$pwm*100/$nuy;
$wt=$oy-$py*$wmc/$nuy/$dix;
$ct=$oy-$py*$Cs/$nuy*2;
$rt=$oy-$py*$ren/$nuy;
$et=$oy-$py*$dmax/$nuy*2;
imageline($im,$xm,$zm,$xt,$zm,$gris);#147
imageline($im,$xm,$itm,$xt,$it,$rouge);$itm=$it;
imageline($im,$xm,$utm,$xt,$ut,$bleu);$utm=$ut;
imageline($im,$xm,$wtm,$xt,$wt,$noir);$wtm=$wt;
imageline($im,$xm,$ctm,$xt,$ct,$vert);$ctm=$ct;
imageline($im,$xm,$rtm,$xt,$rt,$marron);$rtm=$rt;
imageline($im,$xm,$etm,$xt,$et,$rose);$etm=$et;
$xm=$xt;
}#trace
else {$fin=1;}
}#pwm<1.1
}#assistance
}#boucle de calcul

/*

# Sortie tableau

$Vks=sprintf("%02.1f",$Vkmh);$Fdans=sprintf("%01.2f",$Fdan);
$Is=sprintf("%02.1f",$I);$Us=sprintf("%02.1f",$U);
$pwms=$pwm*100;$pwms=sprintf("%02.1f",$pwms);
$Ibs=sprintf("%02.1f",$Ib);$Ubs=sprintf("%02.1f",$Ub);
$whkms=sprintf("%02.1f",$whkm);
#echo(" * ".$Vks." * * ".$Fdans." * * ".$Is." * * ".$Us." * * ".$pwms." * * ".$Ibs." * * ".$Ubs." * * ".$whkms);echo("<br>");

  # sortie des titres courbes

$tit0=" Cycle à pédalage assisté ";imagestring($im,4,20,5,$tit0,$noir);
$tit1=("Pente= ".$p100." % Vent : ".$vv." (m/s)  r=".$r. "ohms) Un= ".$Un." volts");
$titre="m=100 kg   K=".$Kmh." volts/kmh  R = ".$R." ohms SCx=".$SCx."m2";

imagestring($im,4,20,40,$tit1,$noir);
imagestring($im,4,20,20,$titre,$noir);

imagestring($im,4,0,80,"Force de propulsion (daN)",$noir);
imagestring($im,4,0,100,"Consommation électrique (wh/km )",$vert);
imagestring($im,4,0,120,"Tension moteur (Volts)",$bleu);
imagestring($im,4,0,140,"Courant batterie(A)",$rouge);
#imagestring($im,4,20,100,"decawatts électric. et ",$rose);
imagestring($im,4,0,160,"Autonomie (km/".$dix."ah)",$marron);
*/

imagejpeg($im,$nomimag);
imagedestroy($im);

#echo($Vks." ".$Us." ".$Is." ".$Cms." ".$Css." ".$Wms." ".$Wes);echo("<br>");
echo("<div style='position:absolute; top=20;left=250'><img src='$nomimag'' ></div>");
?>