Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 06 November 2006 - 09:36 PM
Posted 06 November 2006 - 10:24 PM
Vector random(rand(), rand(), rand());
Velocity = random - forward * dot(random, forward) / dot(forward, forward);
Posted 06 November 2006 - 10:53 PM
Posted 06 November 2006 - 11:24 PM
Quote:Yup.
Original post by Kest
So in a sense, we're creating a random vector and smashing it onto the forward vector's zero-origin plane?
Quote:Nope.
Is your result velocity vector normalized?
Quote:If your forward vector is known to be unit length, you can drop the dot(forward,forward).
I'm not sure what the additional "/ dot(forward, forward);" is doing. Wouldn't dot(forward,forward) always be 1?
Posted 07 November 2006 - 05:10 AM
Posted 07 November 2006 - 01:33 PM
Quote:
Original post by TheAdmiral
Why the cross-product aversion?
Quote:
Any other method is simply using simplified Gram-Schmidt orthogonalisation in a different (and probably less efficient) way.
Quote:
..chances are that you spend more effort calculating it than you would crossing against a quasi-random vector.
Quote:
If you're worried that cross-products are slow, then they really aren't. Certainly not when compared to anything involving normalisation or rotation (which contain sqrt, sin, cos as opposed to addition and multiplication).
Quote:
If you're worried that cross-products are complicated to implement without an API, then, again, think twice.
Posted 07 November 2006 - 02:12 PM
Quote:It's not an ugly hack. Many would argue that the sole purpose of the cross-product's existence is to produce perpendicular vectors. If you're prepared to start off with a vector (rand(), rand(), rand()) and you don't think that's ugly, then calling rand() once and calculating a cross-product is the picture of elegance.
Its an ugly hack to reach a result that was even simpler than the hack itself.
Quote:My mention of GS orthogonalisation was merely an indication that whatever route you take, you're performing the same operation, only you're likely taking the long way 'round.
Quote:I'm open to suggestions.
Any other method is simply using simplified Gram-Schmidt orthogonalisation in a different (and probably less efficient) way.
Quote:Well I'm sure it's all right, but is it perfect? [wink].
Quote:It's all right here, so you tell me.
...chances are that you spend more effort calculating it than you would crossing against a quasi-random vector.
Quote:It doesn't. I was just guessing as to why you didn't want to use cross-products.
Quote:I don't understand. How does this effect the situation?
If you're worried that cross-products are complicated to implement without an API, then, again, think twice.
Posted 07 November 2006 - 02:24 PM
Posted 07 November 2006 - 02:47 PM
Quote:
Quote:It's not an ugly hack. Many would argue that the sole purpose of the cross-product's existence is to produce perpendicular vectors. If you're prepared to start off with a vector (rand(), rand(), rand()) and you don't think that's ugly, then calling rand() once and calculating a cross-product is the picture of elegance.
Its an ugly hack to reach a result that was even simpler than the hack itself.
Quote:
Quote:My mention of GS orthogonalisation was merely an indication that whatever route you take, you're performing the same operation, only you're likely taking the long way 'round.
Quote:I'm open to suggestions.
Any other method is simply using simplified Gram-Schmidt orthogonalisation in a different (and probably less efficient) way.
Quote:
I doubt any reasonably brief method will asymptotically outperform any other, but I think two lines of fast code are better than two of not-quite-so-fast code. You're more than welcome to use whatever method you like, considering that they're all roughly equivalent. But you appear to be under the false impression that the cross-product method is inferior to the displace-project method.
Quote:
Anyway, this disagreement is completely moot. You've found a solution you're happy with, so let's all go to the pub [grin].
Posted 07 November 2006 - 02:53 PM
Quote:
Original post by mooserman352
depending on how many such particles you want, it might be faster for you to generate a basis for the orthogonal plane first. then you only need to call rand twice and do very little arithmetic.
Posted 07 November 2006 - 03:24 PM
Posted 07 November 2006 - 05:23 PM
Quote:
Original post by Kest
Is there a way to compute a random perp vector to an original 3D vector without crossing?
Vector3 forward = (x,y,z), perp;
float angle = random_angle, cs = cos(angle), sn = sin(angle);
if (|x| >= |y|)
{
perp = (cs*(-z,0,x)+sn*(x*y,-x*x-z*z,y*z))/sqrt(x*x+z*z);
}
else
{
perp = (cs*(0,z,-y)+sn*(-y*y-z*z,x*y,x*z)/sqrt(y*y+z*z);
}
Posted 07 November 2006 - 06:02 PM
Posted 07 November 2006 - 06:27 PM
Vector random(rand(), rand(), rand());
Velocity = Cross(forward, random);
Posted 08 November 2006 - 08:29 AM
Quote:
Original post by erissian
Assuming m is the desired magnitude of the random vector,
r = 1-2*rand();
s = 1-2*rand();
t = sqrt(m*m-r*r-s*s) * -rand()%2;
Vector perp(y*t-z*s,z*r-x*t,x*s-y*r);
Quote:
Original post by Zipster
Vector random(rand(), rand(), rand());
Velocity = Cross(forward, random);
Posted 08 November 2006 - 11:26 AM
Posted 08 November 2006 - 01:43 PM
Quote:
Original post by mooserman352
..then all you need to do is generate a random angle between 0 and 2*pi. then you have x = cos(theta) y = sin(theta), and so your final vector is x*up + y*right.
Quote:
Note, just for principle, that you can also adapt "smashing into planes" algorithm with this, except you would want to use spherical coordinates to generate vectors only on the unit sphere.
Quote:
Original post by erissian
Assuming m is the desired magnitude of the random vector,
r = 1-2*rand();
s = 1-2*rand();
t = sqrt(m*m-r*r-s*s) * -rand()%2;
Vector perp(y*t-z*s,z*r-x*t,x*s-y*r);
It's still the cross product, but in four lines and normalized.
Quote:
Original post by erissian
Even for hundreds of particles, I'm sure it pales in comparison to the number of flops you're doing updating the rest of the system.
Quote:
Original post by Zipster
Technically, the following is an equivalent solution using cross-products:Vector random(rand(), rand(), rand());
Velocity = Cross(forward, random);
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.