j00ey Posted July 15, 2013 Share Posted July 15, 2013 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 Quote Link to comment Share on other sites More sharing options...
tony Posted July 15, 2013 Share Posted July 15, 2013 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 Quote Link to comment Share on other sites More sharing options...
j00ey Posted July 15, 2013 Author Share Posted July 15, 2013 (edited) 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 July 15, 2013 by j00ey Quote Link to comment Share on other sites More sharing options...
anim Posted July 15, 2013 Share Posted July 15, 2013 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 Quote Link to comment Share on other sites More sharing options...
j00ey Posted July 15, 2013 Author Share Posted July 15, 2013 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. Quote Link to comment Share on other sites More sharing options...
tony Posted July 15, 2013 Share Posted July 15, 2013 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. Quote Link to comment Share on other sites More sharing options...
j00ey Posted July 15, 2013 Author Share Posted July 15, 2013 Thanks. Useful information! Quote Link to comment Share on other sites More sharing options...
Fenolis Posted November 17, 2014 Share Posted November 17, 2014 It would seem that the if() expression in Houdini is capable of nesting conditions, as in the case you stated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.