Sorting coordinates of a rectangle (or square or any closed form) in excel clockwise or anti-clockwise when input coordinates are not in any order

Sunny Baggu

New Member
Joined
Jul 14, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hii , Greetings!
In excel, I have points or coordinates of rectangle or any closed shape (example rectangle, square , L shape ).
However the given points or (x,y) coordinates are not in any specific order.
The available points could be in any numbers (including corner points and inline points too).
Then how do I sort the coordinates and plot a rectangle or closed shape in excel chart.
Sample coordinates are given below:

Coordinates of closed shape
Node No.X (m)Z (m)
1181290
11815180
119573618
12033027
120503627
123036
101981
1181000
122611881
122702781
122793681
120773636
230045
12093645
12105054
121133654
234270
324360
1185609
11868369
11939018
12123063
8763663
1220072
12223672
12254081
1667063075957.png
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Add an angle column like I did in column c, then sort the table by the angle column, and plot the sorted table x and y columns. If you want to connect the starting and ending nodes, repeat the top sorted coordinate at the bottom.

SortCoordinates.xlsm
ABCDEFGH
1XYTheta
20.115430.9933161.455108-0.87791-0.47883-2.64227
3-0.874670.4847112.63556-0.8174-0.57607-2.52768
40.017786-0.99984-1.55301-0.74832-0.66334-2.41632
5-0.74832-0.66334-2.41632-0.46047-0.88768-2.04932
6-0.239610.970871.812757-0.38566-0.92264-1.96671
70.4225310.9063481.13456-0.38533-0.92278-1.96637
8-0.217540.9760521.790086-0.13949-0.99022-1.71075
9-0.658930.7522052.2901910.017786-0.99984-1.55301
10-0.13949-0.99022-1.710750.169118-0.9856-1.40086
11-0.38533-0.92278-1.966370.644842-0.76432-0.86998
12-0.87791-0.47883-2.642270.7493350.6621910.723739
13-0.46047-0.88768-2.049320.671370.7411220.83474
140.644842-0.76432-0.869980.4225310.9063481.13456
15-0.38566-0.92264-1.966710.115430.9933161.455108
160.671370.7411220.83474-0.128010.9917731.699158
17-0.8174-0.57607-2.52768-0.217540.9760521.790086
180.169118-0.9856-1.40086-0.239610.970871.812757
190.7493350.6621910.723739-0.658930.7522052.290191
20-0.128010.9917731.699158-0.874670.4847112.63556
21
Sheet3
Cell Formulas
RangeFormula
C2:C20,G2:G20C2=(-1)^(B2<0)*ACOS(A2/(A2^2+B2^2)^0.5)


1667082104784.png
 
Upvote 0
Note that if your shape is not centered at (0,0) the formula in C2 becomes a bit more complex:

Excel Formula:
=(-1)^((B2 - AVERAGE($B$2:$B$20))<0)*ACOS((A2 - AVERAGE($A$2:$A$20))/((A2 - AVERAGE($A$2:$A$20))^2+(B2 - AVERAGE($B$2:$B$20))^2)^0.5)
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

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