We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I have an arraylist that contains a number of points that all belong to the edge of an open surface. I am trying to sort the list so that the points are in clockwise order. I have the center c and the normal n of the surface, but still I have no idea of how to do the sorting in terms of code. Any help would be much appreciated!
Answers
in theory make a class PointInCircle that holds the PVector and the angle
put this class PointInCircle in an arraylist
now calc each angle using atan2 or so
then make compare method in the class iirc and sort it by angle
gotoloop has written a lot about it
google the keywords here in the forum
I have the comparison of angles already. Any idea of how to do the sorting afterwards? I've seen examples in stack overflow but I don't understand the syntax
Ask @gotoloop
Or google "sort" here in the forum
Or click on the tag sort
Ok, thanks a lot for the reply!
Have you created a class that holds the point and the angle about the centre as suggested by chrisir?
The way to sort the points depends on whether you have created a class or not. If you have a class then you can use Java's built in sort routines if not you are going to have to code your own sorting algorithm.
https://forum.processing.org/one/topic/altenratives-sorting-via-comparable.html
this is for finding you angle (0 degrees is to the right (east))
code by the forum
Thanks everyone for the reply! I figured it out eventually :)
Can you post it
Ok, there you go. I did it in a different way eventually
`
boolean isNeighbour; Particle pt0 = (Particle) arrayOfSideParticles.get(0); pt0.isChecked = true; arrayOfSortedEdgePoints.add(pt0); Particle selected = null;
Thanks!