I have user input that consists of a drawn rectangle (freestyle). Now this drawn figure isn’t perfect, so I would like to redraw the shape for them based on an algorithm.
I have a bunch of coordinates from the user’s drawing. I would like to find the greatest (x,y) and the lowest (x,y) coordinates and use the distance between those to determine the diagonal of the rectangle.
But I’m having difficulty determining the greatest (x,y) coordinate and the lowest (x,y) coordinate.
I can’t take the greatest y with the greatest x, or the greatest x with the greatest y for example because maybe the user just made an accidental jut out in their line. (Does that make sense?)
Pretend below is a user drawn line.. if i used the greatest y with the greatest x, I would not have the desired coordinate (because it would find the coordinate in the accidental jut out)
----
/ \
----/ \-------- ----- --
--------------/ \---------------/ \------/ \--
Hope you understand what I’m getting at..
I guess another way of putting it is that I would like the coordinate closest to (0,0) and if my canvas was 1000 x 1000, I would like the second coordinate to be closest to (1000,1000). (the two extreme coordinates)
Can anyone help with this algorithm?
Thanks in advance!
if you want to find the closest point to (0,0), then just find it!
you can easily modify the algo to find points closest to the rest of screen edges.