Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Point Distributions

📅 2010-Sep-14 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ distributions, geometry ⬩ 📚 Archive

A variety of point distributions are used in computer graphics and computational geometry to test out algorithms. Below are a few common point distributions and code to generate points in 3D. Assume that random() is a random function that returns a floating point value in the range (0.0-1.0).

Uniform Distribution

 

Uniform distribution is the most common distribution used in practice. Generate point using random values of x, y and z.

x = random();
y = random();
z = random();

Sphere Distribution

 
do {
    x = random() - 0.5;
    y = random() - 0.5;
    z = random() - 0.5;

    d = ( x * x ) + ( y * y ) + ( z * z );

} while ( ( d < ( 0.45 * 0.45 ) || ( d > ( 0.5 * 0.5) ) ) );

Half Sphere Distribution

 
do {
    x = random() - 0.5;
    y = random() - 0.5;
    z = random() - 0.5;

    d = ( x * x ) + ( y * y ) + ( z * z );

} while ( ( z >= 0.2 ) || ( d < ( 0.45 * 0.45 ) ) || ( d > ( 0.5 * 0.5) ) );

Ball Distribution

 
do {
    x = random() - 0.5;
    y = random() - 0.5;
    z = random() - 0.5;

    d = ( x * x ) + ( y * y ) + ( z * z );

} while ( d > ( 0.49 * 0.49 ) );

Empty Ball Distribution

 
do {
    x = random() - 0.5;
    y = random() - 0.5;
    z = random() - 0.5;

    d = ( x * x ) + ( y * y ) + ( z * z );

} while ( d < ( 0.45 * 0.45 ) );

Ellipsoid Distribution

  Ellipsoid has a surface but no volume inside.

a = 0.5;
b = 0.5;
c = 0.2;

do {
    x = random() - 0.5;
    y = random() - 0.5;
    z = random() - 0.5;

    d = ( ( x * x ) / ( a * a ) ) + ( ( y * y ) / ( b * b ) ) + ( ( z * z ) / ( c * c ) );

} while ( ( d <= 1.4 ) || ( d >= 1.5 ) );

Pancake Distribution

 
a = 0.5;
b = 0.5;
c = 0.2;

do {
    x = random() - 0.5;
    y = random() - 0.5;
    z = random() - 0.5;

    d = ( ( x * x ) / ( a * a ) + ( y * y ) / ( b * b ) + ( z * z ) / ( c * c );

} while ( d >= 1.0 );

© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon📧 Email