Math.Floor err


#1

So I have a model with a bunch of stuff that is slightly off axis. I wanted to quickly know how many grids were off axis. I thought it would be simple but maybe not? I figured Math.Floor and == would be the quickest way to check and see if a girds angle was an integer or a number.

As you can see the grids that are at 180 round down to 179 but the ones at 90 stay at 90. Is this because it is so close that dynamo displays a rounded number with Vector.AngleWithVector when its really 179.somthing?

== then also returns true for 90.00000000000003 and its rounded counter part 90. I would expect a false value here.

Thanks for any insight,
Steven


#2

Hi Steven

I’d guess as Math.Floor returns “A number representing the largest integer less than or equal to the specified number.” that the value of 180 is actually 179.99999999999999999999999 and thus automatically rounded. However it does look strange that, (number 26) is floored from 1.72 to 0 and that they are deemed equal.

EDIT: as @viktor_kuzev rightly observe it is 1.72e-13 which naturally is floored to 0.


#3

@Jonathan.Olesen is right about Math.Floor(), so I would use Math.Round() in this case as it returns the closest integer.
image

Regarding angles, it seems that there is always a small float point error. I tested with 3 vectors, 2 slightly off axis and other rotated at exactly 45 degrees, and even this last one seems to have a very small difference when rounded.

One quick approach would be to multiply both original and rounded values by a large number (10e14 for example) and check if the difference is small than a defined thresdhold (1 on the example below).


#4

If you look closely it’s 1.72 e-13 which means 13 zeroes before 1 or 0.000000000000172.


#5

Good eye, then it does make sense :sweat_smile:


#6

Of note: after 6 zeros (0.000000x) Revit stops indicating that the element is off axis, so using a math.round to 7 digits will get you a consistent result.


#7

@alvpickmans Thanks for the suggestion. Math.Round will work since I am just trying to see if it is a whole number. Would it make more sense to convert the number to a string and check for a decimal though?

@JacobSmall I just checked and there is not a warning for a grid being slightly off axis. would you say that these grids are fine?

My original intent was to check and see that all grids were rotated to a whole number. I was recently brought on to a project that had an angled grid at 31.567899 degrees. In 99% of project there should never be a non rounded grid angle. What is the best way to test this? I can round to 6 decimal places and check to see if that is an integer or not. This would exclude grids that are off axis more than Revit can measure. Not sure if this is ignoring a problem though.

image


#8

Depends on your definition of ‘fine.’

Revit is basically saying that from that point on it will allow you to snap a linear dimension between it and other elements. Anything that tosses a warning won’t allow that in my experience. It could also mean that you’re spending more time calculating room/area/etc volume. You basically are working at a tolerance that partially exceeds the floating point capability of either Revit, dynamo, or the conversion tools in between.