[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] exact algebraic numbers?



Michael George schrieb:
Hello,

For my game I need to represent right isosceles triangles, and do operations including translation and rotation in 15 degree increments. Unfortunately, I cannot tolerate rounding error, because it will cause bad visual and gameplay artifacts. I'm thinking of representing points as vectors where the components are of the form

a + b * sqrt(2) + c * sqrt(3) + d * sqrt(6)

where a, b, c, and d are rationals. I believe numbers of this form are sufficient for my purposes, although I haven't worked out all the proofs yet. Anyway, I was wondering if anyone has done anything similar and can suggest a library I can use for manipulating such vectors before I go off and implement it myself.

Thanks!

--Mike

Hi

I don't think that you can avoid rounding errors, unless you use a math library that takes the math errors of the computer into account (which can differ from hardware to hardware).

I'm not sure, why you want to represent points in such a complicated way, but I don't know the theory about it and I'm not a mathematician.

One way to go is to accumulate the angle of a rotation (same for translation) and use the accumulated angle on a object to transform it into the right orientation (if you do use a previously rotated object then you will get much more rounding errors over time!). Using that way one would have a variable 'angle' which would be incremented in 15 degree steps (15, 30, 45,...) and use it to construct the rotation matrix (or whatever it is used to rotate). This should be precise enough.

Unless you can draw using subpixels, you will have rounding errors when trying to draw the points on integer coordinates of the screen anyway.

Maybe I'm wrong.

~DR0ID