I am working on an html map creator, and I would like to offer our users the ability to quickly create shapes by clicking in the zone, instead of manually defining the shape.
First, let's see what we are doing at the moment. The user would like to display area A. He needs to click several times at each point to define the boundaries of the form.

I would like to know if there is an algorithm that allows the user to click in area A and can determine which points to position in order to create an almost optimal shape, following the boundaries of the form - based on the image contrast.
My first idea to deal with this was to identify the furthest points up, left, down, right from the click point. Set these four points as a starting point. Then, for each segment, divide it into a new point and move the new point along the vector normal until I click on the opposite edge.
Of course, there are some limitations to this approach, but here's what I can assume
- the shape may be convex, concave, etc.
- the contrast should be black from white, but to control possible changes, you must configure the contrast.
- in the example I was thinking about above, it is obvious that there will be a limit on the depth of the unit so as not to kill the user machine.
If any of you know about this alogrite, it will be really great.
samy
source share