Anyone have Python code for generating x,y coordinates around a circle?

Since I can’t rotate watch hands I’ve been using my artwork for faces with marker bars and circles to indicate hours and minutes. Usually reserved for faces with a big picture I don’t want to cover with hands.

https://apps.repebble.com/rabbit-rectangle_cd52b892128c47d68bf19489

I hand place the hours once an hour with an if statement. I used Python to generate a 60 place minutes if statement with those known values and in a rectangle it’s easy enough to hand edit the rest since either X stays the same or Y stays the same over a decent range.

For a circle it’s not so rosy. Both X and Y change. My attempts to translate my usual sin and cosine formula for coordinates yields weird results. I believe it’s also a matter of the minutes circle image being placed by it’s upper left coordinate of the square it’s in rather than by its center coordinate. Examples of what I am after are easy enough to find on-line, but the output is not in clockwise from top zero order in any of them.

If all else fails, I’ll just place each minute circle by hand like I did with the rectangular face. The round version of the above face is much nicer, but currently only moves the minutes every five minutes.

https://apps.repebble.com/e24bd0e5939e4238a709219b

Is the Midpoint circle algorithm one of the methods you don’t want to use?

I don’t believe I’ve seen this method, or if I did I didn’t realize what I was seeing.

My usual method in Facer and Watch Face Studio from Samsung is:

X = (160+(130*(cos(rad(#DWFSS#+90)))))

Y = (160+(130*(sin(rad(#DWFSS#+90)))))

that’s to place an image always right way up in this case. The #DWFSS# is smooth seconds rotation for a second hand usually. For some reason I have failed so far translating this to CloudPebble, but I should give it another look now that I’m thinking of using python to generate the big if statement I want to generate. Before I was trying to translate it to Javascript to use in CloudPebble.

I’ll have a look at the algorithm you suggest as well.

Thanks.

Are you using C? Or JS? With C there’s a polar te rectangular coordinate function. With JS just use the same formula you do in Facer

Well, I should maybe try the Javascript route again. At the moment I am using Python to generate a 60 item list of coordinates for minutes that I paste into CloudPebble Javascript window.

x = (130+(110*(math.cos(math.radians((minutes * 6) - 90)))))
y = (130+(110*(math.sin(math.radians((minutes * 6) - 90)))))

xStr = str(round(x))
yStr = str(round(y))

A sign change from “+90” to “-90” has the coordinates that come out roughly in a circle clockwise, but I can’t seem to control where the center of that circle is. Changes on one side of the dial that work throw off the other side. That sort of thing.

A bit annoying since in the two other face creation systems I’ve been using this is trivial. With the time I’ve just spent on this method I could probably have hand placed each minute.

The center of that circle is (130, 130)

Indeed. That’s clear since when I first started using it. I am less sure, but the 110 part I take to be the length of a line from the center outward. The 110 values were what I was messing with trying to get my circles around 5, 10, 15 minutes etc.

I’m embarrassed that the simple sign change fixed the “coordinates are being generated counter-clockwise” and it only just occurred to me when I looked at it again.

That formula worked just fine for this face where the hour dial rotates around the center and the hour hand rotates from the center of the moving hour dial.

For future reference, Desmos graphing calculator is a great resource for visualising formulas like this

1 Like

I’m not quite sure what problem you’re trying to solve.

Given:

  • a time in minutes M = 0 .. 60
  • and a circle of radius R centred on coordinates (X,Y)

To obtain coordinates (x,y) lying on the circumference that correspond to the minute hand position on a normal clock at time M:

  • x = X + R * cos(a)
  • y = Y + R * sin(a)

where a is angle in radians such that:

  • a = 2 * pi * (15-M)/60

For hours H = 0 .. 12, replace M = 5 * H ( ie. a = (3-H) * pi/6 )
You can subtract (2 * pi/12) * M/60 from a to account for hour hand movement in between exact hours.


The above assumes x increases to the right and y increases upward.

If y increases downward, I think the equations are the same except:

  • y = Y - R * sin(a)

I beat my if statement for coordinates x,y for minutes into rough shape. Then I hand adjusted each minute.

Calculated coordinates for the minute circle for one or two arcs between minutes were almost correct. Others really needed to be moved both x and Y.