![]() |
![]() |
#1 |
Apr 2010
32·17 Posts |
![]()
Here comes a nice gem for those of you who occasionally want to check "rectangularity" of the polygon given by four points
The ordering of the points shall matter; points with index distance 2 are interpreted as diagonally opposite. If you get this wrong, you have a shape containing an X or Z, and that shall be considered far from rectangular. The task is to find a measure for un-rectangleness in the form of just one nonnegative real value, 0 being equivalent to "perfectly rectangular". A plurality of tests* e.g. for checking angles and lengths separately does not fulfill these requirements. Second, besides the measure, you need to choose a reference entity to compare with, such that if the measure exceeds some given fraction of the reference, the quadrilateral** given by the vertices The basic idea has already been given in the title: Think of (1) What would you "naturally" choose as measure for un-rectangleness then? (2) Find mid-point, diagonal directions and diagonal length of the "fitting rectangle". Compare with the given quadrilateral. (3) Choose a suitable reference for the measure. Demonstrate that it bounds errors in angles, relative side lengths, and is suitable for ruling out X shapes even when we are dealing with large aspect ratios. *: Is "plurality of [...]" common language, or Patentese only? **: Tetragon? Quadrangle? What do you prefer? Last fiddled with by ccorn on 2010-07-04 at 20:21 |
![]() |
![]() |
![]() |
#2 |
Apr 2010
32·17 Posts |
![]()
Note: Using algebra and local optimization is allowed, as are Lagrange multipliers. This should ease dimension-independent reasoning. The results shall be interpreted geometrically however.
|
![]() |
![]() |
![]() |
#3 |
Apr 2010
32×17 Posts |
![]()
Here is a figure.
|
![]() |
![]() |
![]() |
#4 | |
Jul 2006
Calgary
52×17 Posts |
![]() Quote:
|
|
![]() |
![]() |
![]() |
#5 |
Jul 2006
Calgary
52·17 Posts |
![]() |
![]() |
![]() |
![]() |
#6 |
"William"
May 2003
New Haven
22×593 Posts |
![]()
Don't you need to check planarity in addition to right angles when n>2?
|
![]() |
![]() |
![]() |
#7 | |
"Richard B. Woods"
Aug 2002
Wisconsin USA
22·3·641 Posts |
![]() Quote:
In 3D: Suppose three points A,B,C are vertices of a right triangle (Angle ABC = 90 degrees). At vertex A construct a disc that's perpendicular to AB. At vertex C construct a disc that's perpendicular to BC. Consider any point D that is on the intersection line of the two discs. Then DAB = BCD = 90 degrees. If D is not coplanar with A,B,C then angle CDA must be less than 90 degrees. As D slides along the intersection line, angle CDA reaches a maximum (90 degrees), and lengths AD and CD both reach a minimum, exactly when D is on the A,B,C plane. If D is not coplanar with A,B,C then the lines CD and AD are hypotenuses of right triangles with a vertex D' where the discs' intersection line meets plane ABC. Then, DD' has nonzero length, CD must be longer than CD', AD must be longer than AD', and angle CDA must be less than the right angle CD'A. Draw the diagonal AC. Then length AC = the square root of the sum of the squares of AD' and CD'. Since AD > AD' and CD > CD', AC is less than the square root of the sum of the squares of AD and CD, so AC can't be the hypotenuse of a right triangle ADC. I think this holds true in higher dimensions, too. Last fiddled with by cheesehead on 2010-07-08 at 17:20 Reason: Not elegantly minimized, but Oll Korrect now, I think. |
|
![]() |
![]() |
![]() |
#8 | |
"William"
May 2003
New Haven
22×593 Posts |
![]() Quote:
Hence it is NOT sufficient to check 3 angles, but it is sufficient to check all four angles. This suggests a solution to the puzzle - calculate the pythagorean error at all four vertices, and take a. The largest or b. The sum of the absolute values d. The sum of he squared deviations A useful solution probably includes some kind of scaling to adjust for the pixel granularity. William |
|
![]() |
![]() |
![]() |
#9 |
Apr 2010
32×17 Posts |
![]()
Those are interesting observations. In particular, they show some aspects of why checking a number of angles can be insufficient.
Already in 2D, even checking four angles is not sufficient. With large enough aspect ratio, you can have crossing sides (the X shape) with all four angles arbitrarily close to 90 degrees, and with opposite sides having exactly the same length. Anyway, as I mentioned in the description of the problem, doing several isolated tests (here: checking several angles) shall be considered a general no-no. The idea I want to convey is that of a "fitting rectangle". If "fitting" somehow does not trigger enough neurons, think of "regression" instead. If the task were to fit sample data to a function of some given form, you would know what to do. Well, actually, yes, this is the task. I have illustrated the problem with a figure in post #3. The blue rectangle tries to fit the yellow quadrilateral. (That the blue rectangle's sides happen to be parallel to the pixel coordinate axes is not a requirement; I arranged for that in order to enable you to verify most easily that it is a rectangle.) It cannot fit perfectly because the yellow quadrilateral is not rectangular. However, the blue rectangle tries to come close to the yellow quadrilateral. There is a fairly standard criterion to define what is "close", and you know it. Use it, then questions (1), (2), (3) can be addressed in a straightforward manner. Depending on how clever you map the problem to mathematical expressions, you get the puzzle done with 1...3 sheets of paper, with remarkable results. Last fiddled with by ccorn on 2010-07-08 at 21:01 |
![]() |
![]() |
![]() |
#10 |
Apr 2010
32·17 Posts |
![]()
Here is the same set of four given vertices as in post #3, but
Last fiddled with by ccorn on 2010-07-08 at 21:06 |
![]() |
![]() |
![]() |
#11 |
"Richard B. Woods"
Aug 2002
Wisconsin USA
22·3·641 Posts |
![]() |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Rectangle Packing | henryzz | Puzzles | 4 | 2012-02-05 16:23 |