<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE page SYSTEM "gen/gandraxa.dtd">
<?xml-stylesheet type="text/xsl" href="gen/gandraxa.xsl"?>
<!--
	To see this page properly, install a browser capable of
	interpreting XML/XSL, for example a recent version of:
	- Mozilla Firefox, see http://www.mozilla.com/
	- Google Chrome, see www.google.com/
	- Internet Explorer, see http://www.microsoft.com/
-->
<page bodywidth="765">
	<head>
		<title>Detect Overlapping Subrectangles</title>
		<url>http://gandraxa.com/detect_overlapping_subrectangles.xml</url>
		<context>
			<path>
				<home>
					<link loc="int">
						<url>home.xml</url>
						<text>Home</text>
					</link>
				</home>
				<dir>
					<link loc="int">
						<url>articles.xml</url>
						<text>Articles</text>
					</link>
				</dir>
				<doc>Detect Overlapping Subrectangles</doc>
			</path>
		</context>
		
		<author>
			<mail>
				<recipient>hg</recipient>
				<server>gandraxa.com</server>
				<name>Herbert Glarner</name>
			</mail>
		</author>
		
		<publ>
			<event>
				<eventdate><y>2006</y><m>Dec</m><d>20</d></eventdate>
				<eventtext>Original HTML version</eventtext>
			</event>
			<event>
				<eventdate><y>2011</y><m>Jan</m><d>29</d></eventdate>
				<eventtext>
					Recoded in XLM
				</eventtext>
			</event>
		</publ>
		
		<furtherreading>
			<readitem>
				<link loc="wiki">
					<url>http://en.wikipedia.org/wiki/Karnaugh_map</url>
					<text>Karnaugh map</text>
				</link> on Wikipedia
			</readitem>
			<readitem>
				<link loc="wiki">
					<url>http://en.wikipedia.org/wiki/Gray_code</url>
					<text>Gray code</text>
				</link> on Wikipedia
			</readitem>
			<readitem>
				<link loc="ext">
					<url>http://www.nist.gov/dads/HTML/karnaughmap.html</url>
					<text>Karnaugh_map</text>
				</link>
				by Sandeep Kumar Shukla,
				in the <em>Dictionary of Algorithms and Data Structures</em> [online], Paul E. Black, ed.
			</readitem>
			<readitem>
				<link loc="ext">
					<url>http://www.embedded.com/showArticle.jhtml?articleID=16100908</url>
					<text>A primer on Karnaugh maps</text>
				</link>
				by Jack W. Crenshaw:
				Boolean algebra and Karnaugh maps
			</readitem>
		</furtherreading>
	</head>

	<toc>
		<toc1 ref="A">Introduction</toc1>
		
	<toc2 ref="A1">Scope</toc2>
		
	<toc2 ref="A2">Problem Description</toc2>
		<toc1 ref="B">Analysis</toc1>
			<toc2 ref="B1">Used Terminology</toc2>
			<toc2 ref="B2">Quantification</toc2>
			<toc2 ref="B3">The Need for Completeness</toc2>
			<toc2 ref="B4">All Cases</toc2>
			<toc2 ref="B5">Karnaugh Map</toc2>
			<toc2 ref="B6">Variable Naming</toc2>
			<toc2 ref="B7">Prime Implicants</toc2>
			<toc2 ref="B8">Simplification and Result</toc2>
			<toc2 ref="B9">Verification</toc2>
			<toc2 ref="B10">Theorem</toc2>
		<toc1 ref="C">Algorithm</toc1>
			<toc2 ref="C1">Formal</toc2>
			<toc2 ref="C2">In Computers</toc2>
			<toc2 ref="C3">Application</toc2>
	</toc>

	<abstract>
		<p><ptitle>Abstract</ptitle>
			This article shows, if two different rectangles sharing an identical area involving at least 2 edges
			can be combined into a single polygon with a subrectangle shared by both constituting rectangles.</p>
	</abstract>



	<part>
		<heading id="A">Introduction</heading>
		<chapter>
			<heading id="A1">Scope</heading>
			<body>
				<p>If we have</p>
				<list>
					<li>two essentially different rectangles ("main rectangles") 
						of arbitrary size larger than 0;</li>
				    <li>in each main rectangle an identical rectangular area of equal or smaller size ("subrectangle"), 
				    	starting at an arbitrary position within the main rectangle;</li>
				    <li>the edges of each subrectangle (if any), which are shared at least partially 
				    	with the parental main rectangle,</li>
				</list>
				<p>then it is a surprisingly inexpensive task to determine, 
					if the two main rectangles can be joined to a polygon with a common area 
					(the overlaid subrectangles),
					such eliminating the space for one of the two subrectangles.</p>
				<p>This article</p>
				<list>
					<li>derives a boolean equation to find the answer to above question in 7 boolean operations;</li>
	    			<li>presents an algorithm suitable for implementation into computer programs, 
	    				at a cost of just 1 boolean operation and a comparison.</li>
				</list>
				<p>The discussion involves knowledge of <em>Karnaugh maps</em> (a special kind of decision tables). 
					If you want to understand the technique and not just get the result, 
					and if you are unfamiliar with Karnaugh maps, then it is suggested that you first 
					follow the links given in the section <em>Further Reading</em> to the left.</p>
			</body>
		</chapter>

		<chapter>
			<heading id="A2">Problem Description</heading>
			<body>
				<p>Assume you have two identical subrectangles, each within a distinct main rectangle. 
					Identical means, that the two subrectangles have identical content and identical dimensions. 
					The horizontal and vertical offsets may be anywhere within the 
					corresponding main rectangles and do not need to be identical as well.</p>

				<multiimg orientation="horizontal" float="right" width="360">
					<img>
						<url>/img/dor_fig1a.gif</url>
						<alt>Subrectangle at bottom right</alt>
						<caption>Fig. 1a: The sub- rectangle comprises its main rectangle's edges 
							at the bottom and to the right</caption></img>
					<img>
						<url>/img/dor_fig1b.gif</url>
						<alt>Subrectangle at top left</alt>
						<caption>Fig. 1b: The sub- rectangle comprises its main rectangle's edges 
							at the top and to the left</caption></img>
					<img>
						<url>/img/dor_fig2.gif</url>
						<alt>Polygon sharing the identical rectangles</alt>
						<caption>Fig. 2: Polygon sharing the identical rectangles</caption></img>
				
				</multiimg>
				<p>Let's visualize the problem with an example. 
					We have a yellow rectangle with red outlines along its edges, 
					and we have a cyan rectangle with blue outlines. 
					They both share an identical subrectangle, shown in magenta.</p>
				<p>In fig. 1 it is obvious, that the identical subrecatangles of the two main rectangles 
					can be overlapped to form a polygon as shown in fig.2.</p>

				<floatclear/>

				
				<multiimg orientation="horizontal" float="right" width="360">
					<img>
						<url>/img/dor_fig3a.gif</url>
						<alt>Subrectangle at bottom right</alt>
						<caption>Fig. 3a: The subrectangle comprises its main rectangle's 
							edges at the bottom and to the right</caption></img>
					<img>
						<url>/img/dor_fig3b.gif</url>
						<alt>Subrectangle at top right</alt>
						<caption>Fig. 3b: The subrectangle comprises its main rectangle's 
							edges at the top and to the right</caption></img>
					<img>
						<url>/img/dor_fig4.gif</url>
						<alt>No possibility to merge the two rectangles into a polygon</alt>
						<caption>Fig. 4: No possibility to merge the two rectangles into a polygon</caption></img>
				
				</multiimg>
				<p>It also should be obvious, that the two main rectangles in fig. 3 can <em>not</em> be merged 
					into a polygon with a shared area (fig. 4).</p>
				<p>The problem is, that the yellow and cyan areas are not identical 
					(the areas marked with the double-ended arrow), and therefore must be kept apart. 
					(If these areas were identical, they should have been included in their magenta subrectangles.)</p>
				<p>You might say: "So, what's the deal? Simply fuse all those rectangles having two opposite corners, 
					and done."</p>
				<p>Unfortunately things are more complicated. It turns out, that there are quite many combinations, 
					of which some are not as obvious as the ones just shown. Quite the opposite, actually.
					This will be 
					<link loc="wiki">
						<url>http://en.wikipedia.org/wiki/Proof_by_exhaustion</url>
						<text>proven by exhaustion</text>
					</link>.</p>
				<p>Let's dive into the details, after definining some terminology.</p>
			</body>
		</chapter>
	</part>

	<part>
		<heading id="B">Analysis</heading>
		<chapter>
			<heading id="B1">Used Terminology</heading>
			<body>
				<multiimg orientation="vertical" float="right" width="120">
					<img>
						<url>/img/dor_fig5.gif</url>
						<alt>Naming edges</alt>
						<caption>Fig. 5: Naming edges</caption></img>
					<img>
						<url>/img/dor_fig6.gif</url>
						<alt>Ordering edges</alt>
						<caption>Fig. 6: Ordering edges</caption></img>
				</multiimg>
				<p>When we refer to the edges of a rectangle, we will call them 
					<em>Right</em>, <em>Bottom</em>, <em>Top</em>, and <em>Left</em>, 
					and abbreviate them with R, B, T, and L, resp. (fig. 5)</p>
				<p>An edge <em>order</em> is important. Not a particular order, as the one shown in fig. 6,
					but any determined order. In your particular project you might want to choose 
					a clockwise or counterclockwise direction. 
					In this article, however, whenever we are going to compare two rectangles, 
					we always will use the shown order RBTL for both rectangles, 
					from left to right in exactly this way.</p>			
			</body>
		</chapter>
		<chapter>
			<heading id="B2">Quantification</heading>
			<body>
				<p>Subrectangles can appear in virtually every position within a main rectangle, 
					comprising none or some or all edges of the parental main rectangle:</p>
				<multiimg orientation="horizontal" float="left" width="360">
					<img>
						<url>/img/dor_a0000.gif</url>
						<alt>No edges</alt>
						<caption>Fig. 7a:<br/>No edges</caption></img>
					<img>
						<url>/img/dor_a0001.gif</url>
						<alt>1 edge</alt>
						<caption>Fig. 7b:<br/>1 edge</caption></img>
					<img>
						<url>/img/dor_a0011.gif</url>
						<alt>2 edges</alt>
						<caption>Fig. 7c:<br/>2 edges (corner)</caption></img>
					<img>
						<url>/img/dor_a0110.gif</url>
						<alt>2 edges</alt>
						<caption>Fig. 7d:<br/>2 edges (strip)</caption></img>
					<img>
						<url>/img/dor_a0111.gif</url>
						<alt>3 edges</alt>
						<caption>Fig. 7e:<br/>3 edges</caption></img>
					<img>
						<url>/img/dor_a1111.gif</url>
						<alt>3 edges</alt>
						<caption>Fig. 7f:<br/>4 edges</caption></img>
				</multiimg>
				<p>Because there are 4 edges in a rectangle, 
					of which each can either be included or not included in the subrectangle, 
					we have a total of <formula>2<sub>4</sub>=16</formula> combinations 
					in which a subrectangle can be arranged with respect to these edges. 
					This includes also "no edges" and "all edges".</p>
				<p>Fig. 7 shows all base types of these combinations; the others are obtained 
					by rotations. However, because we compare two rectangle/subrectangle-combinations with each other, 
					we even will have to deal with <formula>(2<sup>4</sup>)<sup>2</sup>=256</formula> 
					individual cases.</p>
			</body>
		</chapter>

		<chapter>
			<heading id="B3">The Need for Completeness</heading>
			<body>
				<multiimg orientation="horizontal" float="right" width="240">
					<img>
						<url>/img/dor_a0011.gif</url>
						<alt>0°</alt>
						<caption>Fig. 8a:<br/>0°</caption></img>
					<img>
						<url>/img/dor_a1010.gif</url>
						<alt>90°</alt>
						<caption>Fig. 8b:<br/>90°</caption></img>
					<img>
						<url>/img/dor_a1100.gif</url>
						<alt>180°</alt>
						<caption>Fig. 8c:<br/>180°</caption></img>
					<img>
						<url>/img/dor_a0101.gif</url>
						<alt>270°</alt>
						<caption>Fig. 8d:<br/>270°</caption></img>
				</multiimg>
				<p>Let's have a closer look at these 256 cases. 
					It is obvious, that many of the rectangle/subrectangle-combinations 
					do include rotations (fig. 8).
					This observation might tempt us to save some time
					by reducing the set of 256 combinations so, that we find general cases 
					which include all possible rotations. 
					<note ref="1">
						<p>Of course, a rotation on a real rectangle/subrectangle-combination
							containing real data would manipulate the subrectangle's appearance such,
							that it would no longer be identical with the other rectangle's subrectangle.
							However, the 
