# 'Dart throwing' algorithm

## Recommended Posts

Saw this instagram post. The 'dart throwing' algorithm is also something that Simon Holmedal talks about

Anyone care to suggest how to create this using Vex?

##### Share on other sites

I think this is as simple (and naive!) as multi-radius dart throw gets. No space partioning, no optimisations. Simple raw dart throwing. The image below took 2 minutes to cook. There are much better ways via relaxation, rigid bodies, circle packing etc. Many of them are on this site I think.

dt.hipnc

• 1

##### Share on other sites
3 hours ago, julian johnson said:

I think this is as simple (and naive!) as multi-radius dart throw gets. No space partioning, no optimisations. Simple raw dart throwing. The image below took 2 minutes to cook. There are much better ways via relaxation, rigid bodies, circle packing etc. Many of them are on this site I think.

no, not always,  it really depends on what do you want to do, some strats doesnt works on some cases, in a complex project it just complicates everything.  the darth throw is still important!

##### Share on other sites

I just tried it with a SOP Solver, scattered random positions with uvsample() and then filter them out by their distance to the closest of nearpoints().

vector pos_uvw = rand(@Time) * {1, 1, 0};
float dist_uv = xyzdist(2, pos_uvw);

if( dist_uv < 1e-5 ){
vector pos_geo = uvsample(1, 'P', 'uv', pos_uvw);
float rad_pt = fit01( rand(@Time + 45), 0.02, 0.1 );

int pts_close[] = nearpoints(0, '!mesh', pos_geo, 0.5, 2);
vector pos_close = point(0, 'P', pts_close[1]);
float dist_close = distance(pos_geo, pos_close);
float rad_close = point(0, 'pscale', pts_close[1]);

if( len(pts_close) <= 0 || t > 0.0 ){
}
}

While it does some filtering, it still produces fairly obvious intersections:

Is there something about the SOP solver I dont understand (maybe some syncing issue?) or what did I miss here?

dart_throwing.hiplc

##### Share on other sites

couple of things:

- you are finding 2 closest points, but excluding the first, since the first is the closest, you are risking the intersections with it

- even checking just the first, will not guarantee no intersections, cause closest point can have small radius so it can satisfy the distance constraint, but the second or third closest can have big radius and actually intersect you new point even though it's further, so you'd have to check all points within 2*maxpscale radius

- to avoid all this, use pcfind_radius() which directly checks against pscale intersections, also you can directly use uvdist() to avoid having uvmesh

here is modified code and the file:

int primid; vector primuv;
vector pos_uvw = rand(@Time) * {1, 1, 0};
float dist_uv = uvdist(1, "uv", pos_uvw, primid, primuv);

if( dist_uv < 1e-5 ){
vector pos_geo = primuv(1, 'P', primid, primuv);
float rad_pt = fit01( rand(@Time + 45), 0.02, 0.1 );

if( len(pts_close) == 0){
}
}

dart_throwing_mod.hiplc

• 3

##### Share on other sites
6 hours ago, anim said:

use pcfind_radius() which directly checks against pscale intersections, also you can directly use uvdist() to avoid having uvmesh

Thank you Tomas! I put together a little video tutorial summing it all up:

##### Share on other sites

Thanks guys.

Super useful feedback

##### Share on other sites

Hi guys,

there is much simpler solution I think, or maybe I do not understand what you want to achieve exactly...

1. scatter some random points

2. point wrangle with this conde
@pscale = distance(@P, point(0, "P", nearpoints(0, @P, 0.5)[1])) * 0.45;

3. sphere copy to points

all you need to do than is just delete all points but those you want

4. second line in the wrangle ( 10 points more every frame )
@ptnum * 0.1 > @Frame ? removepoint(0, @ptnum) : 0;

here the scene saved out with opscript
just copy paste it into Textport

# Automatically generated script
\set noalias = 1
set saved_path = `execute("oppwf")`
opcf /obj

