#### Archived

This topic is now archived and is closed to further replies.

# Random point in frustum?

This topic is 5382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there, Anyone know a good fast algorithm to return a random point in the frustum? Cheers

##### Share on other sites
not sure, but this should work. get a random number between near clip plane, and far clip plane, then, since the width of the frustum can be said as a function of z and FOV:

x offset = tan(Horizontal FOV / 2) * The first random number between near and far clip plane

say x is a random number between positive x offset and negative x offset.

then, repeat for vertical FOV. here is quick pseudocode (probably mistakes, and untested)

 float z = (rand() / RAND_MAX) * (FarLipPlane - NearClipPlane) + NearClipPlane; float hoffset = tan(FOV / 2) * z; float x = ((2 * rand() / RAND_MAX) - 1) * hoffset; // random number between -1 and 1, times horizontal offset float voffset = tan((FOV / Aspect) / 2) * z; float y = ((2 * rand() / RAND_MAX) - 1) * voffset;

if needed, transform it to world space.

##### Share on other sites
billybob-s method will work, but it will not give you even distribution of points(more points near camera). For that you'll have to change random number generator.

You should never let your fears become the boundaries of your dreams.

[edited by - _DarkWIng_ on February 22, 2004 1:49:16 PM]

##### Share on other sites

Cheers chappies. I''ll give that a go - don''t really mind too much about not being evenly distributed at the moment

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 12
• 17
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633358
• Total Posts
3011511
• ### Who's Online (See full list)

There are no registered users currently online

×