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

Re: [pygame] exact algebraic numbers?



Michael George wrote:
I'm trying to implement a game that allows dragging of objects while maintaining the fact that they do not intersect one another. I want to be able to drag one object so that it abuts another.

Another way to approach this is to allow a tolerance when
deciding whether two objects abut. If the tolerance is less
than a pixel, the player won't be able to tell the difference.

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

These are closed under multiplication and addition, still not sure about division

Hmm. Possibly it might be, although the formulas are going
to get pretty horrendous. For example, a quick calculation
shows that

  1 / (a + b*sqrt(2)) = (a - b*sqrt(2)) / (a*a-2*b*b)

which you can get by multiplying top and bottom by
(a - b*sqrt(2)).

Attempting the first stage of a similar trick using the
full form, I got

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

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

This no longer contains a sqrt(2) term, which is encouraging.
Presumably one could then go on to multiply this by
(a*a-2*b*b) - (a*c-2*b*d)*sqrt(3) to eliminate the
sqrt(3) term, and then E - F*sqrt(6) for some E and F to
be determined. But the back of my envelope is not wide enough
to accommodate any more of this.

As for libraries dealing with this kind of stuff, there
might be something in Sage. But you're probably not going to
want to bolt Sage into your game...

--
Greg