# Thread: And now for some geometry: ordering 4 points around a quadrangle

1. ## Re: And now for some geometry: ordering 4 points around a quadrangle

yes, solution doing the right thing most of the time is the best we can get here. But what if the user draws a square rotated 45deg, the script shows him a solution but he wants the other one?
I'd say that if the algorithm and its reversed version (rotated versions?) yield the same result then we are golden, if these algorithm passes yield different solutions the user should be prompted to choose one.

2. ## Re: And now for some geometry: ordering 4 points around a quadrangle

In practice the path is set by putting its vertices over the corners of real windows in a photograph, so I doubt that the perfect diamond will ever show up...

3. ## Re: And now for some geometry: ordering 4 points around a quadrangle

yes, i suppose it's not going to happen

it occured to me that finding the order by finding crossing pairs is an overkill. It's enough to take 1 vertex and calculate a (y=ax+b) of lines connecting it to other vertices. a in the middle means diagonal (it has to be between sides) so if you sort a's you get vertices in order.
Having the order go to step 2.

4. ## Re: And now for some geometry: ordering 4 points around a quadrangle

Originally Posted by Vaphell
yes, i suppose it's not going to happen

it occured to me that finding the order by finding crossing pairs is an overkill. It's enough to take 1 vertex and calculate a (y=ax+b) of lines connecting it to other vertices. a in the middle means diagonal (it has to be between sides) so if you sort a's you get vertices in order.
Having the order go to step 2.
Will give that some thought. Looks like a good idea. There are algorithms to detect crossing segments, but I'll have to brush up my math to use them

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•