0
$\begingroup$

Sorry my math is very weak so it's difficult to research, this seems like it would be an obvious question that gets asked often.

I'm a budding software developer trying to write a watch face. The face is $240 \times 240$, for our purposes just consider $X(-120,+120)$ and $Y(-120,+120)$, easy enough to convert after.

Trying to derive $(X,Y)$ coordinates to draw hands based on hour/minute. Doing this case by case is easy enough. $\text{Minute} \times 6 = \theta$. This $\theta$ gets applied to $\sin / \cos$ depending on it's value.

The problem is writing it in a single function to derive. For example:

if(theta > 0 && theta <= 45) {
  X = sin(theta) * 120;
  Y = cos(theta) * 120;
}
else if (theta >= 45 && theta <= 90) {
  X = cos(theta) * 120;
  Y = sin(theta) * 120;
}

Then draw a line from [0,0] to $[X,Y]$.

Depending on the value the formula applied changes. This seems like it's surely a problem that somebody has had before. Any easy formula to account for this? Or it becomes 8 unique cases?

$\endgroup$
0

2 Answers 2

0
$\begingroup$

In clock the angle $\theta$ that you compute using $Minute\times6$ is the angle with respect you positive y axis in counter clockwise direction. For this theta you should write position of the minute hand which has a length $l$ as follows $$(x,y)= (l\sin\theta, l\cos\theta)$$ You don't have to worry which quadrant the minute hand is in, as that will be taken care of by the functions of $\sin$ and $\cos$. For example $$\theta=90 \implies(x,y)=(l,0)\\\theta=180 \implies(x,y)=(0,-l)\\\theta=270 \implies(x,y)=(-l,0)$$

$\endgroup$
1
  • $\begingroup$ This will even work if you have minutes more than 60. $\endgroup$
    – Sonal_sqrt
    Dec 28, 2017 at 8:44
0
$\begingroup$

Every two minutes the hour hand rotates by $\theta=1^0$, i.e., by half this time in mins and second hand by $60^0$

$$ (x,y) = 120 (\sin \theta, \cos \theta)$$

reckoning from $12\, O'$ clock position.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .