Jump to content

Incorrect @N size


prat391

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

Link to comment
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>))

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...