Jump to content

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