# XY points on an arc?

#### Davek0974

##### New member
This is where I embarrass myself with my total lack of math skills

I am trying to find the X,Y coordinates of points on an arc in 1 degree steps so 270deg to 90deg and i believe the answer lies in trigonometry

I know the answer is probably staring at me but i can't find it in a form that my feeble brain can interpret, its probably very simple to most ??

I really want a python formula that will take a degree input from 0 to 180, say 20 and return an XY pair that indicates that point on the arc at a known radius, say r=100.

It will end up running an LCD display of size 240 x 240 so the centre point will be x=120, y=120

Any help much appreciated

#### Zermelo

##### Junior Member
Hello there, I guess that by “arc” you mean points on a circle?
if you have a circle of radius r, centered at Cartesian coordinates (0,0), then any point on the circle is given by (r cos x, r sin x), where x is the angle in radians (that is the definition of sin and cos! They are coordinates of points on a unit circle, but you don’t have an unit circle, but a circle of cimc = r).
So, you first need to convert degrees to radians for this formula to work.
Then, you simply compute the points using the upper formula.
Then, you need to translate your solution by 120 in both axes, because your circle is centered at (120, 120).
Hope I didn’t get too much info away, and that everything is clear.

#### Davek0974

##### New member
Hello there, I guess that by “arc” you mean points on a circle?
if you have a circle of radius r, centered at Cartesian coordinates (0,0), then any point on the circle is given by (r cos x, r sin x), where x is the angle in radians (that is the definition of sin and cos! They are coordinates of points on a unit circle, but you don’t have an unit circle, but a circle of cimc = r).
So, you first need to convert degrees to radians for this formula to work.
Then, you simply compute the points using the upper formula.
Then, you need to translate your solution by 120 in both axes, because your circle is centered at (120, 120).
Hope I didn’t get too much info away, and that everything is clear.

Thanks, that actually helped a lot

How would i translate rotationally - i have a bit of code working now, roughed at least, using the info you gave, but if i input 90 degrees its at 3 o'clock, 180 is at 12 o'clock, 0 is at 6 o'clock

I need 0deg at 9, 90deg at 12 and 180deg at 3 if it were a clockface

#### Eugenio

##### New member
$x=120+100*cos(\alpha)$$y=120+100*sin(\alpha)$
Where [imath]\alpha[/imath] is the angle in radians (you have to convert first from degrees to radians)

The general formula for this is
$x=x_0+R*cos(\alpha)$$y=y_0+R*sin(\alpha)$
where [imath](x_0;y_0)[/imath] are the coordinates of the center of the circle and [imath]R[/imath] is its radious.

#### JeffM

##### Elite Member
$\pi \text { radians} = 180 \text { degrees.}$
$\therefore x \text { degrees} = \dfrac{\pi * x}{180} \text { radians.}$
So 90 degrees becomes pi/2 radians.

#### Zermelo

##### Junior Member
Thanks, that actually helped a lot

How would i translate rotationally - i have a bit of code working now, roughed at least, using the info you gave, but if i input 90 degrees its at 3 o'clock, 180 is at 12 o'clock, 0 is at 6 o'clock

I need 0deg at 9, 90deg at 12 and 180deg at 3 if it were a clockface
You probably didn’t convert to radians, Jeff gave you the answer on how

#### Dr.Peterson

##### Elite Member
Thanks, that actually helped a lot

How would i translate rotationally - i have a bit of code working now, roughed at least, using the info you gave, but if i input 90 degrees its at 3 o'clock, 180 is at 12 o'clock, 0 is at 6 o'clock

I need 0deg at 9, 90deg at 12 and 180deg at 3 if it were a clockface
You may need to check your coordinate system. You may have swapped x and y; x in mathematical coordinates is horizontal (positive to the right) and y is vertical (positive up). If looks like you are using screen coordinates, making x vertical with positive down.

If you want the rotation to be clockwise starting at the left, then you need to change the sign of the horizontal coordinate (specifically, of the cosine).

#### lex

##### Full Member
It would appear to me you need: [imath]x=120-100\cos\theta,\hspace2ex y=120+100\sin\theta[/imath]

#### Davek0974

##### New member
You may need to check your coordinate system. You may have swapped x and y; x in mathematical coordinates is horizontal (positive to the right) and y is vertical (positive up). If looks like you are using screen coordinates, making x vertical with positive down.

If you want the rotation to be clockwise starting at the left, then you need to change the sign of the horizontal coordinate (specifically, of the cosine).

Here we go, its in Micropython code...

_D2R = (math.pi/180)
_C = 120 # centre of display (240x240)
_R = 110 # radius of sweep line arc

a = input angle = 0 to 180 varying
b = a * _D2R # Convert degrees to radians

xs = int(math.sin(b)*_R)+_C
ys = int(math.cos(b)*_R)+_C

I believe the LCD zero coords are top-left so y axis is positive down, this may be the issue??

#### Dr.Peterson

##### Elite Member
If x is positive to the right and y is positive down, then you did swap the coordinates, and also have to adjust some signs.

Why did you choose to use sin for x and cos for y, the opposite of what you were shown?

And, yes, you need the negative for y to make your semicircle lie above the center; and if you want angle zero to be to the left, you also need a negative for x. So it should be

xs = -int(math.cos(b)*_R)+_C​
ys = -int(math.sin(b)*_R)+_C​

#### Davek0974

##### New member
If x is positive to the right and y is positive down, then you did swap the coordinates, and also have to adjust some signs.

Why did you choose to use sin for x and cos for y, the opposite of what you were shown?

And, yes, you need the negative for y to make your semicircle lie above the center; and if you want angle zero to be to the left, you also need a negative for x. So it should be

xs = -int(math.cos(b)*_R)+_C​
ys = -int(math.sin(b)*_R)+_C​
Thats sorted it - i was taking replies from a couple of sources and forgot to swap the cos/sin, my apologies

Working well now.