Clock Hands problem 74

Back to General discussions forum

ancastillov     2022-11-02 03:15:51

I do not see where mistake on my code. I did try the follow. but my answer it is diferent in in many cases

    import math
    input = "00:07 19:08 22:07 15:48 21:48 06:26".split()

    r_min = 10
    r_hora = 6
    pi = math.pi

    for tiempo in input:

      tiempo = tiempo.split(":")

      hora = int(tiempo[0]) % 12
      min = int(tiempo[1])
      teta_min = 0
      teta_hora = 0
      sigma = hora * pi / 6 + min * pi /360

      if 0 <= min and min <= 14:
        teta_min = abs(pi / 2 - pi * min / 30)
        posicion_min = [ r_min * math.cos(teta_min) +10 , r_min * math.sin(teta_min) +10 ]

      if 15 <= min and min <= 29:
        teta_min = abs(pi / 2 - pi * min / 30)
        posicion_min = [ r_min * math.cos(teta_min) +10 , -r_min * math.sin(teta_min) +10 ]

      if 30 <= min and min <= 44:
        teta_min = abs(pi  - pi * min / 30)
        posicion_min = [ -r_min * math.cos(teta_min) +10 , -r_min * math.sin(teta_min) +10 ]

      if 45 <= min and min <= 59:
        teta_min = abs(pi  - pi * min / 30)
        posicion_min = [ -r_min * math.cos(teta_min) +10 , r_min * math.sin(teta_min) +10 ]

      if 0 <= hora and hora <= 2:
        teta_hora = abs(pi / 2 - sigma)
        posicion_hora = [ r_hora * math.cos(teta_hora) +10 , r_hora * math.sin(teta_hora) +10 ]

      if 3 <= hora and hora <= 5:
        teta_hora = abs(pi / 2 - sigma)
        posicion_hora = [ r_hora * math.cos(teta_hora) +10 , -r_hora * math.sin(teta_hora) +10 ]

      if 6 <= hora and hora <= 8:
        teta_hora = abs(pi - sigma)
        posicion_hora = [ -r_hora * math.cos(teta_hora) +10 , -r_hora * math.sin(teta_hora) +10 ]

      if 9 <= hora and hora <= 11:
        teta_hora = abs(pi - sigma)
        posicion_hora = [ -r_hora * math.cos(teta_hora) +10 , r_hora * math.sin(teta_hora) +10 ]

      print(posicion_hora, posicion_min)
Rodion (admin)     2022-11-02 11:56:36
User avatar

Could you instead post some example of your answer and expected answer?

Your code seems to be quite wrong, sorry :) there shouldn't be so many lines, you need not split the full circle into quarters. Both sin and cos work fine over all the circle.

Check your code with some simple examples. For example where it points at 12:30? hour hand shouldn't point exactly at 12!

Please login and solve 5 problems to be able to post at forum