Jump to content
Sign in to follow this  
prat391

Incorrect @N size

Recommended Posts

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?

bad.JPG

@N.JPG

geo.JPG

Share this post


Link to post
Share on other sites

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)

 

Share this post


Link to post
Share on other sites
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>))

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×