<?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>GBuffer.net</title>
	<atom:link href="http://www.gbuffer.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.gbuffer.net</link>
	<description>&#62; Sid’s data dump</description>
	<lastBuildDate>Sat, 12 Jun 2010 21:59:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>A different way to find a point on a hyperplane closest to a given point</title>
		<link>http://www.gbuffer.net/archives/193</link>
		<comments>http://www.gbuffer.net/archives/193#comments</comments>
		<pubDate>Sat, 12 Jun 2010 21:59:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[maths]]></category>

		<guid isPermaLink="false">http://www.gbuffer.net/?p=193</guid>
		<description><![CDATA[As a graphics programmer, I often need to find a point on a hyperplane (line or plane) closest to a given point. So far my understanding of the problem has been based on trigonometric concepts that is probably the simplest way of approaching the problem. I&#8217;m not going to explain the boring trigonometric approach to [...]]]></description>
			<content:encoded><![CDATA[<p>As a graphics programmer, I often need to find a point on a hyperplane (line or plane) closest to a given point. So far my understanding of the problem has been based on trigonometric concepts that is probably the simplest way of approaching the problem. I&#8217;m not going to explain the boring trigonometric approach to the problem here. You can find that on some other website using <a href="http://www.google.co.uk/search?q=point%20on%20a%20line%20closest%20to%20a%20given%20point">Google</a>.</p>
<p>A few weeks back I came across a new concept in maths called Lagrange multipliers. In addition to the problem that I was addressing at the time, I was interested in seeing if it could be applied to find a point on a hyperplane closest to a given point.</p>
<p>If you are not familiar with Lagrange multipliers then just go to the <a href="http://en.wikipedia.org/wiki/Lagrange_multipliers">Wikipedia</a> page that explains it all. I think they give a better explanation of the problem than I ever will. Ok, so if you haven&#8217;t already figured out how we are going to approach this problem, read on.</p>
<p>Lets work in 2 dimensions with  a line of the form<br />
<img src='http://s.wordpress.com/latex.php?latex=%5Calpha%20x%2B%5Cbeta%20y%2B%5Cgamma%20%3D%200&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\alpha x+\beta y+\gamma = 0' title='\alpha x+\beta y+\gamma = 0' class='latex' /><br />
Lets try and visualize this&#8230;<br />
The vector <img src='http://s.wordpress.com/latex.php?latex=%28%5Calpha%2C%5Cbeta%29%5ET&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(\alpha,\beta)^T' title='(\alpha,\beta)^T' class='latex' /> represents the normal to the line<br />
The constant <img src='http://s.wordpress.com/latex.php?latex=%5Cgamma&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\gamma' title='\gamma' class='latex' /> is the distance to closest point on the line to the origin.<br />
If you are used to only seeing the line in the slope intercept form as <img src='http://s.wordpress.com/latex.php?latex=y%3Dmx%20%2B%20b&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y=mx + b' title='y=mx + b' class='latex' /><br />
then we can simply assume that<br />
<img src='http://s.wordpress.com/latex.php?latex=%5Calpha%20%3D%20m&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\alpha = m' title='\alpha = m' class='latex' />, <img src='http://s.wordpress.com/latex.php?latex=%5Cbeta%20%3D%20-1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\beta = -1' title='\beta = -1' class='latex' /> and <img src='http://s.wordpress.com/latex.php?latex=%5Cgamma%20%3D%20b&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\gamma = b' title='\gamma = b' class='latex' />.</p>
<p>Now lets take our point <img src='http://s.wordpress.com/latex.php?latex=P%3D%28x_p%2C%20y_p%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P=(x_p, y_p)' title='P=(x_p, y_p)' class='latex' /> in space. Now we would like to do is minimise the Euclidean distance to this point.  The Euclidean distance is calculated using the equation<br />
<img src='http://s.wordpress.com/latex.php?latex=f%28x%2C%20y%29%20%3D%20%5Csqrt%7B%28x-x_%7Bp%7D%29%5E2%2B%28y-y_%7Bp%7D%29%5E2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(x, y) = \sqrt{(x-x_{p})^2+(y-y_{p})^2}' title='f(x, y) = \sqrt{(x-x_{p})^2+(y-y_{p})^2}' class='latex' /><br />
Minimizing this problem is dead simple. The closest point to a point is the point it self. But now we would like to add a constraint such that the closest point must lie of the line, whose equation is<br />
<img src='http://s.wordpress.com/latex.php?latex=g%28x%2Cy%29%20%3D%20%5Calpha%20x%20%2B%20%5Cbeta%20y%20%2B%20%5Cgamma%20%3D%200&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g(x,y) = \alpha x + \beta y + \gamma = 0' title='g(x,y) = \alpha x + \beta y + \gamma = 0' class='latex' /><br />
We approach this problem using a simple form of the Lagrange multiplier where we minimize the function <img src='http://s.wordpress.com/latex.php?latex=f%28x%2Cy%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(x,y)' title='f(x,y)' class='latex' /> subject to the constraint <img src='http://s.wordpress.com/latex.php?latex=g%28x%2Cy%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g(x,y)' title='g(x,y)' class='latex' />. The best way to show that this works is with an example so&#8230;</p>
<h3>Lets try this with an example</h3>
<p>Lets assume we have a line of the form<br />
<img src='http://s.wordpress.com/latex.php?latex=y%3D0.5%20x%20%2B%201&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y=0.5 x + 1' title='y=0.5 x + 1' class='latex' /> and we would like to find a point on this line that is closest to a given point <img src='http://s.wordpress.com/latex.php?latex=P%20%3D%20%283%2C2%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P = (3,2)' title='P = (3,2)' class='latex' /></p>
<p>We know the general form of the Lagrange multiplier which states that<br />
<img src='http://s.wordpress.com/latex.php?latex=f%28x%2Cy%29%20%3D%20-%5Clambda%5C%3A%20g%28x%2Cy%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(x,y) = -\lambda\: g(x,y)' title='f(x,y) = -\lambda\: g(x,y)' class='latex' /><br />
In English this simply means the that we need to find a point <img src='http://s.wordpress.com/latex.php?latex=X%20%3D%20%28x%2C%20y%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X = (x, y)' title='X = (x, y)' class='latex' /> where the functions <img src='http://s.wordpress.com/latex.php?latex=f%28x%2Cy%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(x,y)' title='f(x,y)' class='latex' /> and <img src='http://s.wordpress.com/latex.php?latex=g%28x%2Cy%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g(x,y)' title='g(x,y)' class='latex' /> give us vectors that point in the same direction. By multiplying one of the vectors with a constant <img src='http://s.wordpress.com/latex.php?latex=-%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='-\lambda' title='-\lambda' class='latex' /> we make both  vectors equal in length and direction. We could also write the equation above as<br />
<img src='http://s.wordpress.com/latex.php?latex=%5CLambda%28x%2Cy%2C%5Clambda%29%20%3D%20f%28x%2Cy%29%2B%5Clambda%5C%3A%20g%28x%2Cy%29%20%3D%200&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\Lambda(x,y,\lambda) = f(x,y)+\lambda\: g(x,y) = 0' title='\Lambda(x,y,\lambda) = f(x,y)+\lambda\: g(x,y) = 0' class='latex' /></p>
<p>Before we start we change our distance function to a squared distance function. So in this case <img src='http://s.wordpress.com/latex.php?latex=f%28x%2Cy%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(x,y)' title='f(x,y)' class='latex' /> would become<br />
<img src='http://s.wordpress.com/latex.php?latex=f%28x%2Cy%29%20%3D%20%28x-3%29%5E2%2B%28y-2%29%5E2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(x,y) = (x-3)^2+(y-2)^2' title='f(x,y) = (x-3)^2+(y-2)^2' class='latex' /><br />
We can do this because <img src='http://s.wordpress.com/latex.php?latex=f%28x%2Cy%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='f(x,y)' title='f(x,y)' class='latex' /> is just a function that needs to be minimised and for us it does not make a difference if we minimise the distance or the squared distance. We make this change as differentiating the squared distance function is much simpler and results in a system of linear equations. The function <img src='http://s.wordpress.com/latex.php?latex=g%28x%2Cy%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g(x,y)' title='g(x,y)' class='latex' /> remains the same.</p>
<p>So now we need to find<br />
<img src='http://s.wordpress.com/latex.php?latex=%5Cnabla_%7Bx%2Cy%2C%5Clambda%7D%5CLambda%28x%2Cy%2C%5Clambda%29%20%3D%200&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\nabla_{x,y,\lambda}\Lambda(x,y,\lambda) = 0' title='\nabla_{x,y,\lambda}\Lambda(x,y,\lambda) = 0' class='latex' /><br />
In this case<br />
<img src='http://s.wordpress.com/latex.php?latex=%5CLambda%28x%2Cy%2C%5Clambda%29%20%3D%20%28x-3%29%5E2%20%2B%20%28y-2%29%5E2%20%2B%20%5Clambda%5C%3A%280.5x-y%2B1%29%3D0&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\Lambda(x,y,\lambda) = (x-3)^2 + (y-2)^2 + \lambda\:(0.5x-y+1)=0' title='\Lambda(x,y,\lambda) = (x-3)^2 + (y-2)^2 + \lambda\:(0.5x-y+1)=0' class='latex' /><br />
We now need to find<br />
<img src='http://s.wordpress.com/latex.php?latex=%5Cfrac%7B%5Cdisplaystyle%5Cpartial%7D%7B%5Cdisplaystyle%5Cpartial%20x%7D%5CLambda%28x%2Cy%2C%5Clambda%29%20%3D%200&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\frac{\displaystyle\partial}{\displaystyle\partial x}\Lambda(x,y,\lambda) = 0' title='\frac{\displaystyle\partial}{\displaystyle\partial x}\Lambda(x,y,\lambda) = 0' class='latex' /><br />
<img src='http://s.wordpress.com/latex.php?latex=%5Cfrac%7B%5Cdisplaystyle%5Cpartial%7D%7B%5Cdisplaystyle%5Cpartial%20y%7D%5CLambda%28x%2Cy%2C%5Clambda%29%20%3D%200&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\frac{\displaystyle\partial}{\displaystyle\partial y}\Lambda(x,y,\lambda) = 0' title='\frac{\displaystyle\partial}{\displaystyle\partial y}\Lambda(x,y,\lambda) = 0' class='latex' /><br />
<img src='http://s.wordpress.com/latex.php?latex=%5Cfrac%7B%5Cdisplaystyle%5Cpartial%7D%7B%5Cdisplaystyle%20%5Cpartial%20%5Clambda%7D%5CLambda%28x%2Cy%5Clambda%29%20%3D%200&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\frac{\displaystyle\partial}{\displaystyle \partial \lambda}\Lambda(x,y\lambda) = 0' title='\frac{\displaystyle\partial}{\displaystyle \partial \lambda}\Lambda(x,y\lambda) = 0' class='latex' /><br />
After doing all the hairy math, we get<br />
<img src='http://s.wordpress.com/latex.php?latex=%5Cfrac%7B%5Cdisplaystyle%20%5Cpartial%7D%7B%5Cdisplaystyle%20%5Cpartial%20x%7D%5CLambda%28x%2Cy%2C%5Clambda%29%20%3D%200.5%5Clambda%2B2x-6%3D0&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\frac{\displaystyle \partial}{\displaystyle \partial x}\Lambda(x,y,\lambda) = 0.5\lambda+2x-6=0' title='\frac{\displaystyle \partial}{\displaystyle \partial x}\Lambda(x,y,\lambda) = 0.5\lambda+2x-6=0' class='latex' /><br />
<img src='http://s.wordpress.com/latex.php?latex=%5Cfrac%7B%5Cdisplaystyle%5Cpartial%7D%7B%5Cdisplaystyle%5Cpartial%20y%7D%5CLambda%28x%2Cy%2C%5Clambda%29%20%3D%20-%5Clambda%20%2B%202y%20-4%3D0&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\frac{\displaystyle\partial}{\displaystyle\partial y}\Lambda(x,y,\lambda) = -\lambda + 2y -4=0' title='\frac{\displaystyle\partial}{\displaystyle\partial y}\Lambda(x,y,\lambda) = -\lambda + 2y -4=0' class='latex' /><br />
<img src='http://s.wordpress.com/latex.php?latex=%5Cfrac%7B%5Cdisplaystyle%5Cpartial%7D%7B%5Cdisplaystyle%5Cpartial%20%5Clambda%20%7D%20%5CLambda%28x%2Cy%2C%5Clambda%29%20%3D0.5x-y%2B1%3D%200&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\frac{\displaystyle\partial}{\displaystyle\partial \lambda } \Lambda(x,y,\lambda) =0.5x-y+1= 0' title='\frac{\displaystyle\partial}{\displaystyle\partial \lambda } \Lambda(x,y,\lambda) =0.5x-y+1= 0' class='latex' /><br />
We now have a system of three linear equations with three unknowns. This should be fairly easy to solve using a number of methods. If we had used the distance function instead of the squared distance, we would have ended up with a system of non-linear equations which would not been so easy to solve.</p>
<p>Ok so after solving for <img src='http://s.wordpress.com/latex.php?latex=x%2Cy%2C%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x,y,\lambda' title='x,y,\lambda' class='latex' /> we get<br />
<img src='http://s.wordpress.com/latex.php?latex=x%3D%5Cfrac%7B14%7D%7B5%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x=\frac{14}{5}' title='x=\frac{14}{5}' class='latex' /><br />
<img src='http://s.wordpress.com/latex.php?latex=y%3D%5Cfrac%7B12%7D%7B5%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y=\frac{12}{5}' title='y=\frac{12}{5}' class='latex' /><br />
We are not really interested in <img src='http://s.wordpress.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\lambda' title='\lambda' class='latex' /> anymore, so we shall leave that out. So the point on the line is<br />
<img src='http://s.wordpress.com/latex.php?latex=X%3D%5Cleft%20%28%5Cfrac%7B14%7D%7B5%7D%2C%20%5Cfrac%7B12%7D%7B5%7D%20%5Cright%20%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X=\left (\frac{14}{5}, \frac{12}{5} \right )' title='X=\left (\frac{14}{5}, \frac{12}{5} \right )' class='latex' /></p>
<p>We can use several different methods to verify if this answer is correct. We can solve for the same point using the trigonometric method or we can check if the vectors <img src='http://s.wordpress.com/latex.php?latex=%5Coverrightarrow%7BPX%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\overrightarrow{PX}' title='\overrightarrow{PX}' class='latex' /> and <img src='http://s.wordpress.com/latex.php?latex=%5Coverrightarrow%7BAX%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\overrightarrow{AX}' title='\overrightarrow{AX}' class='latex' /> are orthonormal to each other. Here <img src='http://s.wordpress.com/latex.php?latex=A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A' title='A' class='latex' /> is just another point on our line. We shall use the latter method to verify our results. We already have<br />
<img src='http://s.wordpress.com/latex.php?latex=P%3D%283%2C%202%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P=(3, 2)' title='P=(3, 2)' class='latex' />, <img src='http://s.wordpress.com/latex.php?latex=X%3D%5Cleft%28%5Cfrac%7B14%7D%7B5%7D%2C%20%5Cfrac%7B12%7D%7B5%7D%5Cright%20%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X=\left(\frac{14}{5}, \frac{12}{5}\right )' title='X=\left(\frac{14}{5}, \frac{12}{5}\right )' class='latex' />. We can find <img src='http://s.wordpress.com/latex.php?latex=A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A' title='A' class='latex' /> by just setting <img src='http://s.wordpress.com/latex.php?latex=x%3D0&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x=0' title='x=0' class='latex' /> in line equation. So we get<br />
<img src='http://s.wordpress.com/latex.php?latex=A%3D%280%2C%201%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A=(0, 1)' title='A=(0, 1)' class='latex' /><br />
So we get<br />
<img src='http://s.wordpress.com/latex.php?latex=%5Coverrightarrow%7BAX%7D%20%3D%20%5Cleft%20%28%20-%5Cfrac%7B14%7D%7B5%7D%2C%20-%5Cfrac%7B7%7D%7B5%7D%20%5Cright%20%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\overrightarrow{AX} = \left ( -\frac{14}{5}, -\frac{7}{5} \right )' title='\overrightarrow{AX} = \left ( -\frac{14}{5}, -\frac{7}{5} \right )' class='latex' /><br />
<img src='http://s.wordpress.com/latex.php?latex=%5Coverrightarrow%7BPX%7D%20%3D%20%5Cleft%20%28%20%5Cfrac%7B1%7D%7B5%7D%2C%20-%5Cfrac%7B2%7D%7B5%7D%20%5Cright%20%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\overrightarrow{PX} = \left ( \frac{1}{5}, -\frac{2}{5} \right )' title='\overrightarrow{PX} = \left ( \frac{1}{5}, -\frac{2}{5} \right )' class='latex' /><br />
and&#8230;<br />
<img src='http://s.wordpress.com/latex.php?latex=%5Clangle%5Coverrightarrow%7BAX%7D%2C%5Coverrightarrow%7BPX%7D%5Crangle%3D%200&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\langle\overrightarrow{AX},\overrightarrow{PX}\rangle= 0' title='\langle\overrightarrow{AX},\overrightarrow{PX}\rangle= 0' class='latex' /><br />
<strong><br />
&#8230;or in plain English: IT WORKS!!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/193/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Key Xchanger &#8211; The bluetooth enabled password manager</title>
		<link>http://www.gbuffer.net/archives/185</link>
		<comments>http://www.gbuffer.net/archives/185#comments</comments>
		<pubDate>Mon, 22 Mar 2010 19:39:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bluetooth]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.gbuffer.net/?p=185</guid>
		<description><![CDATA[If I was going to put all my passwords in to one database, it better be protected by a good password - a very good one, one which I would not be able to remember. Of course this does not mean I do something stupid like write it on a piece of paper.Duh!]]></description>
			<content:encoded><![CDATA[<p>A while back I was looking for a good way to create a <strong>very</strong> strong password for my <a href="http://keepass.info/">KeePass Password Safe</a>. If I was going to put all my passwords in to one database, it better be protected by a good password &#8211; a very good one, one which I would not be able to remember. Of course this does not mean I do something stupid like write it on a piece of paper. Duh!</p>
<ul>
<li>A USB stick? Ah too simple.</li>
<li><a href="http://yubico.com/home/index/">YubiKey</a>? Sounded very cool initially, but only can work with one password at a time and another device to take care of. And it was USB &#8211; too much friction if I had to enter the password 5-10 times a day.</li>
<li>My phone: Ah perfect, it&#8217;s very personal. I never leave anywhere without it. WHich means it won&#8217;t be forgotten in my USB port when I&#8217;m out. And yeah, it&#8217;s got bluetooth (no shoving stuff in to usb ports).</li>
</ul>
<p>So I set out to make a bluetooth app that could exchange keys with KeePass. Head on to the <a href="/kxch">KeyXchanger </a>page to get more info and download it.</p>
<h3><strong>The stand alone password exchanger</strong></h3>
<p>Even if you do not use KeePass, you can still use Key Xchanger. The download contains a stand alone application that allows your computer to exchange passwords with your phone. Some features of Key Xchanger are&#8230;</p>
<ul>
<li>All passwords are stored on your phone encrypted.</li>
<li>Passwords on the phone are encrypted and can only be decrypted by an authorized computer</li>
<li>Your password is not compromised even if you loose your phone, since one needs to attack both your phone and computer. This is extremely unlikely to happen.</li>
<li>Passwords are never stored on the PC and are discarded immediately after being used.</li>
<li>You can enter passwords in to almost any application on windows</li>
</ul>
<p><strong>Due to the large number of phones out there I would appreciate it if you could tell me if the application worked for you.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/185/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keyboard remap &#8211; Change, disable or remap keys on Windows</title>
		<link>http://www.gbuffer.net/archives/163</link>
		<comments>http://www.gbuffer.net/archives/163#comments</comments>
		<pubDate>Wed, 10 Jun 2009 06:45:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[general computers]]></category>

		<guid isPermaLink="false">http://www.gbuffer.net/?p=163</guid>
		<description><![CDATA[Very often you need to disable or remap keys to new characters on your keyboard. This post explains how I did this without the need for any additional software running in background and a small guide on how you can do this on your own with software that is available free on the internet.]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;">The problem</span>: For a long time I have tried various methods to disable the worst key on the keyboard &#8211; the CAPS lock. In my opinion, it provides no real function and yet is placed in a position where it can be easily be pressed.</p>
<h3><a href="http://www.autohotkey.com/">AutoHotKey</a></h3>
<p><span style="text-decoration: underline;">Attempt 1</span>: Initially I disabled this key using an <strong><a href="http://www.autohotkey.com/">AutoHotKey</a></strong> script. But for some reason, the script would stop working and I would still find CAPS LOCK ON just when I was entering that password or something. Besides every new computer I went to needed to have AutoHotKey or a compiled .exe just for this purpose. Since I am fanatical about keeping 24&#215;7 background apps to a minimal, this was a big no no. And finally, even though I think AutoHotKey is a very useful app, I doubt it can be used as a full scale keyboard  remapper.</p>
<h3><a href="http://webpages.charter.net/krumsick/">KeyTweak</a></h3>
<p><span style="text-decoration: underline;">Attempt 2</span>: After being pushed over the edge with AutoHotKey&#8217;s incompetence in this area, my hunt for a new application continued. After some modified google search terms and fresh hope for luck, I came across <strong><a href="http://webpages.charter.net/krumsick/">KeyTweak</a></strong>, among others which included plain old <strong><a href="http://www.microsoft.com/whdc/archive/w2kscan-map.mspx">registry hacking</a></strong> and several incarnations or AutoHotKey. KeyTweak did just what I wanted. Once initial the configuration was made, it would do all the dirty registry hacing for me and I did not need any software to running in the background.</p>
<p>But now I was faced with a new problem, and this time it was caused due to personal circumstances. I had recently moved to a new country and this meant getting used to a whole new keyboard layout just for one new charecter &#8211; £. I think you know which country I am talking about. Initially I resisted by opening &#8216;Character Map&#8217; and copying the £ symbol from the table. But soon I realized that this was happening more often than not and I needed another solution.</p>
<p>Secondly even if I did give in and decide to get used to a new keyboard layout, I&#8217;d still be stuck with a US keyboard on my laptop. Changing that would be a fairly expensive affair and if I didn&#8217;t it would mean different keyboard layouts on different computers which can get very very irritating. I say this out of experience.</p>
<p>AutoHotKey &#8211; Although this could do the job, I was still against having an app running in the background just so that it could type the £ for me. But until I found a better solution, this was going to be the answer to the problem.<br />
KeyTweak &#8211; Although this could remap keys to others, somehow it was not able to find the £ character for me.</p>
<h3><a href="http://msdn.microsoft.com/en-gb/goglobal/bb964665.aspx">Microsoft Keyboard Layout Creator</a></h3>
<p><span style="text-decoration: underline;">Attempt 3</span>: So once again it was back to google. That is when I found &#8216;<strong><a href="http://msdn.microsoft.com/en-gb/goglobal/bb964665.aspx">Microsoft Keyboard Layout Creator</a></strong>&#8216;. From the depths of Microsoft&#8217;s lair lies this little known app that can do pretty much anything and everything you wanted. Basically you create a whole new keyboard layout, just like the professionals do.</p>
<p><img class="size-medium wp-image-164 alignnone" title="msklc" src="http://www.gbuffer.net/wp-content/uploads/msklc-300x146.png" alt="msklc" width="300" height="146" /></p>
<p><strong>A quick guide to using <a href="http://msdn.microsoft.com/en-gb/goglobal/bb964665.aspx">Microsoft Keyboard Layout Creator</a></strong></p>
<ol>
<li>So once you have done the obvious download and install, run the application.</li>
<li>If you are like me and want to remap change a few keys, then load your current keyboard layout by going to<br />
<strong>File </strong>&gt; <strong>Load existing keyboard</strong></li>
<li>If you are not sure which keyboard layout you are using, you can find this by going to<br />
<strong>Control Panel</strong> &gt; <strong>Regional and Language Options</strong> &gt; <strong>Languages</strong> (tab) &gt; <strong>Details</strong> (button)</li>
<li>Reconfigure the keys to the way you like it</li>
<li>Create a new installation package by going to<br />
<strong>Project</strong> &gt; <strong>Build DLL and Setup Package<br />
</strong>Follow the instructions and create a installation package. Remember to give it a name that you can identify later.</li>
<li>Install the new layout using the installation package</li>
<li>Go to<br />
<strong>Control Panel</strong> &gt; <strong>Regional and Language Options</strong> &gt; <strong>Languages</strong> (tab) &gt; <strong>Details</strong> (button)<br />
Beside the tree view, click <strong>Add&#8230;</strong> and select the new keyboard layout that you just created.</li>
<li>Activate it by selecting the new layout from the drop down menu where is says<br />
&#8216;<strong>Default input language</strong>&#8216;<br />
Alternatively, you can switch between this layout and your old layout by enabling the language bar.</li>
</ol>
<p>I hope this guide helps you get the most out of your keyboard.</p>
<p><em>All links are verified to be valid at the time of writing this post. If any of the links in this article or anywhere else on my blog are broken, let me know via the comments and I shall do my best to fix it.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/163/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TerminateApp: Close, don&#8217;t kill that app</title>
		<link>http://www.gbuffer.net/archives/152</link>
		<comments>http://www.gbuffer.net/archives/152#comments</comments>
		<pubDate>Mon, 11 May 2009 19:38:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.gbuffer.net/?p=152</guid>
		<description><![CDATA[Recently when automating certain tasks, I came across the need for a command line app that would close windows applications in a clean way. After a lot of searching I was surprised not to find something to do this simple task. Yes there a lot of tools to kill an application, but that was not [...]]]></description>
			<content:encoded><![CDATA[<p>Recently when automating certain tasks, I came across the need for a command line app that would close windows applications in a clean way. After a lot of searching I was surprised not to find something to do this simple task. Yes there a lot of tools to kill an application, but that was not what I was looking for.</p>
<p><span style="text-decoration: underline;">Why?</span><br />
Well, a lot of applications perform a lot of important tasks before they close. These range from saving settings, asking you to save files, releasing hooks. Whatever the task may be, if you killing an application stop it dead in it&#8217;s tracks and the app does not have a chance to perform these tasks.</p>
<p>So TerminateApp is the result of this necessity.<br />
You can specify the process by it&#8217;s name or by it&#8217;s process ID. If you really are impatient, you can even kill the application if the application refuses to terminate within a given amount of time.</p>
<p><span style="text-decoration: underline;">How does it work?<br />
</span>TerminateApp sends a WM_QUIT message to all window handles within a specified process. So it will only work for applications that process the WM_QUIT message. This worked fine for the several applications I tested it on, but I cannot guarantee it works on all the apps out there. This would depend on the way the app has been written.</p>
<p>[<a href="https://files.getdropbox.com/u/757277/www/gbuffer/niknaks/ta/TerminateApp.zip"><img class="alignnone size-full wp-image-153" title="compress" src="http://www.gbuffer.net/wp-content/uploads/compress.png" alt="compress" width="16" height="16" /><strong> Download TerminateApp</strong></a>]<br />
[<a title="Source code" href="https://files.getdropbox.com/u/757277/www/gbuffer/niknaks/ta/TerminateAppSrc.zip"><img class="alignnone size-full wp-image-154" title="page_white_cplusplus" src="http://www.gbuffer.net/wp-content/uploads/page_white_cplusplus.png" alt="page_white_cplusplus" width="16" height="16" /> Download Source Code</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/152/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vector Texture v1</title>
		<link>http://www.gbuffer.net/archives/136</link>
		<comments>http://www.gbuffer.net/archives/136#comments</comments>
		<pubDate>Fri, 27 Mar 2009 14:06:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[demos]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.gbuffer.net/?p=136</guid>
		<description><![CDATA[It&#8217;s been some time since anything technical has been posted here. Been spending my time building up a stronger base since the top seemed a little wobbly. Got a new demo out today. It&#8217;s something that some people (including me) call vector textures. A very interesting technique that uses the existing texture resizing methods implemented [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been some time since anything technical has been posted here. Been spending my time building up a stronger base since the top seemed a little wobbly.</p>
<p>Got a new demo out today. It&#8217;s something that some people (including me) call vector textures. A very interesting technique that uses the existing texture resizing methods implemented on the GPU. These days it&#8217;s hard to find graphics techniques that manage really makes use of everything the GPU provides us with. What&#8217;s even nicer is that this technique could improve existing methods of rendering things like text and could even be extended to rendering blades of grass or leaves on a tree where the possibility of zooming in to a leaf is very real.</p>
<p>Go ahead, <a href="/vector-textures">read more about it and download the demo here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/136/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chamrajpet Charles</title>
		<link>http://www.gbuffer.net/archives/113</link>
		<comments>http://www.gbuffer.net/archives/113#comments</comments>
		<pubDate>Wed, 10 Dec 2008 22:44:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[leisure]]></category>

		<guid isPermaLink="false">http://www.gbuffer.net/?p=113</guid>
		<description><![CDATA[Hey, What you doing child&#8230; Loafing around the internet like a college boy outside a girl&#8217;s college. For those of you who don&#8217;t know who Chamrajpet Charles is, I&#8217;ll forgive you. If you have not heard of him, I seriously doubt you will be able to fully appreciate this post For the rest, you will [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Hey, What you doing child&#8230;</strong><br />
Loafing around the internet like a college boy outside a girl&#8217;s college.</p>
<p>For those of you who don&#8217;t know who Chamrajpet Charles is, I&#8217;ll forgive you. If you have not heard of him, I seriously doubt you will be able to fully appreciate this post</p>
<p>For the rest, you will get some upper cuts on your kidneys if you lie only. So for all CC fans out there, here are some rips that will make you feel at home, where ever you are</p>
<p>He makes me laugh no matter what my mood. Feel free to download them to your computer. And now for my track collection&#8230;</p>
<p><span id="more-113"></span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="7%">20 20</td>
<td width="300"></td>
<td><a href="http://www.gbuffer.net/wp-content/audio/cc/2020.mp3">Download</a></td>
</tr>
<tr>
<td width="7%">Accountant</td>
<td width="300"></td>
<td><a href="http://www.gbuffer.net/wp-content/audio/cc/Accountatnt.mp3">Download</a></td>
</tr>
<tr>
<td width="7%">Cricket Fever</td>
<td width="300"></td>
<td><a href="http://www.gbuffer.net/wp-content/audio/cc/CricketFever.mp3">Download</a></td>
</tr>
<tr>
<td width="7%">Mobile Ban</td>
<td width="300"></td>
<td><a href="http://www.gbuffer.net/wp-content/audio/cc/MobileBan.mp3">Download</a></td>
</tr>
<tr>
<td width="7%">Petrol Strike</td>
<td width="300"></td>
<td><a href="http://www.gbuffer.net/wp-content/audio/cc/PetrolStrike.mp3">Download</a></td>
</tr>
<tr>
<td width="7%">President Rule</td>
<td width="300"></td>
<td><a href="http://www.gbuffer.net/wp-content/audio/cc/PresidentRule.mp3">Download</a></td>
</tr>
<tr>
<td width="7%">Metro Fever</td>
<td width="300"></td>
<td><a href="http://www.gbuffer.net/wp-content/audio/cc/MetroFever.mp3">Download</a></td>
</tr>
<tr>
<td width="7%">Yellow Fever</td>
<td width="300"></td>
<td><a href="http://www.gbuffer.net/wp-content/audio/cc/YellowFever.mp3">Download</a></td>
</tr>
</tbody>
</table>
<p>I wish I was still in Bangalore. I would have recorded many more from the radio. Hey all you buggers out there in Bangalore, if anyone has any more links / recordings, send them to me or leave a comment below. Or else I will have to give two cracks on your elbows.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/113/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
<enclosure url="http://www.gbuffer.net/wp-content/audio/cc/2020.mp3" length="559300" type="audio/mpeg" />
<enclosure url="http://www.gbuffer.net/wp-content/audio/cc/Accountatnt.mp3" length="521626" type="audio/mpeg" />
<enclosure url="http://www.gbuffer.net/wp-content/audio/cc/CricketFever.mp3" length="497420" type="audio/mpeg" />
<enclosure url="http://www.gbuffer.net/wp-content/audio/cc/MobileBan.mp3" length="610988" type="audio/mpeg" />
<enclosure url="http://www.gbuffer.net/wp-content/audio/cc/PetrolStrike.mp3" length="440272" type="audio/mpeg" />
<enclosure url="http://www.gbuffer.net/wp-content/audio/cc/PresidentRule.mp3" length="525266" type="audio/mpeg" />
<enclosure url="http://www.gbuffer.net/wp-content/audio/cc/MetroFever.mp3" length="496692" type="audio/mpeg" />
<enclosure url="http://www.gbuffer.net/wp-content/audio/cc/YellowFever.mp3" length="344540" type="audio/mpeg" />
		</item>
		<item>
		<title>Water you can swim in</title>
		<link>http://www.gbuffer.net/archives/93</link>
		<comments>http://www.gbuffer.net/archives/93#comments</comments>
		<pubDate>Sun, 19 Oct 2008 09:47:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[demos]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.gbuffer.net/?p=93</guid>
		<description><![CDATA[Water you can swim in&#8230; Well only virtually This is my very first graphical demo built on a excellent open source framework called G3D. Demo is based on two chapters in the ShaderX book. &#8220;Rendering Ocean Water&#8221; by John Isidoro, Alex Vlachos, Chris Brennan And &#8220;Rippling Refractive and Reflective Water&#8221; by Alex Vlachos, John Isidoro [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gbuffer.net/demos"><img alt="Water!!!" src="http://www.gbuffer.net/files/G3D/demos/water/small.jpg" title="Water Demo" width="225" height="176" /></a> Water you can swim in&#8230; Well only virtually <img src='http://www.gbuffer.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  This is my very first graphical demo built on a excellent open source <a href="http://g3d-cpp.sourceforge.net/">framework called G3D</a>.</p>
<p>Demo is based on two chapters in the <a href="http://www.shaderx.com/">ShaderX</a> book.<br />
&#8220;Rendering Ocean Water&#8221;<br />
by John Isidoro, Alex Vlachos, Chris Brennan<br />
And<br />
&#8220;Rippling Refractive and Reflective Water&#8221;<br />
by Alex Vlachos, John Isidoro and Chris Oat</p>
<p>Features include</p>
<ol>
<li>Realtime vertex displacement</li>
<li>Full control over speed, wave direction, amplitude and frequency</li>
<li>Additional detailing via two normal maps</li>
<li>Fake refractions that look real</li>
<li>Real time reflections or reflections via environment maps</li>
<li>Fully configurable water color via texture maps</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/93/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Welcome to GBuffer.Net 2.0</title>
		<link>http://www.gbuffer.net/archives/66</link>
		<comments>http://www.gbuffer.net/archives/66#comments</comments>
		<pubDate>Sat, 11 Oct 2008 13:27:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://www.gbuffer.net/?p=66</guid>
		<description><![CDATA[Faster, cleaner, better&#8230; This upgrade has been long overdue, but there are a lot of other things to consider. The blog is now powered by WordPress. I did consider a new version of Drupal, but WordPress seemed a lot cleaner and more widely supported. Pictures and albums are now on Flickr.com. ImageShack.us was not really [...]]]></description>
			<content:encoded><![CDATA[<p>Faster, cleaner, better&#8230;</p>
<p>This upgrade has been long overdue, but there are a lot of other things to consider. The blog is now powered by WordPress. I did consider a new version of Drupal, but WordPress seemed a lot cleaner and more widely supported.</p>
<p>Pictures and albums are now on <a href="http://flickr.com/photos/redeemer/">Flickr.com</a>. ImageShack.us was not really managing my gigabytes of pictures too well and my decision to self manage the pictures backfired.</p>
<p>There have been some posts that have been brewing in my head, but have been put off waiting for this upgrade to happen. So now that it has happened, they will see the light of day fairly soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/66/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Square root without sqrt</title>
		<link>http://www.gbuffer.net/archives/30</link>
		<comments>http://www.gbuffer.net/archives/30#comments</comments>
		<pubDate>Mon, 17 Mar 2008 16:12:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://pacman/testrun/?p=30</guid>
		<description><![CDATA[A few months back, I was given an interesting project to work on in an interview test. The test required me to build a small particle system for the Nintendo DS, using the homebrew tool chain. Well I don&#8217;t know if I was stupid or just plain blind, but I was unable to find a [...]]]></description>
			<content:encoded><![CDATA[<p>A few months back, I was given an interesting project to work on in an interview test. The test required me to build a small particle system for the Nintendo DS, using the homebrew tool chain. Well I don&#8217;t know if I was stupid or just plain blind, but I was unable to find a sqrt in their standard math.h include file. Posting questions on a forum resulted in no replies and time was running short. I had only about a week to make my submission. So I decided to write my own implementation. After all I remember doing this in high scool.</p>
<p><strong>The old school method&#8230;</strong></p>
<p>As usual I headed over to google and after a little searching I found it on <a title="Square root algorithm" href="http://www.geocities.com/cnowlen/Cathy/Emat4680/Squareroot.htm">this website</a>. Well this was exactly what I was looking for, but unfortunately it required too much guessing at every step. Now as we all know computers are not good at guessing. All hopes of implementing a square root function quickly evaporated.</p>
<p>Next day in office, with some help from my coleague Ashwini Kumar, we came up with a very promising solution.</p>
<p>We found something interesting about the patterns a square root takes</p>
<p>sqrt(1.0) = 1.0<br />
sqrt(10.0) = 3.1622<br />
sqrt(100.0) = 10.0<br />
sqrt(1000.0) = 31.622</p>
<p>Now for those of you who have not realized yet, sqrt(1000.0) = sqrt(10.0) * 10.0</p>
<p>Well this could work pretty well and all we needed to do then is just generate a look up table of the first 100 numbers and then just do a multiplication based on it&#8217;s 10th power. So I came up with this code&#8230;</p>
<pre class="brush: c++">
// LUT for square roots below 100. Takes 396 bytes

const static float SQRT_LUT[] =
{
       1.000000f,      1.414214f,      1.732051f,      2.000000f,
       2.236068f,      2.449490f,      2.645751f,      2.828427f,
       3.000000f,      3.162278f,      3.316625f,      3.464102f,
       3.605551f,      3.741657f,      3.872983f,      4.000000f,
       4.123106f,      4.242640f,      4.358899f,      4.472136f,
       4.582576f,      4.690416f,      4.795832f,      4.898980f,
       5.000000f,      5.099020f,      5.196152f,      5.291502f,
       5.385165f,      5.477226f,      5.567764f,      5.656854f,
       5.744563f,      5.830952f,      5.916080f,      6.000000f,
       6.082763f,      6.164414f,      6.244998f,      6.324555f,
       6.403124f,      6.480741f,      6.557438f,      6.633250f,
       6.708204f,      6.782330f,      6.855655f,      6.928203f,
       7.000000f,      7.071068f,      7.141428f,      7.211102f,
       7.280110f,      7.348469f,      7.416198f,      7.483315f,
       7.549834f,      7.615773f,      7.681146f,      7.745967f,
       7.810250f,      7.874008f,      7.937254f,      8.000000f,
       8.062258f,      8.124039f,      8.185352f,      8.246211f,
       8.306623f,      8.366600f,      8.426149f,      8.485281f,
       8.544003f,      8.602325f,      8.660254f,      8.717798f,
       8.774964f,      8.831760f,      8.888194f,      8.944272f,
       9.000000f,      9.055386f,      9.110434f,      9.165152f,
       9.219544f,      9.273619f,      9.327379f,      9.380832f,
       9.433981f,      9.486833f,      9.539392f,      9.591663f,
       9.643651f,      9.695360f,      9.746795f,      9.797959f,
       9.848858f,      9.899495f,      9.949874f,
} ;

float SqrtLUT(const float fNum)
{
     int      nIdx ;
     int      nApproxLog = 0 ;
     float    fCopy = fNum ;
     float    fMultiplier = 1.0f, fDivider = 0.1f ;

     if (fNum &lt; 100.0f &amp;&amp; fNum &gt;= 1.0f) // Use LUT

     {
         nIdx = static_cast&lt;int&gt;(fNum) ;
         if (nIdx)
         {
             --nIdx ;
             return SQRT_LUT[nIdx] ;
         }
     }

     // Number is above 100, bring it down and just multiply the answer

     if (fNum &gt;= 100.0f)
     {
         while (fCopy &gt; 1.0f)
         {
             fCopy *= 0.1f ;

             if ((nApproxLog &amp; ~3) &amp;&amp; (nApproxLog &amp; 1))
             {
                 fMultiplier *= 10.0f ;
                 fDivider *= fDivider ;
             }

             ++nApproxLog ;
         }
     }
     // Number is below 1. Bring it with in the 1-100 range

     else
     {
         // ...
         // Something very similar to the if block above
         // ...
     }

     return GuessSqrt(fNum * fDivider) * fMultiplier ;
}
</pre>
<p>This worked really well for numbers under 10^3, but as the numbers grew larger the errors started growing larger and larger. Even a LUT of doubles instead of floats just offset the errors to a slightly larger numbers.</p>
<p>Time to look for a new solution&#8230;</p>
<p><strong>The Babylonian Method</strong></p>
<p>A quick recap of old college textbooks revealed a suprising simple method. This method only produces an estimate, but the accuracy of the estimate grows rapidly on every iteration. For those of you who need a quick recap of the algorithm, here is a recap from <a href="http://pballew.net/oldsqrt.htm">http://pballew.net/oldsqrt.htm</a></p>
<p>1) Guess a number for the square root<br />
2) Divide the number by the guess<br />
3) Average the original guess and the new guess<br />
4) make this average value your new guess and<br />
5) Go back to step 2 if the accuracy of the result is not satifactory&#8230;</p>
<p>The problem with this method is that it still requires a guess like the old scool method, but this requires a guess only once and the rest of the guesses are relatively small calculations which don&#8217;t need any sort of loop. Besides with our LUT method we can now provde a fairly accurate guess relatively fast. So the initial implementation looked something like this&#8230;</p>
<pre class="brush: c++">
const static int gIterations 20 ;

float mSqrt(const float fNum)
{
 float x1 ;

 x1 = GuessSqrt(fNum) ; // Just uses the LUT function mentioned above

 for (int i=0; i&lt;gIterations; ++i)
 {
 x1 = ( ( fNum / x1 ) + x1 ) * 0.5f ;
 }
}
</pre>
<p>After a little trial and error I decided the the number of iterations are best kept at 12.</p>
<p><strong>The end result</strong></p>
<p>Turns out it aint that bad. On my old 1.6Ghz system this implementation is only 0.002 seconds (approximately) slower than sqrt() when calculating 10000 square roots.</p>
<p>My implementation (available in the attachment below) has a much more complicated implentation that does a loop unwind using C++ templates. How else can I justify spending large amounts of time spent trying to understand <a href="http://erdani.org/">Andrei&#8217;s</a> book, <a title="Modern C++ design" href="http://erdani.org/book/main.html">Modern C++ design</a> . As of now that book has become my latest programming fad. <img src='http://www.gbuffer.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You can download the VS.Net 2005 project of my implementation (Attached at the end of this blog entry). The .cpp file has code to check the speed and accuaracy of the results against the standard CRT sqrt function. Most of the code that you should be interested in, is in main.cpp. If you want to use the function in your own project, just copy everything except the main function in main.cpp</p>
<p>Until next time</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/30/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Download HBO&#8217;s new series &#8216;In Treatment&#8217; from outside the USA</title>
		<link>http://www.gbuffer.net/archives/32</link>
		<comments>http://www.gbuffer.net/archives/32#comments</comments>
		<pubDate>Sun, 09 Mar 2008 04:50:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">http://pacman/testrun/?p=32</guid>
		<description><![CDATA[For the impatient&#8230; head over directly to the direct download links For those of you who don&#39;t know, HBO recently put the first 15 episodes of their new show &#39;In Treatment&#39; online. That was good news so the first thing I did was head over there and checkout their 2 min preview. Looked quite interesting, [...]]]></description>
			<content:encoded><![CDATA[<p>For the impatient&#8230; head over directly to the <a href="#ddl"><font color="#999999">direct download links</font></a></p>
<p>For those of you who don&#39;t know, HBO recently put the first 15 episodes of their new show &#39;In Treatment&#39; online. That was good news so the first thing I did was head over there and checkout their 2 min preview. Looked quite interesting, except for the part where the full episodes can&#39;t be watched from my country (India), or for that matter any country other than USA [Haven&#39;t confirmed this yet]. </p>
<p>Now this has got to be one of the lamest attempts to block people from outside USA watching your shows. This is the probably one of the biggest reasons thepiratebay is doing so well. Besides this goes directly against one of my most fundamental beliefs that once information is online anyone in the world should be able to access it.<!--break--> Sure I could catch the episodes on youtube, but then youtube has never been my favorite for offering such low quality videos without giving you a choice. HBOs online stream was much bigger and was on the border line of acceptable. So this is what I wanted and this is what I was going to get.</p>
<p>The first step is to find the .flv files they were linking to. I thought that if I get a direct link to the .flv file I may not have to even watch it online.</p>
<p>Unfortunately I realized that the .flv file was actually a redirect script, to redirect the person based on his IP address. This is another lame attempt to block people. So I just went and found a proxy in USA and managed to get the direct links to the actual .flv file. Turns out that once you have the direct links to the files, you don&#39;t even need to be behind a proxy. Might as well make HBO pay for the bandwidth.</p>
<p>In fact even if you are in USA, this will probably be a more convenient method of watching the show, as you can just queue up all the episodes in your favorite download manager and then watch it in your favorite media player.</p>
<p>And before I forget, probably the reason you came here, the&#8230;
<p><a name="ddl" title="ddl"></a><font size="4">Direct download links</font></p>
<p><strong>Laura:</strong><br /> <a href="http://hbo-29.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_1/in_treat_ep1_laura.flv">Week 1</a><br /> <a href="http://hbo-79.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_2/in_treat_ep6_laura.flv">Week 2</a><br /> <a href="http://hbo-20.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_3/in_treat_ep11_laura.flv">Week 3</a></p>
<p><strong> Alex:</strong><br /> <a href="http://hbo-45.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_1/in_treat_ep1_alex.flv">Week 1</a><br /> <a href="http://hbo-97.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_2/in_treat_ep7_alex.flv">Week 2</a><br /> <a href="http://hbo-10.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_3/in_treat_ep12_alex.flv">Week 3</a></p>
<p><strong> Sophie:</strong><br /> <a href="http://hbo-70.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_1/in_treat_ep1_sophie.flv">Week 1</a><br /> <a href="http://hbo-16.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_2/in_treat_ep8_sophie.flv">Week 2</a><br /> <a href="http://hbo-62.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_3/in_treat_ep13_sophie.flv">Week 3</a></p>
<p><strong> Jake and amy:</strong><br /> <a href="http://hbo-02.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_1/in_trt_ep1_jake_amy.flv">Week 1</a><br /> <a href="http://hbo-80.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_2/in_treat_ep9_jake_amy.flv">Week 2</a><br /> <a href="http://hbo-89.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_3/in_treat_ep14_jake_amy.flv">Week 3</a><br /> <strong><br /> Paul and Gina:</strong><br /> <a href="http://hbo-66.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_1/in_treat_ep1_gina.flv">Week 1</a><br /> <a href="http://hbo-55.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_2/in_treat_ep10_gina.flv">Week 2</a><br /> <a href="http://hbo-93.vo.llnwd.net/u/d1/hbovideo/in_treat/full_episodes/week_3/in_treat_ep15_gina.flv">Week 3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gbuffer.net/archives/32/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
