# Nearest point with colour above a certain value

## Recommended Posts

I posted here (http://forums.odforce.net/topic/20626-flipping-animation/) yesterday but haven't yet received any replies so I will ask a more basic question that should help me solve the problem in my other post.

If I have a grid of black points and I colour some of them red, how can I find the nearest red point for the other (black) points. I'm fairly sure it would be:

- pcopen

- pciterate

- if red is > 0.1

But then how would I break out of the pciterate and use that found point, e.g. to get the distance between the found red point and the current black point?

Cheers,

Mike

##### Share on other sites

something like this?

```float thr = .1;
int maxDst = 5;
int maxPts = 30;
int clRed = -1;
int pthandle = pcopen(0, "P", @P, maxDst, maxPts);
while(pciterate(pthandle)){
vector ptCd;
pcimport(pthandle,"Cd",ptCd);
int ptIx;
pcimport(pthandle,"point.number",ptIx);
if(ptCd.x>thr){
clRed = ptIx;
break;
}
}
pcclose(pthandle);
if(clRed>-1){
vector distVec = point(0,"P",clRed);
float dist = length(distVec-@P);
i@clPt = clRed;
f@redDst = dist;
}```
Edited by rayman
• 2

##### Share on other sites

That looks like it should work! Thanks Pavel i'll try it now!

##### Share on other sites

That works great! However i'm using a foreach sop to iterate over the primitives so I need to find the nearest red point in one of the primitives (that doesnt exist inside the foreach sop) so i'm trying to reference a node above it but now i'm just getting 0 for the redDst attribute.. any ideas what i'm doing wrong? Here's the basic hip file im testing with:

https://dl.dropboxusercontent.com/u/18098614/triangle_flip_v3.hip

Mike

##### Share on other sites

PCFilter and get P.

If you use pcImport you can get the distance or the point number of the point it's iterating on as well.

http://www.sidefx.com/docs/houdini13.0/nodes/vop/pcimport

• 1

##### Share on other sites

Thanks for the advice, I have it pretty much working now but the rotation is behaving slightly odd, each primitive starts to rotate in one direction then (I think) at 90 degrees it flips to the other side... Is there a problem with my rotation vop sop?

https://dl.dropboxusercontent.com/u/18098614/triangle_flip_v3.hip

Thanks,

Mike

##### Share on other sites

That works great! However i'm using a foreach sop to iterate over the primitives so I need to find the nearest red point in one of the primitives (that doesnt exist inside the foreach sop) so i'm trying to reference a node above it but now i'm just getting 0 for the redDst attribute.. any ideas what i'm doing wrong? Here's the basic hip file im testing with:

https://dl.dropboxusercontent.com/u/18098614/triangle_flip_v3.hip

Mike

I created a simple vopsop to find the nearest red point for each  black points.

Hope it help.

find_near_point.hip

Edited by wateryfield

##### Share on other sites

Hey I dont think the file attached properly? I got that working thanks Pavel's code if you take a look at my hip file posted above (https://dl.dropboxus...gle_flip_v3.hip)

Cheers

## Create an account

Register a new account

×
• Donations