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
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
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) (center.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);
To determine the position of a given point with respect to a circle, all we need to do is to find the distance between the point and the center of the circle, and compare it with the circle's radius. If the distance is greater than the radius, the point lies outside.
The idea is compute distance of point from center. If distance is less than or equal to radius. the point is inside, else outside.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With