Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

enter image description here

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);
like image 718
Alin Avatar asked Apr 26 '11 10:04

Alin


People also ask

How do you show a point is on the circle?

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.

How to find if a point is inside or outside a circle?

The idea is compute distance of point from center. If distance is less than or equal to radius. the point is inside, else outside.


2 Answers

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);
like image 107
Felice Pollano Avatar answered Oct 23 '22 05:10

Felice Pollano


x1 = x + r sin 10

y1 = y + r cos 10

x2 = x - r sin 10

y2 = y - r cos 10

like image 40
NickT Avatar answered Oct 23 '22 07:10

NickT