idea would account for this by assuming that the subrectangle
							itself would not be rotated in any way.</p>
					</note>
					The same is also true for reflections, as they can easily be reduced to rotations.
					</p>
				<p>However, to derive the final formula by means of a Karnaugh map, we will need
					to exhaustively consider all possible cases, i.e., looking at all polygons
					generatable by the 2×16 inputs.
					<note ref="2">
						<p><em>Inputs</em> are those 2 out of the 16 edge combinations which are involved.
							<em>Polygons</em> are closed planar paths composed of a finite number 
							of sequential line segments. In our case the polygons have internal angles 
							being a multiple of 90°, so we more precisely should call them 
							"orthogonal polygons".</p>
					</note>
				</p>
			</body>
		</chapter>

		<chapter>
			<heading id="B4">All Cases</heading>
			<body>
				<p>To represent all cases we use a table. The inputs are given as row and column headers.
					In the table, the rows represent the input for the first main rectangle. 
					The first main rectangle is colored in cyan, and outlined in blue. 
					Its subrectangle is colored blue. - 
					Likewise do the columns represent the input for the second main rectangle, 
					colored in yellow and outlined in red. Its subrectangle is colored red.</p>
				<p>Note, that the rows and columns are labeled in the order defined above, 
					see fig. 6. If an edge is not involved, i.e. if a subrectangle 
					does not include that particular main rectangle's edge, 
					then this is marked with a "-" at the appropriate position. - 
					Also note, that the sequence in which the input rows and input columns appear 
					is not arbitrary: the reason for this order has to do with the <em>Gray Code</em> 
					and is explained below.</p>
				<p>For each combination of the two input rectangles a resulting polygon is given, 
					leaving the input colors unchanged with the exception of the subrectangular area 
					which is shared by both input rectangles. This shared area is colored magenta.</p>
				<p>In the table's cells, the size or shape of the input boxes 
					may be modified to keep things somewhat space-efficient. 
					However, keep in mind, that a magenta rectangle represents both 
					the row header's blue rectangle as well as the column header's red rectangle. 
					Likewise do the cyan and yellow areas within a cell correspond 
					exactly to the cyan and yellow areas of that cell's row and column headers.</p>
				<p>Let's have a look at the table now.</p>


			    <table>
			        <row>
			            <emptycol cols="2"/>
			            <col><code>----</code></col>
			            <col><code>---L</code></col>
			            <col><code>--TL</code></col>
			            <col><code>--T-</code></col>
			
			            <col><code>-BT-</code></col>
			            <col><code>-BTL</code></col>
			            <col><code>-B-L</code></col>
			            <col><code>-B--</code></col>
			            <col><code>RB--</code></col>
			            <col><code>RB-L</code></col>
			
			            <col><code>RBTL</code></col>
			            <col><code>RBT-</code></col>
			            <col><code>R-T-</code></col>
			            <col><code>R-TL</code></col>
			            <col><code>R--L</code></col>
			            <col><code>R---</code></col>
			
			        </row>
			        <row>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_b0000.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b0001.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b0011.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b0010.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b0110.gif</url><alt>Input</alt></img></col>
			
			            <col><img><url>/img/dor_b0111.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b0101.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b0100.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b1100.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b1101.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b1111.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b1110.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b1010.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b1011.gif</url><alt>Input</alt></img></col>
			
			            <col><img><url>/img/dor_b1001.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_b1000.gif</url><alt>Input</alt></img></col>
			        </row>
			        <row>
			            <col><code>----</code></col>
			            <col><img><url>/img/dor_a0000.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="10"/>
			            <col><img><url>/img/dor_00001111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="5"/>
			        </row>
			        <row>
			            <col><code>---L</code></col>
			
			            <col><img><url>/img/dor_a0001.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="10"/>
			            <col><img><url>/img/dor_00011111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_00011110.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="4"/>
			        </row>
			
			        <row>
			            <col><code>--TL</code></col>
			            <col><img><url>/img/dor_a0011.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="8"/>
			            <col><img><url>/img/dor_00111100.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_00111101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_00111111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_00111110.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="4"/>
			        </row>
			        <row>
			            <col><code>--T-</code></col>
			            <col><img><url>/img/dor_a0010.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="9"/>
			            <col><img><url>/img/dor_00101101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_00101111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="5"/>
			        </row>
			        <row>
			            <col><code>-BT-</code></col>
			
			            <col><img><url>/img/dor_a0110.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="9"/>
			            <col><img><url>/img/dor_01101101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01101111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_01101011.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01101001.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="1"/>
			        </row>
			
			        <row>
			            <col><code>-BTL</code></col>
			            <col><img><url>/img/dor_a0111.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="8"/>
			            <col><img><url>/img/dor_01111100.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01111101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01111111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01111110.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01111010.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01111011.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01111001.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01111000.gif</url><alt>Polygon</alt></img></col>
			        </row>
			        <row>
			            <col><code>-B-L</code></col>
			            <col><img><url>/img/dor_a0101.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="10"/>
			            <col><img><url>/img/dor_01011111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01011110.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01011010.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_01011011.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			            <col><code>-B--</code></col>
			
			            <col><img><url>/img/dor_a0100.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="10"/>
			            <col><img><url>/img/dor_01001111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_01001011.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			        </row>
			
			        <row>
			            <col><code>RB--</code></col>
			            <col><img><url>/img/dor_a1100.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_11000011.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_11000111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="4"/>
			            <col><img><url>/img/dor_11001111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_11001011.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			            <col><code>RB-L</code></col>
			            <col><img><url>/img/dor_a1101.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_11010011.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11010010.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11010110.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11010111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="4"/>
			            <col><img><url>/img/dor_11011111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11011110.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11011010.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11011011.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			            <col><code>RBTL</code></col>
			
			            <col><img><url>/img/dor_a1111.gif</url><alt>Input</alt></img></col>
			            <col><img><url>/img/dor_11110000.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11110001.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11110011.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11110010.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11110110.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11110111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11110101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11110100.gif</url><alt>Polygon</alt></img></col>
			
			            <col><img><url>/img/dor_11111100.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11111101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11111111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11111110.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11111010.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11111011.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11111001.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11111000.gif</url><alt>Polygon</alt></img></col>
			        </row>
			
			        <row>
			            <col><code>RBT-</code></col>
			            <col><img><url>/img/dor_a1110.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="1"/>
			            <col><img><url>/img/dor_11100001.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11100011.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_11100111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11100101.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_11101101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11101111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_11101011.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_11101001.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="1"/>
			        </row>
			        <row>
			            <col><code>R-T-</code></col>
			            <col><img><url>/img/dor_a1010.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="5"/>
			            <col><img><url>/img/dor_10100111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10100101.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="2"/>
			            <col><img><url>/img/dor_10101101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10101111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="5"/>
			        </row>
			        <row>
			            <col><code>R-TL</code></col>
			
			            <col><img><url>/img/dor_a1011.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="4"/>
			            <col><img><url>/img/dor_10110110.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10110111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10110101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10110100.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10111100.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10111101.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10111111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10111110.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="4"/>
			        </row>
			
			        <row>
			            <col><code>R--L</code></col>
			            <col><img><url>/img/dor_a1001.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="4"/>
			            <col><img><url>/img/dor_10010110.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10010111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="4"/>
			            <col><img><url>/img/dor_10011111.gif</url><alt>Polygon</alt></img></col>
			            <col><img><url>/img/dor_10011110.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="4"/>
			        </row>
			        <row>
			            <col><code>R---</code></col>
			            <col><img><url>/img/dor_a1000.gif</url><alt>Input</alt></img></col>
			            <emptycol cols="5"/>
			            <col><img><url>/img/dor_10000111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="4"/>
			            <col><img><url>/img/dor_10001111.gif</url><alt>Polygon</alt></img></col>
			            <emptycol cols="5"/>
			        </row>
			        <caption>Table 1: All possible overlaps.</caption>
			    </table>
				<p>All cells displaying no entry have two inputs 
					which can not be merged to a single polygon with a shared area.</p>
			</body>
		</chapter>

		<chapter>
			<heading id="B5">Karnaugh Map</heading>
			<body>
				<p>Now table 1 is converted into an equivalent Karnaugh Map. 
					The Karnaugh map essentially is a table exactly like the one in fig. 1, 
					only that it consists completely of binary information.</p>
				<p>In a Karnaugh map, we work with results of functions, 
					not with graphics, and these results are expressed in binary from as follows: 
					each cell will be marked with <code>1</code> where a polygon resulted in table 1, 
					and <code>0</code> otherwise. 
					However, for better legibility, 
					we omit the zeroes within the result cells and leave them blank: 
					this way, the human eye is better able to catch patterns.
					<note ref="3">
						<p>Those readers famliar with Karnaugh maps should notice, 
						that a blank cell does not imply "Don't care".</p>
					</note>
					</p>
				<p>Similarly, the <em>input</em> as well must be coded such, 
					that we can represent the different input values as a binary variable, 
					each containing a <em>0</em> or <code>1</code>. 
					We already coded the row and column headers binary, though: 
					either a particular edge was present, and then was marked with its initial letter 
					(for example with <code>T</code> for the top edge), 
					or it was not present and then marked with a <code>-</code> symbol. 
					Therefore our task is reduced to replace any letter by ones 
					and the <code>-</code> with zeroes (and this time we better do not omit the zeroes). - 
					Each of these binary digits defines a variable, 
					namely a particular edge within the rectangle. 
					Hence we in total have 2×4 variables (4 edges for each of the two input rectangles): 
					4 variables head each row, and the other 4 each column.</p>

			    <table>
			        <row>
			            <emptycol cols="1"/>
			            <col><code>0000</code></col>
			            <col><code>0001</code></col>
			            <col><code>0011</code></col>
			            <col><code>0010</code></col>
			            <col><code>0110</code></col>
			            <col><code>0111</code></col>
			            <col><code>0101</code></col>
			            <col><code>0100</code></col>
			            <col><code>1100</code></col>
			            <col><code>1101</code></col>
			            <col><code>1111</code></col>
			            <col><code>1110</code></col>
			            <col><code>1010</code></col>
			            <col><code>1011</code></col>
			            <col><code>1001</code></col>
			            <col><code>1000</code></col>
			        </row>
			        <row>
			            <col><code>0000</code></col>
			            <emptycol cols="10"/>
			            <col><code>1</code></col>
			            <emptycol cols="5"/>
			        </row>
			        <row>
			            <col><code>0001</code></col>
			            <emptycol cols="10"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			        </row>
			        <row>
			            <col><code>0011</code></col>
			            <emptycol cols="8"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			        </row>
			        <row>
			            <col><code>0010</code></col>
			            <emptycol cols="9"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="5"/>
			        </row>
			        <row>
			            <col><code>0110</code></col>
			            <emptycol cols="9"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="1"/>
			        </row>
			        <row>
			            <col><code>0111</code></col>
			            <emptycol cols="8"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			        </row>
			        <row>
			            <col><code>0101</code></col>
			            <emptycol cols="10"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			            <col><code>0100</code></col>
			            <emptycol cols="10"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			            <col><code>1100</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			
			            <col><code>1101</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			            <col><code>1111</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			        </row>
			        <row>
			            <col><code>1110</code></col>
			            <emptycol cols="1"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="1"/>
			        </row>
			        <row>
			            <col><code>1010</code></col>
			            <emptycol cols="5"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="5"/>
			        </row>
			        <row>
			            <col><code>1011</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			        </row>
			        <row>
			            <col><code>1001</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			        </row>
			        <row>
			
			            <col><code>1000</code></col>
			            <emptycol cols="5"/>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <emptycol cols="5"/>
			        </row>
			        <caption>Table 2: Karnaugh map with the same information.</caption>
			    </table>
				<p>It became apparent now that the rows and columns indeed are 
					by no means ordered as a binary sequence. 
					Howere, there <em>is</em> an order: 
					it follows the so-called 
					<link loc="wiki">
						<url>http://en.wikipedia.org/wiki/Gray_code</url>
						<text>Gray code</text>
					</link>, a sequence which has the desired property, 
					that each subsequent element changes a bit in just <em>one single position</em>.</p>
				<p>Contrast this with "traditional" binary counting: 
					the transition from e.g. decimal 7 to 8 
					(binary <code>0111</code> to <code>1000</code>) 
					causes 4 bits to change at once. 
					Not so in a Gray sequence: you can easily verify in table 2, 
					that each element's successor changes in just 1 bit. 
					This property is required in Karnaugh maps.</p>
			</body>
		</chapter>

		<chapter>
			<heading id="B6">Variable Naming</heading>
			<body>
				<p>Recall, that each position of the digits in the row and column headings
					represent a variable 
					(<code>R</code>, <code>B</code>, <code>T</code>, <code>L</code> as per fig. 6)</p>
				<p>We will need to refer to our variables in the following sections. 
					Because it would be quite cumbersome to always refer to 
					"the <code>T</code> (or the 3rd digit) of the 2nd rectangle" all the time, 
					we are going to introduce a shorter notation now.</p>
				<p>We redefine the digits in an unambigeous way and set 
					<highlight color="cyan"><code>A</code></highlight> for the leftmost digit (the <code>R</code> edge) 
					of the <highlight color="cyan">first input rectangle</highlight>, and subsequently 
					<highlight color="cyan"><code>B</code></highlight> for its <code>B</code> edge, 
					<highlight color="cyan"><code>C</code></highlight> for <code>T</code>, and 
					<highlight color="cyan"><code>D</code></highlight> for <code>L</code>. 
					Similarly, we rename the edges of the <highlight>second input rectangle</highlight> to 
					<highlight><code>E</code></highlight>, 
					<highlight><code>F</code></highlight>, 
					<highlight><code>G</code></highlight> and 
					<highlight><code>H</code></highlight>.</p>
				<p>Now, if we reserve 4 rows and 4 columns to represent 
					each of the 2×4 variables 
					<highlight color="cyan"><code>A</code></highlight> to 
					<highlight color="cyan"><code>D</code></highlight> and 
					<highlight><code>E</code></highlight> to 
					<highlight><code>H</code></highlight>, omitting the zeroes, 
					the pattern of the Gray code will become apparent immediately.</p>
				<p>The header rows and header columns in which no entry appears is to be read 
					"variable is not set", i.e. <code>0</code>. 
					When such an entry appears, e.g. <highlight><code>H</code></highlight>, 
					then this variable has an input value of <code>1</code>.</p>
				<p>In Karnaugh maps, it is common practice to display 
					half of the 
					<highlight color="cyan">row variables</highlight>
					to the left
					and the other to the right of the table, 
					and in analogy each half of the 
					<highlight>column variables</highlight> 
					above and below the table.</p>

			    <table>
			        <row>
			            <emptycol cols="2"/>
			            <emptycol cols="4" highlight="yellow"/>
			            <col><code><highlight><code>F</code></highlight></code></col>
			            <col><code><highlight><code>F</code></highlight></code></col>
			            <col><code><highlight><code>F</code></highlight></code></col>
			            <col><code><highlight><code>F</code></highlight></code></col>
			            <col><code><highlight><code>F</code></highlight></code></col>
			            <col><code><highlight><code>F</code></highlight></code></col>
			            <col><code><highlight><code>F</code></highlight></code></col>
			            <col><code><highlight><code>F</code></highlight></code></col>
			            <emptycol cols="4" highlight="yellow"/>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			            <emptycol cols="2"/>
			            <emptycol highlight="yellow"/>
			            <col><code><highlight><code>H</code></highlight></code></col>
			            <col><code><highlight><code>H</code></highlight></code></col>
			            <emptycol cols="2" highlight="yellow"/>
			            <col><code><highlight><code>H</code></highlight></code></col>
			            <col><code><highlight><code>H</code></highlight></code></col>
			            <emptycol cols="2" highlight="yellow"/>
			            <col><code><highlight><code>H</code></highlight></code></col>
			            <col><code><highlight><code>H</code></highlight></code></col>
			            <emptycol cols="2" highlight="yellow"/>
			            <col><code><highlight><code>H</code></highlight></code></col>
			            <col><code><highlight><code>H</code></highlight></code></col>
			            <emptycol highlight="yellow"/>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			            <emptycol cols="2" highlight="cyan"/>
			            <emptycol cols="10"/>
			            <col><code>1</code></col>
			            <emptycol cols="5"/>
			            <emptycol cols="2" highlight="cyan"/>
			        </row>
			        <row>
			            <emptycol highlight="cyan"/>
			            <col><code><highlight color="cyan"><code>D</code></highlight></code></col>
			            <emptycol cols="10"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <emptycol cols="2" highlight="cyan"/>
			        </row>
			        <row>
			            <emptycol highlight="cyan"/>
			            <col><code><highlight color="cyan"><code>D</code></highlight></code></col>
			            <emptycol cols="8"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code><highlight color="cyan"><code>C</code></highlight></code></col>
			            <emptycol highlight="cyan"/>
			        </row>
			        <row>
			            <emptycol cols="2" highlight="cyan"/>
			            <emptycol cols="9"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="5"/>
			            <col><code><highlight color="cyan"><code>C</code></highlight></code></col>
			            <emptycol highlight="cyan"/>
			        </row>
			        <row>
			            <col><code><highlight color="cyan"><code>B</code></highlight></code></col>
			            <emptycol highlight="cyan"/>
			            <emptycol cols="9"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="1"/>
			            <col><code><highlight color="cyan"><code>C</code></highlight></code></col>
			            <emptycol highlight="cyan"/>
			        </row>
			        <row>
			            <col><code><highlight color="cyan"><code>B</code></highlight></code></col>
			            <col><code><highlight color="cyan"><code>D</code></highlight></code></col>
			            <emptycol cols="8"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code><highlight color="cyan"><code>C</code></highlight></code></col>
			            <emptycol highlight="cyan"/>
			        </row>
			        <row>
			            <col><code><highlight color="cyan"><code>B</code></highlight></code></col>
			            <col><code><highlight color="cyan"><code>D</code></highlight></code></col>
			            <emptycol cols="10"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <emptycol cols="2" highlight="cyan"/>
			        </row>
			        <row>
			            <col><code><highlight color="cyan"><code>B</code></highlight></code></col>
			            <emptycol highlight="cyan"/>
			            <emptycol cols="10"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <emptycol cols="2" highlight="cyan"/>
			        </row>
			        <row>
			            <col><code><highlight color="cyan"><code>B</code></highlight></code></col>
			            <emptycol highlight="cyan"/>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <emptycol highlight="cyan"/>
			            <col><code><highlight color="cyan"><code>A</code></highlight></code></col>
			        </row>
			        <row>
			            <col><code><highlight color="cyan"><code>B</code></highlight></code></col>
			            <col><code><highlight color="cyan"><code>D</code></highlight></code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <emptycol highlight="cyan"/>
			            <col><code><highlight color="cyan"><code>A</code></highlight></code></col>
			        </row>
			        <row>
			            <col><code><highlight color="cyan"><code>B</code></highlight></code></col>
			            <col><code><highlight color="cyan"><code>D</code></highlight></code></col>
			            <col><code>1</code></col>
			
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code><highlight color="cyan"><code>C</code></highlight></code></col>
			            <col><code><highlight color="cyan"><code>A</code></highlight></code></col>
			        </row>
			        <row>
			            <col><code><highlight color="cyan"><code>B</code></highlight></code></col>
			            <emptycol highlight="cyan"/>
			            <emptycol/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol/>
			            <col><code><highlight color="cyan"><code>C</code></highlight></code></col>
			            <col><code><highlight color="cyan"><code>A</code></highlight></code></col>
			        </row>
			        <row>
			            <emptycol cols="2" highlight="cyan"/>
			            <emptycol cols="5"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="2"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="5"/>
			            <col><code><highlight color="cyan"><code>C</code></highlight></code></col>
			            <col><code><highlight color="cyan"><code>A</code></highlight></code></col>
			        </row>
			        <row>
			            <emptycol highlight="cyan"/>
			            <col><code><highlight color="cyan"><code>D</code></highlight></code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code><highlight color="cyan"><code>C</code></highlight></code></col>
			            <col><code><highlight color="cyan"><code>A</code></highlight></code></col>
			        </row>
			        <row>
			            <emptycol highlight="cyan"/>
			            <col><code><highlight color="cyan"><code>D</code></highlight></code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <emptycol highlight="cyan"/>
			            <col><code><highlight color="cyan"><code>A</code></highlight></code></col>
			        </row>
			        <row>
			            <emptycol cols="2" highlight="cyan"/>
			            <emptycol cols="5"/>
			            <col><code>1</code></col>
			            <emptycol cols="4"/>
			            <col><code>1</code></col>
			            <emptycol cols="5"/>
			            <emptycol  highlight="cyan"/>
			            <col><code><highlight color="cyan"><code>A</code></highlight></code></col>
			        </row>
			        <row>
			            <emptycol cols="2"/>
			            <emptycol cols="2" highlight="yellow"/>
			            <col><code><highlight><code>G</code></highlight></code></col>
			            <col><code><highlight><code>G</code></highlight></code></col>
			            <col><code><highlight><code>G</code></highlight></code></col>
			            <col><code><highlight><code>G</code></highlight></code></col>
			            <emptycol cols="4" highlight="yellow"/>
			            <col><code><highlight><code>G</code></highlight></code></col>
			            <col><code><highlight><code>G</code></highlight></code></col>
			            <col><code><highlight><code>G</code></highlight></code></col>
			            <col><code><highlight><code>G</code></highlight></code></col>
			            <emptycol cols="2" highlight="yellow"/>
			            <emptycol cols="2"/>
			        </row>
			        <row>
			            <emptycol cols="2"/>
			            <emptycol cols="8" highlight="yellow"/>
			            <col><code><highlight><code>E</code></highlight></code></col>
			            <col><code><highlight><code>E</code></highlight></code></col>
			            <col><code><highlight><code>E</code></highlight></code></col>
			            <col><code><highlight><code>E</code></highlight></code></col>
			            <col><code><highlight><code>E</code></highlight></code></col>
			            <col><code><highlight><code>E</code></highlight></code></col>
			            <col><code><highlight><code>E</code></highlight></code></col>
			            <col><code><highlight><code>E</code></highlight></code></col>
			            <emptycol cols="2"/>
			        </row>
			        <caption>Table 3: Karnaugh map with proper variable names.</caption>
			    </table>				
			</body>
		</chapter>

		<chapter>
			<heading id="B7">Prime Implicants</heading>
			<body>
				<p>Our first task is to identify the minterms
				to use in the final expression. 
				(Find out more about 
				<link loc="wiki">
					<url>http://en.wikipedia.org/wiki/Canonical_form_%28Boolean_algebra%29</url>
					<text>minterms</text>
				</link> and 
				<link loc="wiki">
					<url>http://en.wikipedia.org/wiki/Implicant</url>
					<text>prime implicants</text>
				</link>)</p>
				<p>Note, that we use the following notation for Boolean operations:</p>
				<table>
					<row>
						<col>Symbol</col>
						<col>Operation</col>
					</row>
					<row>
						<col>×</col>
						<col><code>AND</code></col>
					</row>
					<row>
						<col>+</col>
						<col><code>OR</code></col>
					</row>
					<caption>Table 4: Notation for Boolean operators</caption>
				</table>
				<p>(The symbol × is omitted when between terms to be <code>AND</code>ed,
					 much like the arithmetic multiplication sign between variables; 
					 e.g. <code>ABCD</code> means <code>A×B×C×D</code>.)</p>
				
				<p>16 prime implicants can be found; they are given in table 5.</p>
			    <table>
			        <row>
			            <col>Prime-1-block</col>
			
			            <col>Prime Implicant</col>
			            <col>Cost</col>
			        </row>
			        <row>
			            <col><code>1-1-1-1-</code></col>
			            <col><code>ABCD</code></col>
			            <col>3</col>
			
			        </row>
			        <row>
			            <col><code>1-1-1--1</code></col>
			            <col><code>ABCH</code></col>
			            <col>3</col>
			        </row>
			        <row>
			
			            <col><code>1-1--11-</code></col>
			            <col><code>ABGD</code></col>
			            <col>3</col>
			        </row>
			        <row>
			            <col><code>1-1--1-1</code></col>
			            <col><code>ABGH</code></col>
			            <col>3</col>
			        </row>
			        <row>
			            <col><code>1--11-1-</code></col>
			            <col><code>AFCD</code></col>
			            <col>3</col>
			        </row>
			
			        <row>
			            <col><code>1--11--1</code></col>
			            <col><code>AFCH</code></col>
			            <col>3</col>
			        </row>
			        <row>
			            <col><code>1--1-11-</code></col>
			
			            <col><code>AFGD</code></col>
			            <col>3</col>
			        </row>
			        <row>
			            <col><code>1--1-1-1</code></col>
			            <col><code>AFGH</code></col>
			            <col>3</col>
			        </row>
			        <row>
			            <col><code>-11-1-1-</code></col>
			            <col><code>EBCD</code></col>
			            <col>3</col>
			        </row>
			        <row>
			
			            <col><code>-11-1--1</code></col>
			            <col><code>EBCH</code></col>
			            <col>3</col>
			        </row>
			        <row>
			            <col><code>-11--11-</code></col>
			            <col><code>EBGD</code></col>
			            <col>3</col>
			        </row>
			        <row>
			            <col><code>-11--1-1</code></col>
			            <col><code>EBGH</code></col>
			            <col>3</col>
			        </row>
			
			        <row>
			            <col><code>-1-11-1-</code></col>
			            <col><code>EFCD</code></col>
			            <col>3</col>
			        </row>
			        <row>
			            <col><code>-1-11--1</code></col>
			
			            <col><code>EFCH</code></col>
			            <col>3</col>
			        </row>
			        <row>
			            <col><code>-1-1-11-</code></col>
			            <col><code>EFGD</code></col>
			            <col>3</col>
			
			        </row>
			        <row>
			            <col><code>-1-1-1-1</code></col>
			            <col><code>EFGH</code></col>
			            <col>3</col>
			        </row>
			        <caption>Table 5: Found prime implicants.</caption>
			    </table>
				<p><em>Cost</em> is the number of involved boolean operations. 
					All found prime implicants require 3 <code>AND</code> operations. 
					E.g. for the first prime implicant: <code>A AND B AND C AND D</code>.</p>
				<p>All terms are essentials, hence our first equation reads:</p>
				<p><code>X=ABCD+ABCH+ABGD+ABGH+AFCD+AFCH+AFGD+AFGH+EBCD+EBCH+EBGD+EBGH+EFCD+EFCH+EFGD+EFGH</code></p>
				<p>The total cost for <code>X</code> therefore is: 
					16×3 <code>AND</code>s + 15 <code>OR</code>s = 63 boolean operations.</p>
			</body>
		</chapter>

		<chapter>
			<heading id="B8">Simplification and Result</heading>
			<body>
				<p>Some algebra will simplify this term. 
					We don't even need to apply any "specials" of Boolean algebra.</p>
				<p>This is the found equation which we want to simplify:</p>
				<p><code>X=ABCD+ABCH+ABGD+ABGH+AFCD+AFCH+AFGD+AFGH+EBCD+EBCH+EBGD+EBGH+EFCD+EFCH+EFGD+EFGH</code></p>
				<p>Factoring out the first two products of each term in above equation:</p>
				<p><code>X=AB(CD+CH+GD+GH)+AF(CD+CH+GD+GH)+EB(CD+CH+GD+GH)+EF(CD+CH+GD+GH)</code></p>
				<p>The terms in the 4 parantheses are identical, hence we have a binomial:</p>
				<p><code>X=(AB+AF+EB+EF)(CD+CH+GD+GH)</code></p>
				<p>Within the 2 parantheses we factor out their first factors:</p>
				<p><code>X=( A(B+F)+E(B+F) )( C(D+H)+G(D+H) )</code></p>
				<p>The inner two parantheses within each outer parathesis are identical, 
					forming binomials once again:</p>
				<p><code>X=( (A+E)(B+F) )( (C+G)(D+H) )</code></p>
				<p>The outer parantheses can be removed, and the final equation reads:</p>
				<p><code>X=(A+E)(B+F)(C+G)(D+H)</code></p>
				<p>Total cost: 4 <code>OR</code>s and 3 <code>AND</code>s</p>
			</body>
		</chapter>

		<chapter>
			<heading id="B9">Verification</heading>
			<body>
				<p>Let's see if our equation holds. 
					A worksheet table is quickly set up to generate a truth table for the 256 possible values. 
					For easy access to the variables from the table body's cells, 
					<code>A</code> to <code>D</code> are written into separate columns, 
					and <code>E</code> to <code>H</code> into separate rows.</p>
				<p>E.g. for <em>MS Excel</em> 
					(<link loc="int">
						<url>/files/detect_overlapping_rectangles.xlsx</url>
						<text>download</text>
					</link>): 
					Assuming that your table starts in cell <code>A1</code>, 
					duplicate the first 6 rows and the first 5 columns as seen below.
					Then the table's body starts in cell <code>F7</code>. 
					Enter this formula into cell <code>F7</code>:</p>
				<p><code>=IF(AND(OR($B7;F$2);OR($C7;F$3);OR($D7;F$4);OR($E7;F$5));"1";"")</code></p>
				<p>Copy it to all 256 cells of the cell body (i.e. a 16 × 16 grid from there).
				</p>
				<p>These are the values you get.</p>
				<table>
					<row><col>Cell A1</col><emptycol cols="3"/><col>EFGH</col><col>0000</col><col>0001</col><col>0011</col><col>0010</col><col>0110</col><col>0111</col><col>0101</col><col>0100</col><col>1100</col><col>1101</col><col>1111</col><col>1110</col><col>1010</col><col>1011</col><col>1001</col><col>1000
