I\'m trying to figure out how I could be able to calculate coordinates on a circle. For simplicity I made some images.
Thats how:
private PointF getPosition(PointF center, float radius, float angle) {
PointF p = new PointF((float) (center.x + radius * Math.cos(Math.toRadians(angle))),
(float) (center.y + radius* Math.sin(Math.toRadians(angle))));
return p;
}
This method calculates the position around the center of a circle (center of your view) depending on radius and angle. Angle in degrees.
The returned PointF
will contain the x- and y-coordinate of the calculated position.
Be aware that 0 degrees is at the very east position of the circle, 270 degrees is in the very north position of the circle:
So if the center of your view is at x: 100, y: 100 and you calculate the position with an angle of 0 degrees and a radius of 50, the result will be x: 150, y: 100
If you use angle 90 degrees and radius 50, the result will be x: 100, y: 150
It is used here in my charting libary, and it works.