# Node scatter_points (Object/geo)
oplocate -x -1.9984567901234569 -y 0.84104938271604945 scatter_points
opset -S on scatter_points
opparm -V 17.0.438 scatter_points stdswitcher ( 0 0 0 ) xOrd ( srt ) rOrd ( xyz ) t ( 0 0 0 ) r ( 0 0 0 ) s ( 1 1 1 ) p ( 0 0 0 ) pr ( 0 0 0 ) scale ( 1 ) pre_xform ( clean ) keeppos ( off ) childcomp ( off ) constraints_on ( off ) constraints_path ( "" ) lookatpath ( "" ) lookupobjpath ( "" ) lookup ( on ) pathobjpath ( "" ) roll ( 0 ) pos ( 0 ) uparmtype ( arc ) pathorient ( 1 ) up ( 0 1 0 ) bank ( 0 ) shop_materialpath ( "" ) shop_materialopts ( override ) tdisplay ( off ) display ( 1 ) use_dcolor ( off ) dcolor ( 1 1 1 ) picking ( on ) pickscript ( "" ) caching ( on ) vport_shadeopen ( off ) vport_displayassubdiv ( off ) vport_onionskin ( off ) stdswitcher4 ( 0 0 0 ) viewportlod ( full ) vm_rendervisibility ( * ) vm_rendersubd ( off ) vm_subdstyle ( mantra_catclark ) vm_subdgroup ( "" ) vm_osd_quality ( 1 ) vm_osd_vtxinterp ( 2 ) vm_osd_fvarinterp ( 4 ) folder0 ( 0 0 0 0 ) categories ( "" ) reflectmask ( * ) refractmask ( * ) lightmask ( * ) lightcategories ( * ) vm_lpetag ( "" ) vm_volumefilter ( box ) vm_volumefilterwidth ( 1 ) vm_matte ( off ) vm_rayshade ( off ) geo_velocityblur ( off ) geo_accelattribute ( accel ) vm_shadingquality ( 1 ) vm_flatness ( 0.050000000000000003 ) vm_raypredice ( 0 ) vm_curvesurface ( off ) vm_rmbackface ( off ) shop_geometrypath ( "" ) vm_forcegeometry ( on ) vm_rendersubdcurves ( off ) vm_renderpoints ( 2 ) vm_renderpointsas ( 0 ) vm_usenforpoints ( off ) vm_pointscale ( 1 ) vm_pscalediameter ( off ) vm_metavolume ( off ) vm_coving ( 1 ) vm_materialoverride ( compact ) vm_overridedetail ( off ) vm_procuseroottransform ( on )
chlock scatter_points -*
chautoscope scatter_points -* +tx +ty +tz +rx +ry +rz +sx +sy +sz
opset -d on -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off -x off scatter_points
opexprlanguage -s hscript scatter_points
opuserdata -n '___toolcount___' -v '1' scatter_points
opuserdata -n '___toolid___' -v 'geometry_grid' scatter_points
opcf scatter_points

# Node attribwrangle1 (Sop/attribwrangle)
oplocate -x -2.4265294082983231 -y 0.1248059013310604 attribwrangle1
opspareds "" attribwrangle1
opparm attribwrangle1  bindings ( 0 ) groupbindings ( 0 )
opparm attribwrangle1 folder0 ( 0 0 ) group ( "" ) grouptype ( guess ) class ( point ) vex_numcount ( 10 ) vex_threadjobsize ( 1024 ) snippet ( '@pscale = distance(@P, point(0, "P", nearpoints(0, @P, 0.5)[1])) * 0.49;\n@ptnum * 0.1 > @Frame ? removepoint(0, @ptnum) : 0;\n' ) exportlist ( * ) vex_strict ( off ) autobind ( on ) bindings ( 0 ) groupautobind ( on ) groupbindings ( 0 ) vex_cwdpath ( . ) vex_outputmask ( * ) vex_updatenmls ( off ) vex_matchattrib ( id ) vex_inplace ( off ) vex_selectiongroup ( "" )
chlock attribwrangle1 -*
chautoscope attribwrangle1 -*
opset -d on -r on -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off attribwrangle1
opexprlanguage -s hscript attribwrangle1
opuserdata -n '___Version___' -v '' attribwrangle1

oplocate -x -5.4176470588235297 -y 4.0552176561425721 testgeometry_pighead1
opparm testgeometry_pighead1 t ( 0 0 0 ) r ( 0 0 0 ) uniformscale ( 1 ) difficulty ( medium ) addshader ( on )
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off testgeometry_pighead1
opuserdata -n '___Version___' -v '' testgeometry_pighead1
opuserdata -n '___toolcount___' -v '1' testgeometry_pighead1
opcf ..
opcf scatter_points

# Node grid1 (Sop/grid)
oplocate -x -2.1764705882352939 -y 3.611764705882353 grid1
opspareds "" grid1
opparm -V 17.0.438 grid1 type ( poly ) surftype ( quads ) orient ( zx ) size ( 4 4 ) t ( 0 0 0 ) r ( 0 0 0 ) rows ( 10 ) cols ( 10 ) orderu ( 4 ) orderv ( 4 ) interpu ( on ) interpv ( on )
chlock grid1 -*
chautoscope grid1 -*
opset -d off -r off -h on -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off grid1
opexprlanguage -s hscript grid1
opuserdata -n '___Version___' -v '17.0.438' grid1
opuserdata -n '___toolcount___' -v '1' grid1
opuserdata -n '___toolid___' -v 'geometry_grid' grid1

