# nearest pt num

## Recommended Posts

I'm using Houdini 15, and i'm following CmiVfx Connections tutorial, chapter 4 where you create sphere and grid and a vop sop wich is suposse to tell which point from the sphere is closest to which point on the grid. I know things changed with the latest H release, and i thought i kind of a figured it out, but all i get is constant number and it's not point number that is closest to anything. I'va attached the file, if anyone can look inside and tell me what i'm missing?

nearestPTNUM.hip

##### Share on other sites

in a attrib wrangle:

i@closestpoint = nearpoint(1,@P);

• 1

##### Share on other sites

thank you so much Bunker! so easy.. still got a loooot to learn.

and how about other attributes like distance between 2 points, normals, position, color, alpha? can it all be done in attribute wrangle node or is this suposse to be done in pc import?

##### Share on other sites

getting attributes is easy, now that you have the point number, you can use the "point" function:

int closestpoint = nearpoint(1,@P);
v@Cd=point(1,"Cd",closestpoint);

or in just one line:
v@Cd=point(1,"Cd",nearpoint(1,@P));

using pointclouds you can limit the search radius:

int maxpoints = 1;
// import Cd from first point from second input
@Cd = pcimportbyidxv(handle,"Cd",0);

you'll have to replace pcimportbyidxv if the attribute is a float for example: pcimportbyidxf

or in one line:

@Cd = pcimportbyidxv(pcopen(1,"P",@P,1,1),"Cd",0);

getting the distance is easy:

vector P2 = pcimportbyidxv(pcopen(1,"P",@P,1,1),"P",0);

float dist = distance(@P,P2);

• 1

## Create an account

Register a new account