Background (skip if you just want to get to the problem):

I’m still trying to implement the voronoi project, having run into some issues with my initial method.

Initially, i was incrementing the radius around a point, and when the the radius intersected with a line I would add a line which would be located at the inital point of intersections and grow with the radius size, using arc length formula, and if it met any other lines it would stop growing. Whilst this seemed like a good approach at first, there are just too many problems that I would later have to correct, to make the project work.

as you can see from the picture, there are a few lines which never intersect, and so would have to be rectified later.

End of Background,

So instead i thought of calculating the midpoints from each point to every other point ( I know this means a lot of operations and is not really feasible as the size of the program grows). However if I calculate intersections with points already in my array first, then I wouldn’t have to deal with iterating through all the points as I would break out of the loop if an intersection is found.

So thats the theory anyway, apart from I’m stuck ordering the points by angle, around the central point.

It works fine in most cases,

however in some cases this happens.

This is due to the fact that angles are calculated clockwise from x = 0 direction.

I however do not understand how to approach correcting this issue.

```
Parent closest(ArrayList<Parent> a){
//next = a.get(a.size()-1);
Parent k = a.get(0);
Parent c = null;
if(sorted_mpoints.size()==0){
c = new Parent(W,H,100000);
}
else{
c = sorted_mpoints.get(sorted_mpoints.size()-1);
}
//k = a.get(0);
for(int i=0;i<a.size();i++){
Parent b = a.get(i);
Float d1 = dist(k.x,k.y,x,y);
Float d2 = dist(b.x,b.y,x,y);
float t1 = atan2(k.y-y,k.x-x);
float t2 = atan2(b.y-y,b.x-x);
if(t2<t1){
k = b;
}}
return k;
};
```