# Node scatter1 (Sop/scatter::2.0)
oplocate -x -2.4235294117647057 -y 1.3764705941957589 scatter1
opspareds "" scatter1
opparm -V 17.0.438 scatter1 group ( "" ) stdswitcher ( 0 0 ) generateby ( bydensity ) densityscale ( 10 ) usedensityattrib ( off ) densityattrib ( density ) useareaattrib ( off ) areaattrib ( area ) indepvoxel ( off ) useareaforvolumes ( off ) forcetotal ( on ) npts ( 4370 ) usedensitytexture ( off ) densitytexture ( default.pic ) primcountattrib ( count ) useemergencylimit ( on ) emergencylimit ( 1000000 ) seed ( 0 ) overrideprimseed ( off ) primseedattrib ( primid ) randomizeorder ( on ) relaxpoints ( off ) relaxiterations ( 10 ) scaleradiiby ( 1 ) usemaxradius ( off ) maxradius ( 10 ) useprimnumattrib ( off ) primnumattrib ( sourceprim ) useprimuvwattrib ( off ) primuvwattrib ( sourceprimuv ) useoutputdensityattrib ( off ) outputdensityattrib ( density ) useoutputradiusattrib ( off ) outputradiusattrib ( pscale ) radiusintexturespace ( off ) pointattribs ( * ) vertattribs ( "" ) primattribs ( "" ) detailattribs ( "" )
chlock scatter1 -*
chautoscope scatter1 -*
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off scatter1
opexprlanguage -s hscript scatter1
opuserdata -n '___Version___' -v '17.0.438' scatter1

# Node sphere1 (Sop/sphere)
oplocate -x -5.6764705882352944 -y 0.31404118257410429 sphere1
opspareds "" sphere1
opparm -V 17.0.438 sphere1 type ( prim ) surftype ( quads ) rad ( 1 1 1 ) t ( 0 0 0 ) r ( 0 0 0 ) scale ( 1 ) orient ( y ) freq ( 2 ) rows ( 13 ) cols ( 24 ) orderu ( 4 ) orderv ( 4 ) imperfect ( on ) upole ( off ) accurate ( on ) triangularpoles ( on )
chlock sphere1 -*
chautoscope sphere1 -*
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off sphere1
opexprlanguage -s hscript sphere1
opuserdata -n '___Version___' -v '17.0.438' sphere1

# Node copytopoints1 (Sop/copytopoints)
oplocate -x -4.6294117647058828 -y -1.1601529349299033 copytopoints1
opspareds "" copytopoints1
opparm -V 17.0.438 copytopoints1 sourcegroup ( "" ) targetgroup ( "" ) showguide ( on ) pack ( off ) pivot ( centroid ) viewportlod ( full ) transform ( on ) doattr ( on ) labelparm ( Set Mult Add Sub ) setpt ( *,^v,^Alpha ) mulpt ( Alpha ) addpt ( v ) subpt ( "" ) setprim ( "" ) mulprim ( "" ) addprim ( "" ) subprim ( "" ) setvtx ( "" ) mulvtx ( "" ) addvtx ( "" ) subvtx ( "" )
chlock copytopoints1 -*
chautoscope copytopoints1 -*
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off copytopoints1
opexprlanguage -s hscript copytopoints1
opuserdata -n '___Version___' -v '17.0.438' copytopoints1

# Node merge1 (Sop/merge)
oplocate -x -3.1617647058823519 -y -2.9212529320927221 merge1
opspareds "" merge1
opparm -V 17.0.438 merge1
chlock merge1 -*
chautoscope merge1 -*
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off merge1
opexprlanguage -s hscript merge1

# Node switch1 (Sop/switch)
oplocate -x -3.761764705882352 -y 2.3258058914366897 switch1
opspareds "" switch1
opparm -V 17.0.438 switch1 input ( 0 )
chlock switch1 -*
chautoscope switch1 -*
opset -d off -r off -h off -f off -y off -t off -l off -s off -u off -F on -c on -e on -b off switch1
opexprlanguage -s hscript switch1
oporder -e grid1 scatter1 sphere1 copytopoints1 attribwrangle1 merge1 testgeometry_pighead1 switch1
opcf ..

opcf /obj
opcf scatter_points
opwire -n switch1 -0 scatter1
opwire -n sphere1 -0 copytopoints1
opwire -n attribwrangle1 -1 copytopoints1
opwire -n scatter1 -0 attribwrangle1
opwire -n copytopoints1 -0 merge1
opwire -n switch1 -1 merge1
opwire -n grid1 -1 switch1
opcf ..
opcf \$saved_path

## Create an account

Register a new account