<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nklein software &#187; vecto</title>
	<atom:link href="http://nklein.com/tags/vecto/feed/" rel="self" type="application/rss+xml" />
	<link>http://nklein.com</link>
	<description>software development and consulting</description>
	<lastBuildDate>Thu, 02 Sep 2010 01:03:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Finding the Perfect Hyperbola</title>
		<link>http://nklein.com/2010/02/finding-the-perfect-hyperbola/</link>
		<comments>http://nklein.com/2010/02/finding-the-perfect-hyperbola/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 20:53:18 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[algebra]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[vecto]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1189</guid>
		<description><![CDATA[For an application that I&#8217;m working on, I needed a way to scale quantities that range (theoretically) over the real numbers (though practically are probably between plus and minus three) into positive numbers.  I wanted the function to be everywhere increasing, I wanted , and I wanted control of the derivative at .
The easy [...]]]></description>
			<content:encoded><![CDATA[<p>For an application that I&#8217;m working on, I needed a way to scale quantities that range (theoretically) over the real numbers (though practically are probably between plus and minus three) into positive numbers.  I wanted the function to be everywhere increasing, I wanted <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_c1cb7a5bdd50535b670e023bf91a94fc.png" title="f(0) = 1" style="vertical-align:-20%;" class="tex" alt="f(0) = 1" />, and I wanted control of the derivative at <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_055bb38e2223c10cbcfd8330867c873f.png" title="x = 0" style="vertical-align:-20%;" class="tex" alt="x = 0" />.</p>
<p>The easy choice is: <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1664c465b5fa480b7e4896c0ece77e57.png" title="f(x) = e^{\alpha x}" style="vertical-align:-20%;" class="tex" alt="f(x) = e^{\alpha x}" />.  This is monotonically increasing.  <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_c1cb7a5bdd50535b670e023bf91a94fc.png" title="f(0) = 1" style="vertical-align:-20%;" class="tex" alt="f(0) = 1" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_ed9cb8fb0eee1cd2d3a17d75a4c58847.png" title="f^\prime(0) = \alpha" style="vertical-align:-20%;" class="tex" alt="f^\prime(0) = \alpha" />.</p>
<p>I needed to scale three such quantities and mush them together.  I thought it&#8217;d be spiffy then to have three different functions that satisfy my criteria.  The next logical choice was <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_7b757a3e18f1bca442c93c1065331ed4.png" title="f(x) = 1 + \mathrm{tanh} (\alpha x)" style="vertical-align:-20%;" class="tex" alt="f(x) = 1 + \mathrm{tanh} (\alpha x)" />.  It is everywhere positive and increasing.  And, it has <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_ed9cb8fb0eee1cd2d3a17d75a4c58847.png" title="f^\prime(0) = \alpha" style="vertical-align:-20%;" class="tex" alt="f^\prime(0) = \alpha" />.</p>
<p>Now, I needed third function that was always positive, always increasing, had <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_c1cb7a5bdd50535b670e023bf91a94fc.png" title="f(0) = 1" style="vertical-align:-20%;" class="tex" alt="f(0) = 1" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_ed9cb8fb0eee1cd2d3a17d75a4c58847.png" title="f^\prime(0) = \alpha" style="vertical-align:-20%;" class="tex" alt="f^\prime(0) = \alpha" />.  One choice was:  <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_5e73c987e194dae7b18809999c7cedd6.png" title="f(x) = e^{e^{\alpha x} - 1}" style="vertical-align:-20%;" class="tex" alt="f(x) = e^{e^{\alpha x} - 1}" />.  But, that seemed like overkill.  It also meant that I really had to keep my <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_a7175a60e504c64ad51e7119b44ee9aa.png" title="\alpha" style="vertical-align:-20%;" class="tex" alt="\alpha" /> tiny if I didn&#8217;t want to scale things into the stratosphere.</p>
<h3>Playing with hyperbolas</h3>
<p><a href="http://nklein.com/wp-content/uploads/2010/02/hyperbola.png"><img src="http://nklein.com/wp-content/uploads/2010/02/hyperbola-300x300.png" alt="" title="hyperbola" width="300" height="300" class="alignright size-medium wp-image-1191" /></a>So, I thought&#8230; why don&#8217;t I make a hyperbola, rotate it, and shift it so that the apex of one side of the hyperbola is at <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_899c0ad792ee5fca9071f5bbeb6fc9ad.png" title="(0,1)" style="vertical-align:-20%;" class="tex" alt="(0,1)" />.  And, I can adjust the parameters of the hyperbola so that <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_2213bb99d8be759f217ca55bd95edd12.png" title="f'(0) = \alpha" style="vertical-align:-20%;" class="tex" alt="f'(0) = \alpha" />.  After a variety of false starts where I tried to keep the hyperbola general until the very end (<img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_65fc2db1a4b8c991b7049c4fe78eed83.png" title="\frac{x^2}{a^2} - \frac{y^2}{b^2} = r^2" style="vertical-align:-20%;" class="tex" alt="\frac{x^2}{a^2} - \frac{y^2}{b^2} = r^2" />, rotated by <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_0004c76178a1d078888badee6891a8bd.png" title="\theta" style="vertical-align:-20%;" class="tex" alt="\theta" /> degrees, and shifted by <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_ed45436c4512976c4600afab449577d8.png" title="\beta" style="vertical-align:-20%;" class="tex" alt="\beta" />), I quickly got bogged down in six or seven incredibly ugly equations in eight or nine variables.</p>
<p>So, it was time to start trying to make it easy from the beginning.   I noticed that if was going to rotate it by an angle <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_0004c76178a1d078888badee6891a8bd.png" title="\theta" style="vertical-align:-20%;" class="tex" alt="\theta" /> in the clockwise direction, then I needed <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_b4a257df561663115406a382c2fdfb00.png" title="\phi = \frac{\pi}{2} - \theta" style="vertical-align:-20%;" class="tex" alt="\phi = \frac{\pi}{2} - \theta" /> to be such that <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1537f3082a10cb5448ec9dabe01a0d12.png" title="\tan \phi = \alpha" style="vertical-align:-20%;" class="tex" alt="\tan \phi = \alpha" /> if my slope was going to work out right in the end.<a href="http://nklein.com/wp-content/uploads/2010/02/triangle.png"><img src="http://nklein.com/wp-content/uploads/2010/02/triangle-150x150.png" alt="" title="triangle" width="150" height="150"  style="clear: right;" class="alignright size-thumbnail wp-image-1192" /></a>   So, I&#8217;m looking at the basic triangle on the right then to determine all of my sines and cosines and such.</p>
<p>Based on that triangle, it was also obvious that the asymptote for my starting hyperbola had to have <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_16d704e03ab06854b6f15c35ef6b6c63.png" title="\frac{b}{a} = \frac{1}{\alpha}" style="vertical-align:-20%;" class="tex" alt="\frac{b}{a} = \frac{1}{\alpha}" />.  I played around a bit then with making <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_cbc4d0c9418a975cd07b3481c3233e22.png" title="a = \alpha" style="vertical-align:-20%;" class="tex" alt="a = \alpha" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_76ad81f0c9a6b05231a9d44eb84b8637.png" title="b = 1" style="vertical-align:-20%;" class="tex" alt="b = 1" />.  In the end, I found things simplified sooner if I started with <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_bfc64db88044b1bed880f65ab006c520.png" title="a = 1" style="vertical-align:-20%;" class="tex" alt="a = 1" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_56f3ac4506d4d0fd32c01984d7ea7fa5.png" title="b = \frac{1}{\alpha}" style="vertical-align:-20%;" class="tex" alt="b = \frac{1}{\alpha}" />.</p>
<p>I also needed <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_de3adc820dbc4655c45b5555765fe84b.png" title="r" style="vertical-align:-20%;" class="tex" alt="r" /> to be such that the point <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_6351922e40bc95d55bb60e1fe4fb18fd.png" title="(-r,0)" style="vertical-align:-20%;" class="tex" alt="(-r,0)" /> rotate up so that its <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_e561f1e00880abb7e58816455af00a48.png" title="y" style="vertical-align:-20%;" class="tex" alt="y" />-coordinate was <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_e04a0c4d52e7f8537abf80bb9beb4a8a.png" title="1" style="vertical-align:-20%;" class="tex" alt="1" />.  This meant that <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_82520310515e5f6f8a4d1dd2a84c782a.png" title="r \sin \theta = 1" style="vertical-align:-20%;" class="tex" alt="r \sin \theta = 1" /> or <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_5f02e0b2b4a7ef37d5076f74f518a6ca.png" title="r = \frac{1}{\sin \theta} = \sqrt{1 + \alpha^2}" style="vertical-align:-20%;" class="tex" alt="r = \frac{1}{\sin \theta} = \sqrt{1 + \alpha^2}" />.</p>
<p>So, my starting hyperbola then was: <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_f0b77c1ca12c3756fceacceb7ee4ac21.png" title="x^2 - \alpha^2 y^2 = 1 + \alpha^2" style="vertical-align:-20%;" class="tex" alt="x^2 - \alpha^2 y^2 = 1 + \alpha^2" />.</p>
<p>From there, I had to rotate the <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1a507c5494969dc6de305770cadc6630.png" title="x" style="vertical-align:-20%;" class="tex" alt="x" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_e561f1e00880abb7e58816455af00a48.png" title="y" style="vertical-align:-20%;" class="tex" alt="y" /> by <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_0004c76178a1d078888badee6891a8bd.png" title="\theta" style="vertical-align:-20%;" class="tex" alt="\theta" /> in the clockwise direction.  This gave me:<br />
<center><img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_d54c652aea88202bb256c37f3d486786.png" title="(x\cos\theta - y\sin\theta)^2 - \alpha^2 (x\sin\theta + y\cos\theta)^2 = 1 + \alpha^2" style="vertical-align:-20%;" class="tex" alt="(x\cos\theta - y\sin\theta)^2 - \alpha^2 (x\sin\theta + y\cos\theta)^2 = 1 + \alpha^2" /></center></p>
<p>A little multiplying out leads to:<br />
<center><img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_802799f8a59061e695ae8624b0a1a115.png" title="(x^2\cos^2\theta - 2xy\sin\theta\cos\theta + y^2\sin^2\theta) \\ - \alpha^2(x^2\sin^2\theta + 2xy\sin\theta\cos\theta + y^2\cos^2\theta) = 1 + \alpha^2" style="vertical-align:-20%;" class="tex" alt="(x^2\cos^2\theta - 2xy\sin\theta\cos\theta + y^2\sin^2\theta) \\ - \alpha^2(x^2\sin^2\theta + 2xy\sin\theta\cos\theta + y^2\cos^2\theta) = 1 + \alpha^2" /></center></p>
<p>From there, using <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_ba506e83b38225aee1a949dfefa8f98b.png" title="cos^2\theta = \frac{\alpha^2}{1 + \alpha^2}" style="vertical-align:-20%;" class="tex" alt="cos^2\theta = \frac{\alpha^2}{1 + \alpha^2}" />, <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_63a5ce798225d66ffd828cbf6adc0d27.png" title="sin^2\theta = \frac{1}{1 + \alpha^2}" style="vertical-align:-20%;" class="tex" alt="sin^2\theta = \frac{1}{1 + \alpha^2}" />, and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_31893ba13c851bec319d1e84fa273c4f.png" title="\sin\theta\cos\theta = \frac{\alpha}{1 + \alpha^2}" style="vertical-align:-20%;" class="tex" alt="\sin\theta\cos\theta = \frac{\alpha}{1 + \alpha^2}" />, we come to:</p>
<p><center><img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_932ad4d95a72a6cae8c353b9bce95524.png" title="\frac{-2\alpha(1 + \alpha^2)xy + ( 1 - \alpha^4 )y^2}{1 + \alpha^2} = -2\alpha{}xy +  (1 - \alpha^2)y^2 = 1 + \alpha^2" style="vertical-align:-20%;" class="tex" alt="\frac{-2\alpha(1 + \alpha^2)xy + ( 1 - \alpha^4 )y^2}{1 + \alpha^2} = -2\alpha{}xy +  (1 - \alpha^2)y^2 = 1 + \alpha^2" /></center></p>
<p>The only step remaining was to shift it all over so that when <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_409ec858a4679ef8370133dc2076b0b0.png" title="y = 1" style="vertical-align:-20%;" class="tex" alt="y = 1" />, we end up with <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_055bb38e2223c10cbcfd8330867c873f.png" title="x = 0" style="vertical-align:-20%;" class="tex" alt="x = 0" />.  Plugging in <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_409ec858a4679ef8370133dc2076b0b0.png" title="y = 1" style="vertical-align:-20%;" class="tex" alt="y = 1" />, we see that <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1150678e298fe9f8e85ddc65f9fec594.png" title="-2x\alpha + 1 - \alpha^2 = 1 + \alpha" style="vertical-align:-20%;" class="tex" alt="-2x\alpha + 1 - \alpha^2 = 1 + \alpha" />.  That equation balances when <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_5ced797303d05efbca9c01afa8b0c01d.png" title="x = -\alpha" style="vertical-align:-20%;" class="tex" alt="x = -\alpha" />.  We want it to balance when <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_055bb38e2223c10cbcfd8330867c873f.png" title="x = 0" style="vertical-align:-20%;" class="tex" alt="x = 0" />, so we&#8217;re going to substitute <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_eb4abeadbac893437197dcaef65065d0.png" title="(x - \alpha)" style="vertical-align:-20%;" class="tex" alt="(x - \alpha)" /> in place of the <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1a507c5494969dc6de305770cadc6630.png" title="x" style="vertical-align:-20%;" class="tex" alt="x" /> in the above equation to get:<br />
<center><img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_fa1ee19decc1e63df0780f88c698e267.png" title="-2\alpha(x - \alpha)y + (1 - \alpha^2)y^2 = 1 + \alpha^2" style="vertical-align:-20%;" class="tex" alt="-2\alpha(x - \alpha)y + (1 - \alpha^2)y^2 = 1 + \alpha^2" /></center></p>
<p>We can easily verify that the point <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_899c0ad792ee5fca9071f5bbeb6fc9ad.png" title="(0,1)" style="vertical-align:-20%;" class="tex" alt="(0,1)" /> is on the curve.  And, we can implicitly differentiate the above to get:<br />
<center><img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_e3c61432dce722a22bd63f345ff46dfb.png" title="-2\alpha(x - \alpha)\frac{dy}{dx} - 2\alpha{}y + 2(1 - \alpha^2)y\frac{dy}{dx} = 0" style="vertical-align:-20%;" class="tex" alt="-2\alpha(x - \alpha)\frac{dy}{dx} - 2\alpha{}y + 2(1 - \alpha^2)y\frac{dy}{dx} = 0" /></center><br />
Plopping <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_055bb38e2223c10cbcfd8330867c873f.png" title="x = 0" style="vertical-align:-20%;" class="tex" alt="x = 0" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_409ec858a4679ef8370133dc2076b0b0.png" title="y = 1" style="vertical-align:-20%;" class="tex" alt="y = 1" /> in there, we find that <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_72e4810a86292a1519a296309402d06c.png" title="\frac{dy}{dx} = \alpha" style="vertical-align:-20%;" class="tex" alt="\frac{dy}{dx} = \alpha" />.</p>
<p>This is pretty good as it goes.  The only step is to complete the square to find a nicer expression for <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_e561f1e00880abb7e58816455af00a48.png" title="y" style="vertical-align:-20%;" class="tex" alt="y" /> in terms of <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1a507c5494969dc6de305770cadc6630.png" title="x" style="vertical-align:-20%;" class="tex" alt="x" />.  We start by adding <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_62383f7ea78be0903e109947ea724843.png" title="\left[ \frac{\alpha}{\sqrt{1 - \alpha^2}} (x - \alpha) \right]^2" style="vertical-align:-20%;" class="tex" alt="\left[ \frac{\alpha}{\sqrt{1 - \alpha^2}} (x - \alpha) \right]^2" /> to both sides to get:<br />
<center><img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_9e6cf43c71372d26b0e06677ad2ac25c.png" title="\left[ \sqrt(1 - \alpha^2)y - \frac{\alpha}{\sqrt{1 - \alpha^2}(x - \alpha)} \right]^2 = 1 + \alpha^2 + \frac{\alpha}{1 - \alpha^2} (x-\alpha)^2" style="vertical-align:-20%;" class="tex" alt="\left[ \sqrt(1 - \alpha^2)y - \frac{\alpha}{\sqrt{1 - \alpha^2}(x - \alpha)} \right]^2 = 1 + \alpha^2 + \frac{\alpha}{1 - \alpha^2} (x-\alpha)^2" /></center></p>
<p>This is easy enough to solve for <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_e561f1e00880abb7e58816455af00a48.png" title="y" style="vertical-align:-20%;" class="tex" alt="y" /> by taking the square root of both sides and shuffling some things about:<br />
<center><img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_bec4a5b2c46a0636d3a736f5a68e1a5b.png" title="y = \frac{\alpha}{1 - \alpha^2}(x - \alpha) + \frac{1}{\sqrt{1 - \alpha^2}} \sqrt{1 + \alpha^2 + \frac{\alpha^2}{1 - \alpha^2}(x - \alpha)^2}" style="vertical-align:-20%;" class="tex" alt="y = \frac{\alpha}{1 - \alpha^2}(x - \alpha) + \frac{1}{\sqrt{1 - \alpha^2}} \sqrt{1 + \alpha^2 + \frac{\alpha^2}{1 - \alpha^2}(x - \alpha)^2}" /></center></p>
<p>Here are all three curves with <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3fa6bf5c636b83a0ae3d01c31d078f76.png" title="\alpha = \frac{1}{4}" style="vertical-align:-20%;" class="tex" alt="\alpha = \frac{1}{4}" />.  The exponential is in black, the hyperbolic tangent is in red, and the hyperbola is in blue:<br />
<center><a href="http://nklein.com/wp-content/uploads/2010/02/final.png"><img src="http://nklein.com/wp-content/uploads/2010/02/final.png" alt="" title="final" width="522" height="322" class="alignnone size-full wp-image-1218" /></a></center></p>
<p>The first image on the page here was made with Zach&#8217;s <a href="http://www.xach.com/lisp/vecto/">Vecto</a> library with some post-processing in the GIMP.  (Here is the source file: <a href="http://nklein.com/wp-content/uploads/2010/02/hyperbola.lisp">hyperbola.lisp</a>.) The second image was made entirely within the GIMP.  And, the last image was made using <a href="http://fooplot.com/">Foo Plot</a> and the GIMP.</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2010/02/finding-the-perfect-hyperbola/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DSL for Drawing Floor Plans</title>
		<link>http://nklein.com/2009/10/dsl-for-drawing-floor-plans/</link>
		<comments>http://nklein.com/2009/10/dsl-for-drawing-floor-plans/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 04:06:00 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[vecto]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=999</guid>
		<description><![CDATA[Last week, I needed create a scale drawing of my basement floor plan.  My license for OmniGraffle Professional are long since out-of-date.  I didn&#8217;t want to pay $200 for a new license or even another $75 if I can dig up one of my old license keys.  So, what&#8217;s a hacker to [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, I needed create a scale drawing of my basement floor plan.  My license for <a href="http://www.omnigroup.com/applications/omnigraffle/">OmniGraffle Professional</a> are long since out-of-date.  I didn&#8217;t want to pay $200 for a new license or even another $75 if I can dig up one of my old license keys.  So, what&#8217;s a hacker to do?  Roll his own (on top of Zach&#8217;s <a href="http://www.xach.com/lisp/vecto/">Vecto</a> library).</p>
<p>My first cut worked, but was pretty ugly:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>with-floor-plan #P<span style="color: #ff0000;">&quot;basement.png&quot;</span> <span style="color: #cc66cc;">200.0</span><br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>interior-wall <span style="color: #66cc66;">:</span><span style="color: #555;">start</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>- <span style="color: #cc66cc;">91</span> <span style="color: #cc66cc;">31</span> <span style="color: #cc66cc;">1</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; hose cover</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">:</span><span style="color: #555;">north</span> <span style="color: #cc66cc;">18</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">:</span><span style="color: #555;">east</span> &nbsp;<span style="color: #66cc66;">&#40;</span>+ <span style="color: #cc66cc;">31</span> <span style="color: #cc66cc;">1</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>interior-wall <span style="color: #66cc66;">:</span><span style="color: #555;">start</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #cc66cc;">91</span> <span style="color: #66cc66;">&#40;</span>- <span style="color: #cc66cc;">103</span> <span style="color: #cc66cc;">27</span> <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; storage wall</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">:</span><span style="color: #555;">south</span> <span style="color: #66cc66;">&#40;</span>- <span style="color: #cc66cc;">103</span> <span style="color: #cc66cc;">27</span> <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>interior-wall <span style="color: #66cc66;">:</span><span style="color: #555;">start</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>+ <span style="color: #cc66cc;">91</span> <span style="color: #cc66cc;">83</span><span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">103</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #808080; font-style: italic;">; fish-tank wall</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">:</span><span style="color: #555;">to</span> '<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">91</span> <span style="color: #66cc66;">.</span> <span style="color: #cc66cc;">103</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">:</span><span style="color: #555;">south</span> <span style="color: #cc66cc;">27</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span></div></div>
<p><a href="http://nklein.com/wp-content/uploads/2009/10/basement.png"><img src="http://nklein.com/wp-content/uploads/2009/10/basement-120x150.png" alt="basement" title="basement" width="120" height="150" class="alignright size-thumbnail wp-image-1000" /></a><br />
I ended up with large calculations like that <b>(-&nbsp;103&nbsp;27&nbsp;30)</b> you see there.  It worked.  I got an okay looking floor-plan out of it.  But, it was obvious that it needed some rethinking.</p>
<p>My next thought was turtle graphics!  Tell things where to move.  Tell it to start drawing an interior wall.  Tell it where to move.  Tell it to start drawing a window.  Tell it where to move.  Tell it to stop drawing a window.  Etc.  This has possibilities, especially for an internal representation (which I need because I want to autoscale the drawing to fit on a sheet of paper well, so I can&#8217;t start drawing until I&#8217;ve determined the extents).  However, it seems awkward to go with all of the start/stop commands.  I am thinking of going more in this sort of direction:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;; The floor-plan stuff works in units. &nbsp;To facility readability, I am</span><br />
<span style="color: #808080; font-style: italic;">;; going to make some simple functions that use feet and inches instead</span><br />
<span style="color: #808080; font-style: italic;">;; of units. &nbsp;If you want centimeters and meters, go for it.</span><br />
<br />
<span style="color: #66cc66;">&#40;</span>flet <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>feet <span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>* n <span style="color: #cc66cc;">12</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>inches <span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span> n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>with-floor-plan <span style="color: #66cc66;">&#40;</span>#P<span style="color: #ff0000;">&quot;floor-plan.png&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">:</span><span style="color: #555;">max-width</span> &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">8.0</span> &nbsp;<span style="color: #808080; font-style: italic;">; maximum width of output (units)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">:</span><span style="color: #555;">max-height</span> &nbsp; &nbsp; <span style="color: #cc66cc;">10.0</span> &nbsp;<span style="color: #808080; font-style: italic;">; maximum height of output (units)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">:</span><span style="color: #555;">dots-per-unit</span> <span style="color: #cc66cc;">300.0</span> &nbsp;<span style="color: #808080; font-style: italic;">; resolution of output</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">:</span><span style="color: #555;">grid</span> &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>inches <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; size of background-grid</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>compass <span style="color: #66cc66;">:</span><span style="color: #555;">north</span> <span style="color: #cc66cc;">180.0</span><span style="color: #66cc66;">&#41;</span> &nbsp; <span style="color: #808080; font-style: italic;">; draw north indication 180 degrees CCW from right</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>exterior-wall &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; start drawing an exterior wall</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">:</span><span style="color: #555;">closed</span> t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; that closes at the end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>left <span style="color: #66cc66;">&#40;</span>feet <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; extend wall left 10 feet</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>up <span style="color: #66cc66;">&#40;</span>feet <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; extend wall up 6 feet</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>window<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>up <span style="color: #66cc66;">&#40;</span>inches <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; draw 30&quot; window</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>up <span style="color: #66cc66;">&#40;</span>inches <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; draw 8&quot; wall</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>door <span style="color: #66cc66;">:</span><span style="color: #555;">starts</span> <span style="color: #66cc66;">:</span><span style="color: #555;">hinge-side</span> &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; or :latch-side</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">:</span><span style="color: #555;">opens</span> <span style="color: #66cc66;">:</span><span style="color: #555;">left</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; or :right seen from direction of motion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>up <span style="color: #66cc66;">&#40;</span>inches <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; this door goes up, so :left is to</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">; the left of the page</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>up <span style="color: #66cc66;">&#40;</span>inches <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>right <span style="color: #66cc66;">&#40;</span>feet <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>left <span style="color: #66cc66;">&#40;</span>feet <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; move four feet to the left</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>interior-wall<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>up <span style="color: #66cc66;">&#40;</span>feet <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>right <span style="color: #66cc66;">&#40;</span>inches <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>door <span style="color: #66cc66;">:</span><span style="color: #555;">starts</span> <span style="color: #66cc66;">:</span><span style="color: #555;">latch-side</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">:</span><span style="color: #555;">opens</span> <span style="color: #66cc66;">:</span><span style="color: #555;">right</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>right <span style="color: #66cc66;">&#40;</span>inches <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>right-to <span style="color: #66cc66;">&#40;</span>feet <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">; move to an absolute left-right coordinate</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>move <span style="color: #66cc66;">&#40;</span>feet <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>feet <span style="color: #66cc66;">&#40;</span>+ <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">1</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>label <span style="color: #ff0000;">&quot;Bathroom&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Has anyone tackled this problem well already?  Or, have any suggestions of how to improve this?</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2009/10/dsl-for-drawing-floor-plans/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Ask a simple question&#8230;</title>
		<link>http://nklein.com/2009/08/ask-a-simple-question/</link>
		<comments>http://nklein.com/2009/08/ask-a-simple-question/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 05:55:45 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[integrals]]></category>
		<category><![CDATA[probability density functions]]></category>
		<category><![CDATA[vecto]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=735</guid>
		<description><![CDATA[Ask a simple question, spend the next forty minutes sifting through integral tables.  Earlier, I took some code that was uniformly selecting points from a square centered at the origin and converted it to code using points from a normal distribution.  For my purposes, I used a standard-deviation for the normal distribution that [...]]]></description>
			<content:encoded><![CDATA[<p>Ask a simple question, spend the next forty minutes sifting through integral tables.  Earlier, I took some code that was uniformly selecting points from a square centered at the origin and converted it to <a href="http://nklein.com/2009/08/casting-to-integers-considered-harmful/">code using points from a normal distribution</a>.  For my purposes, I used a standard-deviation for the normal distribution that was half of the in-radius of the box.  It wasn&#8217;t at all exact in any way.</p>
<p>What if I wanted to be exact?  Suppose I wanted to switch from points uniformly distributed in a box to points from a normal distribution while maintaining the <em>expected distance from the selected point to the origin</em>.</p>
<p>What exactly is the expected distance from a selected point to the origin if one picks each coordinate for the point from a uniform distribution on the range [-1,+1]?  Let&#8217;s start with the one-dimensional case.  The probability density is <img src="http://l.wordpress.com/latex.php?latex=%5Cfrac%7B1%7D%7B2%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\frac{1}{2}" style="vertical-align:-20%;" class="tex" alt="\frac{1}{2}" /> everywhere.  So, the answer is <img src="http://l.wordpress.com/latex.php?latex=2%20%5Cint_%7Br%3D0%7D%5E1%20%5Cfrac%7B1%7D%7B2%7D%20r%20dr%20%3D%20%5Cfrac%7B1%7D%7B2%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="2 \int_{r=0}^1 \frac{1}{2} r dr = \frac{1}{2}" style="vertical-align:-20%;" class="tex" alt="2 \int_{r=0}^1 \frac{1}{2} r dr = \frac{1}{2}" /> as we would expect.</p>
<p><img src="http://nklein.com/wp-content/uploads/2009/08/integrate.png" alt="(image created in Lisp using Zach&#039;s Vecto library)" title="integrate" width="256" height="256" class="alignright size-full wp-image-737" />How about two dimensions?  This is immediately more awkward.  The one-dimensional disk looks exactly like the one-dimensional square.  In two dimensions, the disk and square are quite different.  We either have to integrate over the square and calculate the radius of each point, or we have to integrate over increasing radii and be careful once we get to the in-radius of the square. <span style="font-size: 75%;">(image created in Lisp using <a href="http://xach.livejournal.com/">Zach</a>&#039;s <a href="http://www.xach.com/lisp/vecto/">Vecto</a> library)</span></p>
<p>I originally chose to try to integrate over the square.  The probability density is <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_c78400c32272b1ce00c8785c0d99408d.png" title="\frac{1}{4}" style="vertical-align:-20%;" class="tex" alt="\frac{1}{4}" /> everywhere.  This means the expected radius is  <img src="http://l.wordpress.com/latex.php?latex=%5Cint_%7By%3D-1%7D%5E1%20%5Cint_%7Bx%3D-1%7D%5E1%20%5Csqrt%7Bx%5E2%2By%5E2%7D%20dx%20dy&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\int_{y=-1}^1 \int_{x=-1}^1 \sqrt{x^2+y^2} dx dy" style="vertical-align:-20%;" class="tex" alt="\int_{y=-1}^1 \int_{x=-1}^1 \sqrt{x^2+y^2} dx dy" />.  This gets to be no fun very fast since the inner integral comes out with a logarithm in it.  I mean, do you want to finish this integral?<br />
<center><img src="http://l.wordpress.com/latex.php?latex=%5Cint_%7By%3D-1%7D%5E1%20%5Cleft.%5Cleft%28%20%5Cfrac%7B1%7D%7B2%7D%20x%20%5Csqrt%7Bx%5E2%20%2B%20y%5E2%7D%20%2B%20%5Cfrac%7B1%7D%7B2%7D%20y%5E2%20%5Cln%20%5Cleft%28%20x%20%2B%20%5Csqrt%7Bx%5E2%20%2B%20y%5E2%7D%20%5Cright%29%5Cright%29%5Cright%7C_%7Bx%3D-1%7D%5E1%20dy&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\int_{y=-1}^1 \left.\left( \frac{1}{2} x \sqrt{x^2 + y^2} + \frac{1}{2} y^2 \ln \left( x + \sqrt{x^2 + y^2} \right)\right)\right|_{x=-1}^1 dy" style="vertical-align:-20%;" class="tex" alt="\int_{y=-1}^1 \left.\left( \frac{1}{2} x \sqrt{x^2 + y^2} + \frac{1}{2} y^2 \ln \left( x + \sqrt{x^2 + y^2} \right)\right)\right|_{x=-1}^1 dy" /></center><br />
It may be easy.  I didn&#8217;t want to mess with it.  I suppose once you evaluate the <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1a507c5494969dc6de305770cadc6630.png" title="x" style="vertical-align:-20%;" class="tex" alt="x" /> terms, it reduces a fair bit (if I did that all right):<br />
<center><img src="http://l.wordpress.com/latex.php?latex=%5Cint_%7By%3D-1%7D%5E1%20%5Cleft%28%20%5Csqrt%7B1%20%2B%20y%5E2%7D%20%2B%20%5Cfrac%7B1%7D%7B2%7D%20y%5E2%20%5Cln%20%5Cleft%28%20%5Cfrac%7B1%20%2B%20%5Csqrt%7B1%20%2B%20y%5E2%7D%7D%7B-1%20%2B%20%5Csqrt%7B1%20%2B%20y%5E2%7D%7D%20%5Cright%29%20%5Cright%29%20dy&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\int_{y=-1}^1 \left( \sqrt{1 + y^2} + \frac{1}{2} y^2 \ln \left( \frac{1 + \sqrt{1 + y^2}}{-1 + \sqrt{1 + y^2}} \right) \right) dy" style="vertical-align:-20%;" class="tex" alt="\int_{y=-1}^1 \left( \sqrt{1 + y^2} + \frac{1}{2} y^2 \ln \left( \frac{1 + \sqrt{1 + y^2}}{-1 + \sqrt{1 + y^2}} \right) \right) dy" /></center><br />
I still don&#8217;t want to touch it.</p>
<p>So, how about integrating over the radii?  Again, the probability density is <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_c78400c32272b1ce00c8785c0d99408d.png" title="\frac{1}{4}" style="vertical-align:-20%;" class="tex" alt="\frac{1}{4}" /> everywhere.  This makes the expected radius:<br />
<center><img src="http://l.wordpress.com/latex.php?latex=%5Cint_%7Br%3D0%7D%5E1%20%5Cfrac%7B1%7D%7B4%7D%20%5Ccdot%202%20%5Cpi%20r%20dr%20%2B%20%5Cint_%7Br%3D1%7D%5E%7B%5Csqrt%7B2%7D%7D%20%5Cfrac%7B1%7D%7B4%7D%20%5Ccdot%208%20%5Cleft%28%20%5Cfrac%7B%5Cpi%7D%7B4%7D%20-%20%5Carccos%20%5Cfrac%7B1%7D%7Br%7D%20%5Cright%29%20dr&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\int_{r=0}^1 \frac{1}{4} \cdot 2 \pi r dr + \int_{r=1}^{\sqrt{2}} \frac{1}{4} \cdot 8 \left( \frac{\pi}{4} - \arccos \frac{1}{r} \right) dr" style="vertical-align:-20%;" class="tex" alt="\int_{r=0}^1 \frac{1}{4} \cdot 2 \pi r dr + \int_{r=1}^{\sqrt{2}} \frac{1}{4} \cdot 8 \left( \frac{\pi}{4} - \arccos \frac{1}{r} \right) dr" /></center><br />
With a little massaging, you can move the <img src="http://l.wordpress.com/latex.php?latex=%5Cfrac%7B%5Cpi%7D%7B4%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\frac{\pi}{4}" style="vertical-align:-20%;" class="tex" alt="\frac{\pi}{4}" /> from the second integral into the first instead:<br />
<center><img src="http://l.wordpress.com/latex.php?latex=%5Cint_%7Br%3D0%7D%5E%7B%5Csqrt%7B2%7D%7D%20%5Cfrac%7B1%7D%7B4%7D%20%5Ccdot%202%20%5Cpi%20r%20dr%20-%20%5Cint_%7Br%3D1%7D%5E%7B%5Csqrt%7B2%7D%7D%20%5Cfrac%7B1%7D%7B4%7D%20%5Ccdot%208%20%5Carccos%20%5Cfrac%7B1%7D%7Br%7D%20dr&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\int_{r=0}^{\sqrt{2}} \frac{1}{4} \cdot 2 \pi r dr - \int_{r=1}^{\sqrt{2}} \frac{1}{4} \cdot 8 \arccos \frac{1}{r} dr" style="vertical-align:-20%;" class="tex" alt="\int_{r=0}^{\sqrt{2}} \frac{1}{4} \cdot 2 \pi r dr - \int_{r=1}^{\sqrt{2}} \frac{1}{4} \cdot 8 \arccos \frac{1}{r} dr" /></center><br />
This is hardly consolation though.  Here is where we get lost in our table of integrals for the better part of an hour.</p>
<p>And, this is only the two-dimensional case!  In my original problem, the ambient space was 32-dimensional.  My, oh my.</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2009/08/ask-a-simple-question/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
