Why does this restlength not work?

   1541   3   0
User Avatar
Member
2 posts
Joined: Sept. 2017
Offline
Hello.
I am a beginner in Houdini.

I am currently trying to assign numbers to primitive attributes based on the individual lengths of the lines I draw.

However, when I try to use the VEX function to assign @index_num=1 to a line with a restlength of 0.2, some of the lines don't seem to respond, even though they are the same 0.2.
(For the second image, I tried the same thing, but in a different way, and the result was still the same.)

Does anyone know the reason for this and how to solve it?


Attachments:
1.PNG (76.1 KB)
2.PNG (71.4 KB)
linelength.hipnc (89.9 KB)

User Avatar
Member
94 posts
Joined: April 2011
Offline
Hi John,
From what I know, it's a matter a precision. Your values might seem to be equal to 0.2 in the spreadsheet but they might actually be 0.200548.
In this case, your condition will evaluate to false which will give you what you have.

In general, you should never use the equal sign while comparing to a float. What you should use is something more like that:
if (@restlength - 0.2 < 0.01) 
{
    i@index_num = 1;
}

This should fix your issue, as you are no more comparing the exact values.
User Avatar
Member
8555 posts
Joined: July 2007
Offline
to see the actual value instead of the rounded one you can check View/Full Precision in the Spreadsheet
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2 posts
Joined: Sept. 2017
Offline
Sorry for the delay in replying.

I did not know that such a specification existed.
I will try not to use the equal sign next time.
Also, thanks for sharing the details about spreadsheet.

Thank you both so much for your help!
  • Quick Links