Jump to content
michaelb-01

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 this post


Link to post
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
  • Like 2

Share this post


Link to post
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

 

Thanks for your help,

Mike

Share this post


Link to post
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 this post


Link to post
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

 

Thanks for your help,

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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×