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 on other sites

Hi Mattia,

here are a few examples on snapping or shifting values:

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);
Edited by konstantin magnus
• 1