Jump to content

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

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

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

Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...