# Ruby API: Numeric.degrees precision and a “magic 19”

One of my occasionally studies, when I worked with creating polygons, I have been discovered an interesting thing about Numeric.degrees precision.

Background:
During my study - for a better human reading - I just used degrees. `angle = (360 / side).degrees` After a while I realized visible distortion of the polygons (in SU drawing), when the side is longer length and side number is higher especially (19!).

First, I thought that I have a mistake in my vector and transformation calculation methods, whatever. But what about 19?

Suddenly I ‘replaced’ the 360 to 2xPI. `(angle = 2*Math::PI / side)` .
Bang! Everything became “nice and shiny” immediately. The distortion of the polygons are gone!

So, I made a test snippet to see what is going on:

``````def test_360_vs_2pi
puts "dif - side"
(1..30).each{|side|
ang_2pi = 2 * Math::PI / side
ang_360  = (360 / side).degrees
puts "#{((ang_2pi-ang_360)*1.0e6).round(6)} - #{side}"
}
end
test_360_2pi
``````

The result is:

``````dif - side
0.0 - 1
0.0 - 2
0.0 - 3
0.0 - 4
0.0 - 5
0.0 - 6
7479.982509 - 7
0.0 - 8
0.0 - 9
0.0 - 10
12693.303651 - 11
0.0 - 12
12083.048668 - 13
12466.637514 - 14
0.0 - 15
8726.64626 - 16
3079.992798 - 17
0.0 - 18
16534.698177 - 19
0.0 - 20
2493.327503 - 21
6346.651825 - 22
11382.582078 - 23
0.0 - 24
6981.317008 - 25
14768.170594 - 26
5817.764173 - 27
14959.965017 - 28
7222.052077 - 29
0.0 - 30
``````

You can see the big deviation when there is more sides.
I have no clue why 19 is the biggest and why e.g. 20 have no significant deviation again…

I don’t think that’s a bug, but it is at least interesting.
Any thought?

For me, Lesson learned:

Interesting

In World War II the average age of the combat soldier was twenty-six
In Vietnam he was nineteen
In inininininin Vietnam he was nineteen

Number 19 represents completion in numerology . This number is made up of numbers 1 and 9. Number 1 signifies a beginning and 9 signifies an end, which makes number 19 a message that indicates you’re set for the next stage in life, maybe also in SketchUp

And Kurt starts off with a nice simple definition that everyone knows about. He defines division . That is, how to divide one number with another. But he only uses the symbols of formal logic. So Kurt’s Definition #1 is:

y/x ≡ ∃z: y = x × z

This is read as follows (with a crib suppled):

y divided by x ( y/x ) is defined ( ) by the formal statement “There exists some number z ( ∃z ) such that ( : ) y equals x times z ( y = x × z ).”

Now note how much shorter the formal definition is. But here’s where Kurt did something that was new. You can write the formal definition, which is

∃z: y = x × z

as a unique number. Yes, the formula can be written as or actually mapped into the set of counting numbers. But only, we must caution, a special subset of the counting numbers. Kurt - with a bit of pardonable hubris - called his numbers Gödel numbers .

Now to write a Gödel number, you do this. First you must assign some numbers to the primitive symbols of the formal language. For instance, the first dozen symbols can be:

0 is 2
is 3
: is 4
= is 5
¬ is 6
is 7
( is 8
) is 9
× is 10
x is 17
y is 19
z is 21

To be honest this isn’t Kurt’s original numbering system. He used the highly simplified set that Bertie and Alfred created. Doing so avoids redundancies. For instance, saying “x is not equal to y” in the original symbols would be ¬(x = y). With out symbols you could also write this as x≠y. For now we’ll assume we can handle redundancies.

2 Likes

@MikeWayzovski, man, Saturday morning and I didn’t even have my coffee yet!

2 Likes

Couldn’t this be the problem? If you divide two integers you get an integer. For example
`360 / 19 == 18`
while
`360 / 19.to_f == 18.94736842105263`
It seems like 19 creates the maximum distortion because the integer division truncation removes almost a full degree.

6 Likes

Doh! I knew there was something basic in the background… Time for Correctly:

Then there will be no deviation!

4 Likes

resistance is futile.

1 Like