Hubert Solecki
Hubert Solecki

Reputation: 2761

Calculate points coordinate in canvas by axes

I need to make a rotating wheel on my android App. To do so, I'm creating a custom View in order to place it anywhere I want in the App activities. All around the wheel, I need to place TextViews. Thanks to the width and height of the view, I can get the center point of the canvas' view. I know the angle, I know the radius, so now I need to place textviews on the edge of the circle by calculating the coordinates on the canvas.

enter image description here

Does anyone knows how to achieve that ?

Thanks in advance !

Upvotes: 2

Views: 140

Answers (1)

Rohit Jagtap
Rohit Jagtap

Reputation: 1670

A point at angle theta on the circle whose center is (x0,y0) and whose radius is r is (x0 + r cos theta, y0 + r sin theta)

Or Once you have drawn the circle you have to rotate the canvas put the text at required angle and then again restore it as,

canvas.save();
canvas.rotate(45, x, y);
canvas.drawText("your text here", x, y, paint);
canvas.restore();

Hope that helps..!!

Upvotes: 2

Related Questions