Jump to content
j00ey

HScript IF expression - double less than operator

Recommended Posts

Hi

I'm just looking at one of the example files [specifically PointCloudIterateAverage] whilst investigating point clouds and I came across this syntax which I cannot fathom :

if($TX*$TX + $TZ*$TZ < 8 < 0.5, 0, 1)

It's in an attributecreate SOP, creating a point attribute on a grid. I don't understand the double 'less than', how can that evaluate properly. It seems to me to be saying if $TX squared + $TY squared is less than 8 is less than 0.5 but that makes no sense. Can anyone help me out?

Thanks very much

Share this post


Link to post
Share on other sites

I've never come across it before, but I just tested it out and it seems to evaluate exactly the same as if you put:

if($TX*$TX + $TZ*$TZ > 8, 0, 1)

I read it like this:

x=(($TX*$TX) + ($TZ*$TZ)) < 8

y=x<0.5

(this seems strange as x would either be 0 or 1, but still)

if(y,0,1)

or:

if( ( ( ($TX*$TX) + ($TZ*$TZ) ) < 8) < 0.5, 0, 1)

Definitely not the most friendly way of writing an expression.

Cheers,

Tony

Share this post


Link to post
Share on other sites

Hi Tony

Thanks for the reply.

It does evaluate like that, you're right but I still don't understand...

Looking at your reading of it can you explain something quickly? On the first line

x=(($TX*$TX) + ($TZ*$TZ)) < 8

Am I right in think this evaluates as 1 if (($TX*$TX) + ($TZ*$TZ)) < 8 and 0 otherwise? So hence in the second line

y=x<0.5

if x==0 y will be 1?

I've never come across this sort of notation, I wonder if you can string as many operators as you like together...

Thanks again

*EDIT - it would seem you can, this doesn't throw an error -

if($TX*$TX + $TZ*$TZ < 8 < 0.5 < 0.5 == 0 !=0, 0, 1)

Edited by j00ey

Share this post


Link to post
Share on other sites

it will not error out as there is an order of evaluating each operator and in case of operators with equal precedence it's left to right

ressions/_operators'>http://www.sidefx.com/docs/houdini12.5/expressions/_operators

so using as many operators in an expression as you want is ok, it just doesn't make sense to overcomplicate an expression if it's possible to use simpler form

Share this post


Link to post
Share on other sites

No, I see what you're saying Tomas. I had no idea that you could use more than 1 operator at all so interesting to learn that you can. I doubt if I will be making a habit of it myself as it seems a little illegible but good to be able to decode it when I come across it.

Thanks for replying.

Share this post


Link to post
Share on other sites

Looking at your reading of it can you explain something quickly? On the first line

x=(($TX*$TX) + ($TZ*$TZ)) < 8

Am I right in think this evaluates as 1 if (($TX*$TX) + ($TZ*$TZ)) < 8 and 0 otherwise? So hence in the second line

y=x<0.5

if x==0 y will be 1?

Yes that's right.

Share this post


Link to post
Share on other sites

It would seem that the if() expression in Houdini is capable of nesting conditions, as in the case you stated.

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

×