top of page

Code snippet: Houdini create curve from shortest path

  • Ellie Ansell
  • Nov 15, 2020
  • 1 min read

Given scattered points, build a curve from the shortest path. This was used to create loops on lots of geos to sim for CFX.





int nps[] = nearpoints(0, v@P, chf("maxdist"));
int pts_found[];
int pt_id=0;
int cur_pt=0;
append(pts_found, cur_pt);
int n=1;
vector p;

for (int pt=0; pt<@numpt; pt++)
{
    n=1;
    p = point(0, "P", cur_pt);
    nps= nearpoints(0, p, chf("maxdist"), 300);
    while(find(pts_found, nps[n])>=0 && n<120)
    {
        n++;
    }
    pt_id = nps[n];
    append(pts_found, pt_id);
    setpointattrib(0, "np", cur_pt, pt_id, "set");
    cur_pt = pt_id;
}

i[]@pts_found = pts_found;
@pt_id = pt_id;
i[]@nps = nps;
@n=n;


//New wrangle:

//use the nearpoint to create polyprim lines between nodes.
int prim;
int pt_id = 0;

prim=addprim(0, "polyline");

for (int pt=0; pt<@numpt; pt++)
{
    addvertex(0, prim, pt_id);
    pt_id = point(0, "np", pt_id);
    @pt_id=pt_id;
    addvertex(0, prim, pt_id); 
}


Comments


  • LinkedIn // Professional Bio
  • Facebook // ellieansellart page
  • Instagram // Informal fun
  • Vimeo

© 2020 by Ellie Ansell

Happily created using Wix.com

bottom of page