I hope the German PHP Gurus are not sleeping like the American Coders atm
I have created a function which should notice if there is a Star in spheric range (distance = $gap (=20) of my analized star. It seems to find some stars but the result is really strange. (At bottom of the code)
I printed out the distances of the potencial in-range-stars to the analysing star and there comes results of that:
(Differences x,y,z)
19/2/-13
19/2/-12
19/2/-13
19/1/-12
-19/-2/12
19/2/-13
Distance is always between 22 and 24, not as expectet <20!
It would be very kind, if you could help me with that dilema!
I have created a function which should notice if there is a Star in spheric range (distance = $gap (=20) of my analized star. It seems to find some stars but the result is really strange. (At bottom of the code)
PHP-Code:
function collision($db, $x, $y, $z, $gap){
$collision = false;
$x_min = $x-$gap; $x_max = $x+$gap;
$y_min = $y-$gap; $y_max = $y+$gap;
$z_min = $z-$gap; $z_max = $z+$gap;
$sql = 'SELECT x, y, z FROM stars
WHERE x BETWEEN '.$x_min.' AND '.$x_max.'
AND y BETWEEN '.$y_min.' AND '.$y_max.'
AND z BETWEEN '.$z_min.' AND '.$z_max;
$result = $db->query($sql) or die (mysql_error());
while ($row = $result->fetch_assoc()) {
$dx = $x-$row['x'];
$dy = $y-$row['y'];
$dz = $z-$row['z'];
$distance = sqrt($dx*$dx+$dy*$dy+$dz*$dz);
if ($distance<$gap) {
$collision = true;
echo '<br>There was a star in range at '.$x.'-'.$y.'-'.$z;
break;
}
}
return $collision;
}
(Differences x,y,z)
19/2/-13
19/2/-12
19/2/-13
19/1/-12
-19/-2/12
19/2/-13
Distance is always between 22 and 24, not as expectet <20!
It would be very kind, if you could help me with that dilema!
Kommentar