开发者

Find point on Circle on Android

Everything seemed so plain and simple until I had to actually program it.

What I've got

I uploaded an image to explain it better.

  • I have a circle and I know

    • it's radius
    • center point coordinates
    • each button's initial coordinates (the red circles).

I want to be able, when I rotate the gray circle image, with 10 degrees, to calculate red buttons new coordinates (x1y1, x2y2).

This shouldn't be hard to achieve for someone who knows math, but I didn't manage to find a suitable solution. I've also searched around here and couldn't find a working solution. Any help is greatly appreciated. Thank you

Find point on Circle on Android

The working solution, as Felice stated below is:

-first take care of rotation angle, on each redraw simply increment it

   angle = angle+mainRotationAngle;

    float x =  (float) (cente开发者_如何转开发r.X + Math.cos(angle*Math.PI / 180F) * radius 
    float y =  (float) (center.Y + Math.sin(angle*Math.PI / 180F) * radius

    button.setX(x);
    button.setY(y);


It is easyer if you keep with you the button initial angles, then modify the angle to produce the rotation. so in pseudocode:

newAngle = Angle+rot;
xbutton = center.x+cos(newAngle)*radius;
ybutton = center.y+sin(newAngle)*radius;

If you really just have the coordinates of the buttons, you can convert them to the angle by using the function atan2, in pseudocode:

buttonAngle = atan2(button.y-center.y,button.x-center.x);


x1 = x + r sin 10

y1 = y + r cos 10

x2 = x - r sin 10

y2 = y - r cos 10

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