2
\$\begingroup\$

I’m trying to do hyperbolic pong in a Poincaré disk.
I'm using C++ and SFML.
Here is my problem: when the ball rebounds on a paddle, I deduce two coordinates allowing me to recover the equation of the hyperbola in circular equation form:

x² + y² + ax + by + 1 = 0

So, I have my equation and I can only move my sprite from x and y coordinates or I don’t know how to do it differently.
How can I do to move my sprite following this circle equation? Moreover, I would like, in a second time also represent the Poincaré metric, so the ball velocity will also vary in function of the metric and it position…

\$\endgroup\$
3
\$\begingroup\$

We can solve this by completing the square:

x² + y² + ax + by + 1 = 0
x² + ax + a²/4 + y² + by + b²/4 + 1 - a²/4 - b²/4 = 0
(x + a/2)² + (y + b/2)² = (a² + b²)/4 - 1

This means the circle's center is at (-a/2, -b/2) and has radius = sqrt(a² + b² - 4)/2 (meaning we lack a solution if a² + b² < 4)

You can compute an offset from the circle's center to your sprite's current coordinates to get its phase angle theta:

theta = atan2(sprite.y + b/2, sprite.x + a/2)

And then move your sprite along this circular arc by incrementing/decrementing theta (depending on whether you want to move counter-clockwise or clockwise).

newPosition.x = cos(theta) * radius - a/2
newPosition.y = sin(theta) * radius - b/2

I'll have to punt for now on the magnitude of the increment to theta that corresponds to a consistent speed under the Poincaré metric, but hopefully this gives you enough to get started. :)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.