View Single Post
  #14  
Old 04-15-2005, 02:24 AM
TimM TimM is offline
Senior Member
 
Join Date: Jan 2004
Location: New York
Posts: 147
Default Re: Programming Question

I think you need to use the random function on a cube that "circumscribes" the sphere, and some kind of loop to reject any points from that cube that are not in the sphere.

I don't even know the language so here is some pseudo code.

$result = $sphereR; // just so the loop executes at least once, and to clear the last value of $result
while ($result >= $sphereR)
{
$p = 1 * (rand(<<($sphereX - $sphereR),($sphereY - $sphereR), ($sphereZ - $sphereR)>>, <<($sphereX + $sphereR),($sphereY + $sphereR), ($sphereZ + $sphereR)>&gt); // why the 1 * stuff?
$sqrX = pow((the x value of vector $p - $sphereX), 2);
$sqrY = pow((the y value of vector $p - $sphereY), 2);
$sqrZ = pow((the z value of vector $p - $sphereZ), 2);
$result = sqrt($sqrX + $sqrY + $sqrZ);
}
Reply With Quote