Poincare Disk

Hi,

I'm trying to make a basic program where I have a bunch of circles on a Poincare disk, and one of them is controlled with arrow keys.

What would be handy is to do all the moving code and whatnot in Euclidean space and then make a hyperbolic projection only when I want to actually display stuff.

Unfortunately, I'm not sure how to go about this, or even if it is the best way of doing it.

What I have at the moment are three classes: A main class (not important), and a HypObject class (a generic object that lives on a hyperbolic space) and a Circ class, which extends HypObject. The two methods in question are a method for moving forward by (dx, dy), and a method for drawing the object in the appropriate place with appropriate scaling.

The moving method, which is in the HypObject class, as far as I've been able to figure, is:

publicvoid move(double dx,double dy)

{

//diskX and diskY are the circle's

//current location in the unit disk centered at the origin

double x = diskX;

double y = diskY;

//Using the metric tensor to

//calculate the distance being moved

double ds = 2*Math.sqrt(dx*dx + dy*dy)/(1 - x*x - y*y);

double theta = Math.atan(dy/dx);

double R = 1;

if(y >= 0)

{

R = (x*x + y*y - 1) / (2*y);

}

else

{

R = (x*x + y*y - 1) / (-2*y);//?

}

//R now represents the radius of the circle that makes

//the geodesic tangent to the (Euclidean) vector (dx, dy).

//Using this, we can move a distance ds

//along this arc in the appropriate direction to get

//the new diskX and diskY:

double psi = ds / R;

double D = Math.sqrt(dx*dx + dy*dy);

//The cartesian coords of the center of the ``geodesic circle'':

double cx = x + (R*dy) / D;

double cy = y - (R*dy) / D;

double newX = cx + R*Math.sin(psi - theta);

double newY = cy - R*Math.cos(psi - theta);

diskX = newX;

diskY = newY;

}

That's the gist of my current approach, but I'll want to get this one settled out before I start drawing things.

It seems somewhat wrong, judging from numerical output, but I'm not exactly sure what to fix, as it doesn't really follow the way of doing this I was hoping to get.

Thanks in advance for your help!

[3449 byte] By [xplodesa] at [2007-10-3 4:34:40]
# 1
if you are asking whether your formulas(or application of formulas) are correct then you may be asking in the wrong place.If you are doubting the precision of double(you should be) then go ahead and try BigDecimal. You will get different results
r035198xa at 2007-7-14 22:38:19 > top of Java-index,Java Essentials,Java Programming...