convert x and y to angle?

Mutatis Mutandis

New Member
Joined
May 6, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi folks,
Long time lurker but never had an account.

I'm trying to convert x and y coordinates (both positive and negative) to an angle and distance for a mapping project. I can calculate the length no problem but the angle is bugging me?

The origin is always 0,0 in this case.

I need the angle to run clockwise with 0/360 degrees being the positive y axis and run clockwise around the graph?

For example
X1 in cell A1 is 0
Y1 in cell B1 is 0
X2 in cell A2 is 3.3
Y2 in cell B2 is -3.7

Length in C2 is SQRT((A2-A1)^2)+((SQRT(B2-B1)^2)) the answer for the above example is around 4.9

But how do I calculate the angle in say D2 as the angle can be in any of the 4 quadrants? The angle in the above example is around 140 degrees clockwise from the positive Y axis?

I've been trying to sort this out for days and finally give up, my math skills are no longer what they used to be when I was at college :(

Cheers,

MM
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try this...angle relative to line connecting the origin (0,0) to specified point with respect to the vertical y-axis being 0 and positive angles in a clockwise direction.
MrExcel_20220505B.xlsx
ABCDE
100<-- (x1, y1)LengthAngle (degrees) wrt y axis=0 (clockwise +)
23.3-3.7<-- (x1, y1)4.96138.27
3110<-- (x1, y1)10.055.71
41-10<-- (x1, y1)10.05174.29
5-1-10<-- (x1, y1)10.05185.71
6-110<-- (x1, y1)10.05354.29
Sheet9
Cell Formulas
RangeFormula
D2D2=SQRT((A2-A1)^2+(B2-B1)^2)
E2:E6E2=IF(SIGN(A2)>=0,90-DEGREES(ATAN((B2)/(A2))),270-DEGREES(ATAN((B2)/(A2))))
D3:D6D3=SQRT((A3)^2+(B3)^2)
 
Upvote 0
For the angle formula in E2, you could use the following:

Excel Formula:
=MOD(DEGREES(ATAN2(B2,A2))+360,360)

The ATAN2 function will handle the signs to choose the right quadrant. The non-intuitive part is reversing the x and y coordinates to make the y-axis positive and reverse the positive angle direction. Adding 360 and using the MOD function with 360 as the divisor eliminates negative values.

Hope that helps.

Regards,
Ken
 
Upvote 0
Solution
Thanks Ken for the speedy replies, that works well and I can now get on with the main task in hand.

MM
 
Upvote 0

Forum statistics

Threads
1,215,824
Messages
6,127,087
Members
449,358
Latest member
Snowinx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top