Something about how to locate the coordinates

Hello guys, I got problem in locating coordinates, and kinda hoping anybody can help me out.

I am intend to draw a circle and small 3D Rectangle. I want to use a Timer to rapaint the painting and make the rectangle can move on the circleSMOOTHLY, so I use the code

xRec = (int) xCentre + radius * Math.cos(angle);

yRec = (int) yCentre + radius * Math.sin(angle);

angle += 1;

to produce the coordinates of the rectangle, I want to use "double" in the code, but because either the draw3DRec or fill3DRec method can only support "integer", so I have to parse the coordinates from double to int, and it causes a problem: because the angle has to change 1 degree each time, but not like 0.1, 0.2....... so it causes the difference values between the last coordinates of rectangle and the current one too large and make the rectangle looks like jumping on the circle but not smoothly moving.

Does anyone has idea to solve my problem please?

Million thanks.

Jack

[1086 byte] By [jack_hzya] at [2007-11-27 11:56:24]
# 1

For me the problem isn't rounding but big angle increase step.

Math.sin and cos argument is double (radians)

I would say you have to define double angle and step should be 0.01 or even 0.01.

Or Math.PI/180

Regards,

Stas

StanislavLa at 2007-7-29 19:07:24 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thanks for your reply, Stas.

I had tried what you suggest before I posted. the problem is, the value that produced by Math.cos or Math.sin is double, but the value that used by draw3DRec is int, so I have to parse it from double to int. if the value is between 0.0 to 1.0, the one after parsed could be 0, which means the coordinates of the rectangle are (0,0), it will stay in the top-left corner, or the original position forever. That is the real problem.

Regrads

Jack

jack_hzya at 2007-7-29 19:07:24 > top of Java-index,Desktop,Core GUI APIs...