Jump to content

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

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

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

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

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

Link to comment
Share on other sites

  • 1 year later...

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...