LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sort clockwise

Solved!
Go to solution

I have a series of order pairs stored in a Vector such that the first ordered pair has the xcoord in index 0 and the ycoord in index 1, and so on for every ordered pair. Now I want to print out a traversal of the pairs in clockwise order, with the start point being arbitrary. Anyone have any ideas of how to sort these coords in a clockwise order or how to print them out that way. Any help would be appreciated. 

0 Kudos
Message 1 of 11
(3,989 Views)

Here is one way to do it.  The key is the Sort Complex Numbers VI.  The shift is so the Sorted Array starts with the element at location Start Index in the original array.

 

21177i86245E3962A1CEA1

0 Kudos
Message 2 of 11
(3,979 Views)

Could you include it as a .vi file? Thanks.

0 Kudos
Message 3 of 11
(3,974 Views)

I misread how you stored your points, here is a VI version which uses a 2D array along with another snippet.  If you have LV2009, you can drag these pictures to your BD and the code will be placed.  If you do not have LV2009, the VI I attached won't be much more help and you will have to let me know which version you are using.

 

21181iA83B58B5E7C9881C

0 Kudos
Message 4 of 11
(3,970 Views)

Mine is 8.5.1. Drag/Drop doesn't work here.

 

Thanks

 

0 Kudos
Message 5 of 11
(3,967 Views)
Solution
Accepted by AliEskan

Try this version which I saved to 8.5.

0 Kudos
Message 6 of 11
(3,962 Views)

Thank you. This is not sorting them clockwise tho b/c the center is not always the origin. I believe it'll work tho if I move the center to the average of the points, do the sort by your VI and return them back to where they were. I'll try to make it work. 

0 Kudos
Message 7 of 11
(3,951 Views)

Ok, this is not working unless if we are able to make it sort just by phase angle and I can't find that option here. Do you know how to do that? I attached my file.

Thanks.

0 Kudos
Message 8 of 11
(3,944 Views)

It appears to work for me.  Notice how I set the magnitude to 1 before sorting, this makes it sort only on phase.  You may want to graph the points, along with your center point to verify.

0 Kudos
Message 9 of 11
(3,939 Views)

A few ideas to simpify the code. I don't think we need to pull out the big guns to sort complex numbers if all we are interested is sorting the phase, which is a plain DBL array. 😉

 

Here are a few code draft fragments. Of course you should put Darin's code back in to get the rows of the 2D array and to rotate the array to shift the origin around. Also note that if you built the final array inside the loop, you don't need to transpose. (Sorry, the snippet is 2010, but the attached VI is 8.5)

 

Download All
0 Kudos
Message 10 of 11
(3,934 Views)