prat391 Posted December 7, 2021 Share Posted December 7, 2021 Hi all, I am in the process of trying to make a procedural building system and have seemed to encounter an error. I have a very small piece of vex code that is deleting top and bottom-facing prims by checking if their @N.y value is <0 or >0. vector ynorm = @N; if(ynorm.y > 0 || ynorm.y < 0){ removeprim(0,@primnum,1); } A few primitives which should have a @N.y of 0 value have incorrect values like -5.67663e-0 or -1.0457e-07. This is causing primitives that should not be deleted, to be deleted. How can I correct these normal values? Quote Link to comment Share on other sites More sharing options...
dleonhardt Posted December 8, 2021 Share Posted December 8, 2021 Those values are most likely rounding errors. In cases where like here the values are very very small, I would just give a small tolerance to the if statement. So something like: if(ynorm.y > 0.0001 || ynorm.y < 0.0001) Quote Link to comment Share on other sites More sharing options...
acey195 Posted December 10, 2021 Share Posted December 10, 2021 On 8-12-2021 at 9:40 AM, dleonhardt said: Those values are most likely rounding errors. In cases where like here the values are very very small, I would just give a small tolerance to the if statement. So something like: if(ynorm.y > 0.0001 || ynorm.y < 0.0001) Yup never rely on floats with == checks a further alternative would be something like: if(abs(dot(ynorm, {0,1,0})) > 0.001) or if you want to set a specific angle: if(acos(abs(dot(ynorm, {0,1,0}))) > radians(<angle in degrees>)) 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.