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?
Why does this restlength not work?
1514 3 0- John_MR
- Member
- 2 posts
- Joined: Sept. 2017
- Offline
- Matthew05
- 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:
This should fix your issue, as you are no more comparing the exact values.
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.
- tamte
- Member
- 8449 posts
- Joined: July 2007
- Offline
- John_MR
- Member
- 2 posts
- Joined: Sept. 2017
- Offline
-
- Quick Links