How to get the x and y coordinates in a circle from an angle

Asked

Viewed 36 times

-1

I’m trying to create an analog clock and my idea was the following one would get the angle corresponding to the hour and then discover the position x e y of that angle in a circle and draw a line from the center of my watch up to the given positions to thus display the hands. But I’m having trouble getting the positions from that angle. My code so far is this:

calendar = Calendar.getInstance();
        int h = Integer.valueOf(new SimpleDateFormat("hh").format(calendar.getTime()));
        int m = Integer.valueOf(new SimpleDateFormat("mm").format(calendar.getTime()));
        a = (h * 30) + (m / 2);

1 answer

0


First you have to know which direction the pointer will be displayed (Example: in hour 3 in 27 minutes) and then you have to make a calculation to know the condemned Y and X in which the pointer will mark in the direction corresponding to the time

Image example A imagem representa um circulo com 360°, e seus valores em H e M

In this picture a circle with 360° (E in the theoretical min = -160 & max = 160) and it has the parameter H and each H has a parameter M, so when completing 4h, we were able to go around in the circle (result of 360°) and as you also use the minutes, we added the parameter M of H, and we also completed 1 hour full

Code example

double h = 360/4; 
double m = h/4;
double result = h*3 + m*4;

System.out.println(result); 
//Log: 360.0

Obs: Now you take this result, you make a system to define the exact direction of each pointer on its X and Y axis

int x = 680;
int y = 680;

int eixoX = y / ...
int eixoY = x / ...

//Cada unidade vai ser um valor simultâneo entre a direção do círculo e o eixo do ponteiro
//direção: 117 = 90°
//eixo: 36 = 90°

resultX = eixoX * result;
resultY = eixoY * result;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.