![]() |
#11
|
|||
|
|||
![]()
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> ![]() So am I correct that what you are looking for is a function that will randomly generate points within a sphere? |
#12
|
|||
|
|||
![]()
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... |
#13
|
|||
|
|||
![]()
blah this is totally wrong...
|
#14
|
|||
|
|||
![]()
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)>> ![]() $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); } |
#15
|
|||
|
|||
![]()
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) |
#16
|
|||
|
|||
![]()
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... |
#17
|
|||
|
|||
![]()
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.
|
#18
|
|||
|
|||
![]()
int $i;
for ($i = 0 ; $i < $numPart ![]() { vector $p = 1 * (rand(<<$sphereX - $sphereR, $sphereY - $sphereR, $sphereZ - $sphereR>>, <<$sphereX + $sphereR, $sphereY + $sphereR, $sphereZ + $sphereR>> ![]() 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... |
![]() |
|
|