Jump to content
Sign in to follow this  
mois23

How to round to zero smallest attributes values?

Recommended Posts

Hi there, 

just a quick one. I have a cloud of points with an attribute that goes from -1 to 1.

Now, if a value it's really small and close to zero (ie 0.00001 or 1e-09), how I can round it to zero? And how I can do it based on decimal? Ie, if value is 0.001 or -0.001 I want to keep it as it is; if value is 0.0001 or -0.0001 I want it to be 0.

 

How I can do it in VEX?

 

Thank you so much!!

Edited by mois23

Share this post


Link to post
Share on other sites

Hi Mattia,

here are a few examples on snapping or shifting values:

snap.png.8713785a842e93db80de48f70e69c0ed.png

1) Once you have set the value to absolute with abs(), you can compare it to a threshold like 1e-1. Between more than -1 and less than <1 truncating will result to 0.

if(abs(v@P.y) < 1e-1)
  {v@P.y = trunc(v@P.y);}

2) With vectors calculating the distance() returns a value that can be compared:

if(distance(v@P, pos) < 1e-1)
  {v@P = pos;} 

3) For transitions (or a cheap wormhole effect) the smooth function remaps values to between 0.0 and 1.0

float dist = distance(v@P, pos);
float mask = 1.0 - smooth(0.0, thresh, dist, rolloff);
v@P = lerp(v@P, pos, mask);

zero.hiplc

Edited by konstantin magnus
  • Like 1

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  

×