Hi ive created an array which holds PVectors of points on a sketch, when mouse is pressed a point is created at mouseX and mouseY. im trying to connect each point to its closest neigbour in order to make a planar graph with one face. which should look something like

Unfortunately this statement does not match the diagram if we take

connect each point to its closest neigbour

We get the following graph

make a planar graph with one face

This is ambiguous because a planar graph would allow for lines to intersect but the ‘one face’ and the diagram suggests that what you want is a polygon i.e. a closed shape without intersecting lines.

A problem must be clearly defined if we are to devise a good algorithm to solve it

Might just be missing something but why don’t you just loop round the array, and connect, the last item to the first item? Problem solved no?

Also I can see a possible problem in your approach, your seeking the closest neighbour, which is fine, but from your first diagram you can see that the first and lat point counting clockwise from top left are not closest neighbours.