Jump to content
foible50

Distance Expression Query

Recommended Posts

I recently saw an example of someone having used the distance expression to isolate a point on a separate geometry which shared the same position.  They used it in the following expression:

 

if(distance($TX, $TY, $TZ, point("../each1", 0, "P", 0), point("../each1", 0, "P", 1), point("../each1", 0, "P", 2)) == 0,1,0)

 

When the delete node was put to 'delete non-selected' it seemed to have the desired effect of deleting all the points from the incoming geometry, except the one sharing the precise location as point 0 from the 'each1' node.  What I can't make sense of is why the distance is 0, 1, 0 and not 0, 0, 0, as I would've thought that there should be no distance between them.  I hope I've explained this clearly enough to make it make some sense - I've included a hip file beneath - but if anyone could give me an answer then I'd be really grateful as I've been puzzling over it for weeks!

 

Many thanks

 

Toby

distanceExpressionMystery.hipnc

Share this post


Link to post
Share on other sites

I think it's just about the if statement:

if(condition, do this if True, do this if False) so

if(distance is equal to 0, set to 1, otherwise set to 0)

actually condition = distance($TX, $TY, $TZ, point("../each1", 0, "P", 0), point("../each1", 0, "P", 1), point("../each1", 0, "P", 2)) == 0

if(distance($TX, $TY, $TZ, point("../each1", 0, "P", 0), point("../each1", 0, "P", 1), point("../each1", 0, "P", 2)) == 0,1,)

I suppose isn't necessary the "if" statement, it should works putting the condition itself and the answer will be 1 for True and 0 for False, but I may be wrong

Share this post


Link to post
Share on other sites

Thank you so much for answering this and so thoroughly - it seems obvious now you say it, I just got confused by the format and it was driving me crazy feeling like I couldn't work it out.  Many, many thanks!

Share this post


Link to post
Share on other sites

You also can split long expressions to make it more readable.

{
    float x = point("../each1", 0, "P", 0);
    float y = point("../each1", 0, "P", 1);
    float z = point("../each1", 0, "P", 2);
    return distance($TX, $TY, $TZ, x, y, z) == 0;
}

Some reference on HScript Expressions syntax.

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

×