Two Plus Two Older Archives  

Go Back   Two Plus Two Older Archives > 2+2 Communities > Other Other Topics
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #11  
Old 04-15-2005, 01:49 AM
The Goober The Goober is offline
Senior Member
 
Join Date: Oct 2004
Location: I am the threadkiller
Posts: 164
Default Re: Programming Question

Ah, I think I understand now. Its fuuny, because I'm actually due to start learning MEL for work soon.

If that rand() function with those arguments is giving you points randomly distributed within a box, then that is all its going to give you. The two points that you are specifying are actually the corners of the (axis-aligned) box - there is no way to use that function to generate points within a sphere. That is, I think what its computing is: p = rand(<x,y,z>,<x1,y,z1&gt returns a point p such that x<=p.x<=x1, y<=p.y<=y1, z<=p.z<=z1. I'm guessing here, but seems to make sense.

So am I correct that what you are looking for is a function that will randomly generate points within a sphere?
Reply With Quote
  #12  
Old 04-15-2005, 02:00 AM
thirddan thirddan is offline
Senior Member
 
Join Date: Nov 2003
Location: San Francisco CA
Posts: 849
Default Re: Programming Question

yeah, it will pick random points within the confines of the vector that i give it, then run the point coordinates thru a fractal function and give them a threshold to either draw a particle or not...

my teacher gave us a hint that we would need to use the x^2 + y^2 + z^2 = r^2 forumla....

so far i have this ($sphereX/Y/Z/R are user defined)

float $sqrX = pow((0 - $sphereX), 2);
float $sqrY = pow((0 - $sphereY), 2);
float $sqrZ = pow((0 - $sphereZ), 2);
float $sqrR = pow($sphereR, 2);
float $result = sqrt($sqrX + $sqrY + $sqrZ);
if ($result < $sphereR)
{
vector $p = << ????? >>;
}
else
{
vector $p = << ?????? >>;
}

haha, you guys are the best, thanks for helping...
Reply With Quote
  #13  
Old 04-15-2005, 02:12 AM
thirddan thirddan is offline
Senior Member
 
Join Date: Nov 2003
Location: San Francisco CA
Posts: 849
Default Re: Programming Question

blah this is totally wrong...
Reply With Quote
  #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
  #15  
Old 04-15-2005, 02:38 AM
The Goober The Goober is offline
Senior Member
 
Join Date: Oct 2004
Location: I am the threadkiller
Posts: 164
Default Re: Programming Question

heh... i didn't realize I was doing your homework for you.

I still don't understand exactly what the question is. What are you given, and what must you compute?

If the problem is: given $sphereX/Y/Z/R and point $p, accept or reject $p, then its like this:

float $distSq = pow($p.x - $sphereX, 2) + pow($p.y - $sphereY), 2) + pow($p.z - $sphereZ, 2);

if($distSq <= ($sphereR * $sphereR))
{
// reject it somehow
}
else
{
// accept it somehow
}

(note that I'm using $p.x to mean the x component of $p, and I'm assuming that comments are the same C... I dunno the mel syntax, although I'd like to learn it)
Reply With Quote
  #16  
Old 04-15-2005, 02:42 AM
thirddan thirddan is offline
Senior Member
 
Join Date: Nov 2003
Location: San Francisco CA
Posts: 849
Default Re: Programming Question

haha, you arent doing my hw for me, my teacher gave us a fractal function to use, so im using it for something somewhat interesting and pretty useful...the eventual goal is to be able to take any arbitrary 3d object and fill it with particles using the fractal pattern...

TimM is on the right track, his code works pretty well, but i have to add to the loop so that it will only accept a certain defined amount of points...and once it finds taht many acceptable points it will exit the loop...

i really appreciate you guys helping me nerd out...
Reply With Quote
  #17  
Old 04-15-2005, 02:45 AM
TimM TimM is offline
Senior Member
 
Join Date: Jan 2004
Location: New York
Posts: 147
Default Re: Programming Question

Yeah my loop exits after finding one valid point, so you need a bigger loop around all of this to generate however many you need.
Reply With Quote
  #18  
Old 04-15-2005, 03:15 AM
thirddan thirddan is offline
Senior Member
 
Join Date: Nov 2003
Location: San Francisco CA
Posts: 849
Default victory....

int $i;

for ($i = 0 ; $i < $numPart
{
vector $p = 1 * (rand(<<$sphereX - $sphereR, $sphereY - $sphereR, $sphereZ - $sphereR>>, <<$sphereX + $sphereR, $sphereY + $sphereR, $sphereZ + $sphereR>&gt);
float $sqrX = pow(($p.x - $sphereX), 2);
float $sqrY = pow(($p.y - $sphereY), 2);
float $sqrZ = pow(($p.z - $sphereZ), 2);
float $sqrR = pow($sphereR, 2);
float $result = sqrt($sqrX + $sqrY + $sqrZ);

if ($result < $sphereR)
{
float $fbm = fBm( $p, 0.8, 2, 3 );
$thresh = rand (0.4, 0.7);
if($fbm > $thresh)
{
emit -object $s[0] -position ($p.x) ($p.y) ($p.z);
$max--;
$i = $i + 1 ;
}
}
}


thanks guys...now i must sleep...
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:17 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.