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:
Use radians!