Kalo ini grafik gerak peluru.. inget ya.. kalo mau buka, xampp nya diaktifin dulu.. tapi jangan bingung kalo hasilnya ternyata tidak setengah lingkaran simetris.. kan emang harusnya ga simetris. Tanya kenapa??? lah, kan dalam gerak peluru ini hambatannya diperhitungkan.. ga ada pengabaian hlo ya.. :D
silakan mencoba....
//membuat kanvas bidang gambar :
//ukuran panjang, lebar
$aa=600;
$bb=400;
$xmin=-4;
$xmax=50;
$ymin=-2.5;
$ymax=20;
$k1=$aa/($xmax-$xmin);
$k2=-$aa*$xmin/($xmax-$xmin);
$k3=$bb/($ymin-$ymax);
$k4=-$bb*$ymax/($ymin-$ymax);
//menampilkan kanvas
$gb=ImageCreate ($aa,$bb);
//membuat warna
$pink=ImageColorAllocate($gb,150,125,168);
$warna1=ImageColorAllocate($gb,200,200,200);
$warna2=ImageColorAllocate($gb,255,0,0);
$biru=ImageColorAllocate($gb,0,0,255);
$kuning=ImageColorAllocate($gb,255,255,0);
$m=0.1;
$rho=1.2;
$c=0.46;
$g=9.8;
$r=0.03;
$h=0.01;
$k=0.5*$rho*$c*PI()*$r*$r/$m;
$alpha=37;
$t=0;
$x=0;
$y=0;
$v=25;
$vx=$v*cos(deg2rad($alpha));
$vy=$v*sin(deg2rad($alpha));
$v=sqrt($vx*$vx + $vy*$vy);
$ax=-$k*$v*$vx;
$ay=-$g-$k*$v*$y;
$vx=$vx+$ax*$h/2; //v1/2
$vy=$vy+$ay*$h/2;
for ($t=0;$t<=10;$t+=$h){
//grafik
ImageSetPixel($gb,$x*$k1+$k2,$y*$k3+$k4,$warna2);
//sumbu x : ($gb,x awal, y awal, x akhir, y akhir, warna)
Imageline($gb,($xmin+1)*$k1+$k2,0*$k3+$k4,$xmax*$k1+$k2,0*$k3+$k4,$biru);
//sumbu y
ImageLine($gb,0*$k1+$k2,($ymin+1)*$k3+$k4,0*$k1+$k2,($ymax-5)*$k3+$k4,$biru);
//menampilkan tulisan
imagestring($gb,5,45*$k1+$k2,-16*$k3+$k2,'x(m)',$kuning);
imagestring($gb,5,1.1*$k1+$k2,15*$k3+$k4,'y(m)',$kuning);
imagestring($gb,15,1*$k1+$k2,18*$k3+$k4,'Grafik Hubungan Posisi (y) terhadap Posisi(x)',$kuning);
//membuat skala x
Imageline($gb,10*$k1+$k2,0.5*$k3+$k4,10*$k1+$k2,-0.5*$k3+$k4,$biru);
Imageline($gb,20*$k1+$k2,0.5*$k3+$k4,20*$k1+$k2,-0.5*$k3+$k4,$biru);
Imageline($gb,30*$k1+$k2,0.5*$k3+$k4,30*$k1+$k2,-0.5*$k3+$k4,$biru);
Imageline($gb,40*$k1+$k2,0.5*$k3+$k4,40*$k1+$k2,-0.5*$k3+$k4,$biru);
//membuat skala y
ImageLine($gb,-0.5*$k1+$k2,5*$k3+$k4,0.5*$k1+$k2,5*$k3+$k4,$biru);
ImageLine($gb,-0.5*$k1+$k2,10*$k3+$k4,0.5*$k1+$k2,10*$k3+$k4,$biru);
ImageLine($gb,-0.5*$k1+$k2,15*$k3+$k4,0.5*$k1+$k2,15*$k3+$k4,$biru);
//tulisan skala ($gb, font, letak x, letak y, )
imagestring($gb,14,9*$k1+$k2,-0.5*$k3+$k4,'10',$biru);
imagestring($gb,14,19*$k1+$k2,-0.5*$k3+$k4,'20',$biru);
imagestring($gb,14,29*$k1+$k2,-0.5*$k3+$k4,'30',$biru);
imagestring($gb,14,39*$k1+$k2,-0.5*$k3+$k4,'40',$biru);
imagestring($gb,14,-1.9*$k1+$k2,5.5*$k3+$k4,'5',$biru);
imagestring($gb,14,-1.9*$k1+$k2,10.5*$k3+$k4,'10',$biru);
imagestring($gb,14,-1.9*$k1+$k2,15.5*$k3+$k4,'15',$biru);
$x=$x+$vx*$h;
$y=$y+$vy*$h;
$v=sqrt($vx*$vx + $vy*$vy);
$ax=-$k*$v*$vx;
$ay=-$g-$k*$v*$y;
$vx=$vx+$ax*$h; //v1 1/2
$vy=$vy+$ay*$h;
}
Header('Content-Type:Image/Jpeg');
ImageJPEG($gb);
ImageDestroy($gb);
?>
Tidak ada komentar :
Posting Komentar