</col></row>
					<row><emptycol cols="4"/><col>E </col><col>0</col><col>0</col><col>0</col><col>0</col><col>0</col><col>0</col><col>0</col><col>0</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col></row>
					<row><emptycol cols="4"/><col>F </col><col>0</col><col>0</col><col>0</col><col>0</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>0</col><col>0</col><col>0</col><col>0</col></row>
					<row><emptycol cols="4"/><col>G </col><col>0</col><col>0</col><col>1</col><col>1</col><col>1</col><col>1</col><col>0</col><col>0</col><col>0</col><col>0</col><col>1</col><col>1</col><col>1</col><col>1</col><col>0</col><col>0</col></row>
					<row><emptycol cols="4"/><col>H </col><col>0</col><col>1</col><col>1</col><col>0</col><col>0</col><col>1</col><col>1</col><col>0</col><col>0</col><col>1</col><col>1</col><col>0</col><col>0</col><col>1</col><col>1</col><col>0</col></row>
					<row><col>ABCD</col><col>A </col><col>B </col><col>C </col><col>D </col><emptycol cols="8"/><emptycol cols="8"/></row>
					<row><col>0000</col><col>0</col><col>0</col><col>0</col><col>0</col><emptycol cols="10"/><col>1</col><emptycol cols="5"/></row>
					<row><col>0001</col><col>0</col><col>0</col><col>0</col><col>1</col><emptycol cols="10"/><col>1</col><col>1</col><emptycol cols="4"/></row>
					<row><col>0011</col><col>0</col><col>0</col><col>1</col><col>1</col><emptycol cols="8"/><col>1</col><col>1</col><col>1</col><col>1</col><emptycol cols="4"/></row>
					<row><col>0010</col><col>0</col><col>0</col><col>1</col><col>0</col><emptycol cols="9"/><col>1</col><col>1</col><emptycol cols="5"/></row>
					<row><col>0110</col><col>0</col><col>1</col><col>1</col><col>0</col><emptycol cols="9"/><col>1</col><col>1</col><emptycol cols="2"/><col>1</col><col>1</col><emptycol cols="1"/></row>
					<row><col>0111</col><col>0</col><col>1</col><col>1</col><col>1</col><emptycol cols="8"/><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col></row>
					<row><col>0101</col><col>0</col><col>1</col><col>0</col><col>1</col><emptycol cols="10"/><col>1</col><col>1</col><col>1</col><col>1</col><emptycol cols="2"/></row>
					<row><col>0100</col><col>0</col><col>1</col><col>0</col><col>0</col><emptycol cols="10"/><col>1</col><emptycol cols="2"/><col>1</col><emptycol cols="2"/></row>
					<row><col>1100</col><col>1</col><col>1</col><col>0</col><col>0</col><emptycol cols="2"/><col>1</col><emptycol cols="2"/><col>1</col><emptycol cols="4"/><col>1</col><emptycol cols="2"/><col>1</col><emptycol cols="2"/></row>
					<row><col>1101</col><col>1</col><col>1</col><col>0</col><col>1</col><emptycol cols="2"/><col>1</col><col>1</col><col>1</col><col>1</col><emptycol cols="4"/><col>1</col><col>1</col><col>1</col><col>1</col><emptycol cols="2"/></row>
					<row><col>1111</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col></row>
					<row><col>1110</col><col>1</col><col>1</col><col>1</col><col>0</col><emptycol cols="1"/><col>1</col><col>1</col><emptycol cols="2"/><col>1</col><col>1</col><emptycol cols="2"/><col>1</col><col>1</col><emptycol cols="2"/><col>1</col><col>1</col><emptycol cols="1"/></row>
					<row><col>1010</col><col>1</col><col>0</col><col>1</col><col>0</col><emptycol cols="5"/><col>1</col><col>1</col><emptycol cols="2"/><col>1</col><col>1</col><emptycol cols="5"/></row>
					<row><col>1011</col><col>1</col><col>0</col><col>1</col><col>1</col><emptycol cols="4"/><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><col>1</col><emptycol cols="4"/></row>
					<row><col>1001</col><col>1</col><col>0</col><col>0</col><col>1</col><emptycol cols="4"/><col>1</col><col>1</col><emptycol cols="4"/><col>1</col><col>1</col><emptycol cols="4"/></row>
					<row><col>1000</col><col>1</col><col>0</col><col>0</col><col>0</col><emptycol cols="5"/><col>1</col><emptycol cols="4"/><col>1</col><emptycol cols="5"/></row>
					<caption>Table 6: A comparison with the first Karnaugh map shows, that the equation holds.</caption>
				</table>
			</body>
		</chapter>

		<chapter>
			<heading id="B10">Theorem</heading>
			<body>
				<infobox float="right" width="300" background="#F8F8F8">
					<boxtitle>Theorem</boxtitle>
					<body>
						<p>If there exist two identical subrectangles <code>C1</code> and <code>C2</code> 
						at an arbitrary position
						within their parental rectangles A and B, resp., 
						then the rectangles <code>A</code> and <code>B</code> can be joined 
						to form an orthogonal polygon with 
						a common subrectangle <code>C1=C2</code> then and only then,
						when the edges which the subrectangles share with their parental rectangles 
						include all 4 possible edges at the top, right, bottom and left at least once,
						regardless of which rectangle provides which edge(s).</p>
					</body>
				</infobox>
				<p>As per the date writing this article (Dec 20, 2006)
					I was not able to find an according theorem on the Internet. 
					If there exists a such, I would be thankful for a comment or an e-mail 
					in order to mention it. 
					The same is true when you happen to come across another proof.
					In the meantime I suggest the text to the right.</p>
				<p>It has been shown for all 256 possible cases, that the formula holds. 
					Now it's easy to see, why 
					<link loc="up">
						<url>#A2</url>
						<text>fig. 1</text>
					</link> contains two subrectangles which can me merged:
					the subrectangle in fig. 1a comprises the bottom and right edges of it's parental
					rectangle, the subrectangle in fig. 1b the top and left edges: 
					all 4 edges are present, hence the two rectangles can be formed to the
					polygon shown in fig. 2.</p>
				<p>On the other hand, the two rectangles in 
					<link loc="up">
						<url>#A2</url>
						<text>fig. 3</text>
					</link> can not be joined to a polygon sharing a common subrectangle, 
					because none of the two rectangles lies at least partially 
					on its parental rectangle's left edge.</p>
			</body>
		</chapter>
	</part>

	<part>
		<heading id="C">Algorithm</heading>
		<chapter>
			<heading id="C1">Formal</heading>
			<body>
				<p>The algorithm may formally be expressed like this:</p>
				<indentlist>
					<il><p>Set <code>R:=1</code> (<code>R</code> will hold the final result)</p></il>
					<il><p>For all 4 edges:</p>
						<il><p>Set <code>X:=0</code> if the subrectangle of the first main rectangle 
							does not include that particular edge of its main rectangle, 
							<code>X:=1</code> otherwise</p></il>
						<il><p>Set <code>Y:=0</code> if the subrectangle of the second main rectangle 
							does not include that particular edge of its main rectangle, 
							<code>Y:=1</code> otherwise</p></il>
						<il><p>Perform the boolean operation <code>Z:=X OR Y</code></p></il>
						<il><p>Perform the boolean operation <code>R:=R AND Z</code></p></il>
						<il><p>If <code>R</code> is <code>0</code>, then the algorithm terminates and 
							no overlapping polygon is possible</p></il>
						<il><p>If <code>R</code> still is <code>1</code>, repeat for the next edge. 
							If there is no more next edge, the algorithm terminates 
							and creation of a polygon with a shared area is possible</p></il>
					</il>
				</indentlist>
			</body>
		</chapter>

		<chapter>
			<heading id="C2">In Computers</heading>
			<body>
				<p>Note, however, that on a computer the loop of the formal algorithm is not needed, 
					because we can make use of bit parallelism.</p>
				<p>Assume, that we have the values of 4 edges 
					of the first rectangle <code>ABCD</code> in a variable <code>X</code>, coded in 4 bits; 
					and similarly those of the second rectangle <code>EFGH</code> in a variable <code>Y</code>. 
					The order of the edges does not matter, as long as both variables use the same order 
					and the 4 bits are in the same position.</p>
				<table>	
					<row>
						<col>Variable</col>
						<col>Content</col>
					</row>
					<row>
						<col><code>X</code></col>
						<col><code>ABCD</code></col>
					</row>
					<row>
						<col><code>Y</code></col>
						<col><code>EFGH</code></col>
					</row>
					<caption>Table 7: Both rectangle's 4 subrectangle edges in a dedicated variable</caption>
				</table>
				<p>Then <code>X OR Y</code> will perform all 4 Boolean <code>OR</code> operations in one go. 
					Let's store the result in variable <code>Z</code> and 
					name the 4 resulting bits <code>IJKL</code>.</p>
				<table>	
					<row>
						<col>Parallel Boolean operation</col>
						<col>Content after operation</col>
					</row>
					<row>
						<col><code>Z := X OR Y</code></col>
						<col><code>IJKL</code></col>
					</row>
					<caption>Table 8: Parallely ORing 2<ent>times</ent>4 bits</caption>
				</table>
				<p>Now it is only left to find out, if any of the bits in <code>IJKL</code> is <code>0</code>. 
					If so, no overlapping area exists for the two inputs. 
					If all 4 bits are set to <code>1</code>, though, then such an overlapping area exists.</p>
				<p>And because the 4 bits form an unambigeous value when all set, 
					this can be found out with just one comparison. 
					E.g.: assume that the 4 bits all are in the least significant bits of a word 
					(bit values from LSB to MSB: <code>1+2+4+8</code>). Then:</p>
<pre>IF Z = 15 THEN
    Overlapping
ELSE 
    Not Overlapping	
FI</pre>
			</body>
		</chapter>

		<chapter>
			<heading id="C3">Application</heading>
			<body>
				<p>Of course, this algorithm does not tell you yet, <em>how</em> to merge 
				the original rectangles into a polygon combining the common area. 
				But it tells you, if it is possible <code>at all</code>, 
				and this it does at a surprisingly low cost.</p>
			</body>
		</chapter>
	</part>
</page>





