Sphere Packing / Dart Throwing Algorithm

calendar_today

06.06.2023

label

VEX

mouse

Houdini 19.5

Description

Populating a mesh surface with non-intersecting spheres using the dart throwing algorithm inside a Houdini solver.

1 Code discussion

Every @Frame a random uvw-position is tested for its distance to the uv islands of the mesh with the uvdist-function. If dist < 1e-5 the random UV position is either on the island or at least very close to its boundary. Then the corresponding world position is returned by the primuv-function and only if no other point len(pts) != 1 can be found pcfind within a randomly defined radius a new point is created. The new point's radius is written into the pscale attribute with setpointattrib so it can potentially be found in the next iterations.

CPP
        vector uvw = rand(@Frame, 123);
uvw[2] = 0.0;

int pr;
vector st;
float dist = uvdist(1, 'uv', uvw, pr, st);

if(dist < 1e-5){
    vector pos = primuv(1, 'P', pr, st);
    float radius = fit01( rand(@Frame, 456), 0.05, 0.1 );
    int pts[] = pcfind_radius(0, 'P', 'pscale', 1.0, pos, radius, 1);
    
    if(len(pts) != 1){
        int pt = addpoint(0, pos);
        setpointattrib(0, 'pscale', pt, radius, 'set');
    } 
}
    
download

Downloads

smart_display

Videos

Dart throwing algorithm – Houdini Tutorial

link

Related articles

favorite

347

label

VEX

Attribute to match across inputs

favorite

258

label

VEX

Deintersecting spheres with Voronoi

favorite

291

label

VEX

Fitting Planes to Point Clouds

favorite

301

label

VEX

How to analyze VEX code

favorite

139

label

VEX

Monte Carlo Geometry Processing

favorite

132

label

VEX

Predicate Incircles from 3 points