Shrinking numbers
Posted: Fri Aug 17, 2018 3:43 pm
Why do the values gradually 'shrink' with this piece of code which rotates points in 3d around the y axis:
For example, watching a starting x value of -12 gives the following after each 360 degree circuit:
-11.429731395506
-10.886154091496
-10.368043324118
-9.8742290380113
I can't see where there's a rounding error, which is what it looks like, and the values are only being read elsewhere in the code (I even tried using math.floor(x + 0.5) to get rounded integer values but the problem persists).
Code: Select all
cos1 = math.cos(math.rad(1))
sin1 = math.sin(math.rad(1))
for i = 1, numPoints do
points[i].x = points[i].x * cos1 + points[i].z * sin1
points[i].z = points[i].z * cos1 - points[i].x * sin1
end
-11.429731395506
-10.886154091496
-10.368043324118
-9.8742290380113
I can't see where there's a rounding error, which is what it looks like, and the values are only being read elsewhere in the code (I even tried using math.floor(x + 0.5) to get rounded integer values but the problem persists).