I have user input consisting of a drawn rectangle (freestyle). Now this drawn figure is not perfect, so I would like to redraw the form for them based on the algorithm.
I have a bunch of coordinates from a custom drawing. I would like to find the largest (x, y) and lowest (x, y) coordinates and use the distance between them to determine the diagonal of the rectangle.
But it's hard for me to determine the largest coordinate (x, y) and the lowest (x, y) coordinate.
I cannot take the largest y with the largest x or the largest x with the largest y, for example, because maybe the user just made a random attempt on his line. (It makes sense?)
Pretend below is the user's drawn line. If I used the largest y with the largest x, I would not have the desired coordinate (because it will find the coordinate in a random ledge)
---- / \ ----/ \-------- ----- -- --------------/ \---------------/ \------/ \--
Hope you understand what I get ..
I suppose another way to put it is that I need the coordinate closest to (0,0), and if my canvas was 1000 x 1000, I would like the second coordinate to be closer to (1000,1000). (two extreme coordinates)
Can anyone help with this algorithm?
Thanks in advance!
source share