views:

61

answers:

2
+4  A: 

I would probably go through all line segments, calculate the distance of the point to the line segment, and insert the point between the end points of the line segment with the shortest distance to the new point. Further I would only consider line segments where the line through the new point and perpendicular to the line through the end points of the line segment intersects the line segment.

Daniel Brückner
Considering the "Further" part of that reduces the complexity of the distance of point to line - you won't have to consider distance from point to end-points. This *might* also give results equivalent to answer from Mau but simpler to implement.
phkahler
+1  A: 

I would go though all pairs of corners, compute the bisector to the 2 angles. If the clicked point falls into the semi-plane defined by the 2 bisectors and the segment between the 2 angles, then your point must be added to the current segment (i.e. the new point gets connected to the 2 corners under exam).

You have to be careful with concave polygons. If the 2 bisectors intersect outside the polygon, the point must be added to the current segment only if it falls inside the triangle defined by bisectors and segment.

Example:

alt text

Mau
Mau , is there a link to an image ? seems its invalid.
umanga
@umanga: the link broke, sorry. Fixed now.
Mau