<?php 
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_scatter.php');
 
$polex = 6;
$poley = 40;
 
function FldCallback($x,$y,$a) {
    GLOBAL $polex, $poley;
    $maxr = 3000;
 
    
    $size="";
    $arrowsize="";
 
    
    
    
    $x *= 10; 
 
    
    $r = ($x-$polex*10)*($x-$polex*10)+($y-$poley)*($y-$poley);
    $f = $r/$maxr;
    if( $f > 1 ) $f=1;
    $red = floor((1-$f)*255);
    $blue = floor($f*255);
    $color = array($red,0,$blue);
    
    return array($color,$size,$arrowsize);
}
 
$datax = array();
$datay = array();
$angle = array();
for($x=1; $x < 10; ++$x ) {
    for($y=10; $y<100; $y += 10) {
    $a = -1;
    if( $x==$polex && $y==$poley ) continue;
    if( $x==$polex ) {
        if( $y > $poley ) $a=90;
        else $a = 270;
    }
    if( $y==$poley ) {
        if( $x  > $polex ) $a=0;
        else  $a=180;        
    }
    if( $a == -1 ) {
        $d1 = $y-$poley;
        $d2 = ($polex-$x)*20;
        if( $y < $poley ) $d2 *= -1;
        $h = sqrt($d1*$d1+$d2*$d2);
        $t = -$d2/$h;
        $ac = acos($t);
        if( $y < $poley ) $ac += M_PI;
        $a = $ac * 180/M_PI;
    }
    $datax[] = $x;
    $datay[] = $y;
    $angle[] = $a;
    }
}
 
$graph = new Graph(300,200);
$graph->SetScale("intlin",0,100,0,10);
$graph->SetMarginColor('lightblue');
 
 
$graph->title->Set("Field plot");
 
$fp = new FieldPlot($datay,$datax,$angle);
 
$fp->SetCallback('FldCallback');
 
$fp->arrow->SetSize(20,2);
$fp->arrow->SetColor('navy');
 
$graph->Add($fp);
 
$graph->Stroke();
 
?> |