tae
tae

Reputation: 51

Drawing no intersected polygon with dragging vertexes

I'm trying to draw a polygon without intersecting.

Below is good example which I want to.

enter image description here

Bad example what I want to prevent.

enter image description here

If I choose red dot one, then what algorithm I can apply to prevent the intersecting sides of the polygon?

Upvotes: 1

Views: 81

Answers (1)

user1196549
user1196549

Reputation:

Technical answer:

The moving point must belong to the visibility zones of its two neighbors (ignoring the two adjoining edges).

enter image description here

You can construct these two zones and their intersection once for all, then constrain the cursor to remain in the intersection. This can be made efficiently in time O(Log(N)) per query, after some preprocessing. But this is quite complex and not worth the effort.

enter image description here

Practical answer:

Simply check that the two edges from the moving point do not intersect the remaining edges.

Upvotes: 2

Related Questions