Vinita
Vinita

Reputation: 95

Converting angle of circle to time in minutes

I have been trying to develop a clock control with a help of a circle. So if the circle is at 360 degree its 3'O clock, if its 90 degree then it will be 12'o clock. I can't figure out what formula can be used to find the time in hh:mm format if I have the angle of the circle.

eg.

9'o clock is 180 degree. 3'o clock is 360 degree 12'o clock is 90 degree and so on.

Upvotes: 3

Views: 10923

Answers (4)

EnLil
EnLil

Reputation: 1

hrs=date +%H #H >> min=date +%M #min >> dim=echo "scale=2; $hrs * 60 + $min" | bc #day in minutes >> dis=echo "scale=2; $dim * 60 + $sec" | bc #day in seconds >> did=echo "scale=2; $dis / 240" | bc #day in degree >>

The Planet revolution is One degree per 240 seconds.

I work to make a sumerian-time-sys . One sumerian hour is equivant with two current HRS or 30 revolution-degree. search for sexagesimal systems. Have fun!

Upvotes: 0

Tap
Tap

Reputation: 6522

There's probably a more concise way to do this, but here's what you need to do.

  1. Calculate the decimal value of the time, using 3 - (1/30) * (angle mod 360)
  2. If the result is less than zero, add 12.
  3. Take the integer portion to use as the hours, replacing a value of zero with 12.
  4. Take the remainder (the decimal portion of the calculation from step 1) and convert to minutes by multiplying by 60.
  5. Format your hours and minutes, padding with leading zeros if less than 10, and combine them with the colon.

An example implementation in java:

public static String convertAngleToTimeString(float angle) {
    String time = "";
    float decimalValue = 3.0f - (1.0f/30.0f) * (angle % 360);
    if (decimalValue < 0)
        decimalValue += 12.0f;

    int hours = (int)decimalValue;
    if (hours == 0)
        hours = 12;
    time += (hours < 10 ? "0" + hours: hours) + ":";
    int minutes = (int)(decimalValue * 60) % 60; 
    time += minutes < 10 ? "0" + minutes: minutes;
    return time;
}

Upvotes: 3

Bernhard Barker
Bernhard Barker

Reputation: 55619

First assume 12 o'clock is at 0 degrees. This makes sense because the degrees just increases when going around the clock once, and so does the hours (there's no wrap-around), so maybe we can just multiply the hours by a constant.

To have it reach 360 again at 12 o'clock, we need to multiply the hours by 360/12 = 30.

So now 3 o'clock is at 90 degrees and 12 o'clock is at 0.

Subtract 90 and we have 3 o'clock at 0 and 12 o'clock at -90.

Then make it negative and we have 3 o'clock at 0 and 12 o'clock at 90, as required.

There we go, now you just need to put it all together.

Upvotes: 1

user1416564
user1416564

Reputation: 401

You could check out these formula's on Wikipedia, they might help: http://en.wikipedia.org/wiki/Clock_angle_problem

But other than that, you could do something simple like, degrees/360 * 12. + offset.

For example, if we set that 360 degrees is 12 o'clock, and you had 90 degrees. You would get. 90/360 * 12 = 3. So that would be 3'o clock. Then you could add your offset, which in your case is 3 so it would be 6 o'clock.

Upvotes: 2

Related Questions