<?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>Polymath Programmer &#187; Mathematics</title>
	<atom:link href="http://polymathprogrammer.com/category/mathematics/feed/" rel="self" type="application/rss+xml" />
	<link>http://polymathprogrammer.com</link>
	<description>Where entrepreneurship, mathematics and programming meet</description>
	<lastBuildDate>Wed, 23 May 2012 16:09:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Does the point lie on the Bezier curve?</title>
		<link>http://polymathprogrammer.com/2012/04/03/does-point-lie-on-bezier-curve/</link>
		<comments>http://polymathprogrammer.com/2012/04/03/does-point-lie-on-bezier-curve/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 14:06:57 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[bezier]]></category>
		<category><![CDATA[curve]]></category>
		<category><![CDATA[degree]]></category>
		<category><![CDATA[dimensionality]]></category>
		<category><![CDATA[point]]></category>
		<category><![CDATA[polynomial]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=3497</guid>
		<description><![CDATA[Someone recently asked me how to tell if a point lies on a Bezier curve. For the purposes of discussion, it&#8217;s a quadratic Bezier curve and all 3 control points are known (or the start and end points and the 1 control point if you prefer). You can read more about the reverse process of [...]]]></description>
			<content:encoded><![CDATA[<p>Someone recently asked me how to tell if a point lies on a Bezier curve.</p>
<p>For the purposes of discussion, it&#8217;s a quadratic Bezier curve and all 3 control points are known (or the start and end points and the 1 control point if you prefer). You can read more about the <a href="http://polymathprogrammer.com/2010/05/03/reverse-engineering-quadratic-bezier-curves/">reverse process of finding the control points here</a>, which is the reference point of that person&#8217;s question.</p>
<p>The answer is actually straightforward. <strong>Substitute everything into the Bezier curve equation and solve for t</strong>. Here&#8217;s the quadratic Bezier equation:<br />
B(t) = (1-t)^2 * p0 + 2(1-t)t * p1 + t^2 * p2</p>
<p>Let&#8217;s say p0 is [1,1] and p1 is [1.5,4.5] and p2 is [2,3]. We&#8217;ll keep the points in 2 dimensions to keep the maths working less cumbersome. And let&#8217;s say the point you want to check is [1.8,3.4]. We substitute all the points into the equation, and we get this:</p>
<p>[1.8,3.4] = (1-t)^2 * [1,1] + 2(1-t)t * [1.5,4.5] + t^2 * [2,3]</p>
<p>I know, it doesn&#8217;t look pretty. But hey, we&#8217;re doing this by hand. If you&#8217;re writing code to generalise the solution, the code will probably look just a little uglier, but the solution will come out faster. Like probably instantly given the current modern processors.</p>
<p>Because we&#8217;re dealing with 2 dimensional points, that equation splits into 2 separate equations (with scalars instead of vectors as coefficients), like so:<br />
1.8 = (1-t)^2 * 1 + 2(1-t)t * 1.5 + t^2 * 2<br />
3.4 = (1-t)^2 * 1 + 2(1-t)t * 4.5 + t^2 * 3</p>
<p>If you have 3 dimensional points, you&#8217;d have 3 equations. Note that even then, the degree of your equations remains as 2. The degree of the Bezier curve is independent of the number of dimensions you&#8217;re working with.</p>
<p>If you simplify<br />
1.8 = (1-t)^2 * 1 + 2(1-t)t * 1.5 + t^2 * 2</p>
<p>You get t = 0.8. It so happens that in this case, there&#8217;s only one solution.</p>
<p>If you simplify<br />
3.4 = (1-t)^2 * 1 + 2(1-t)t * 4.5 + t^2 * 3</p>
<p>You get<br />
5*t^2 &#8211; 7*t + 2.4 = 0</p>
<p>and after solving for that, you get t = 0.6 or t = 0.8 (you&#8217;re a smart person, you know how to solve a quadratic equation, right?)</p>
<p>Now, the solution t=0.8 appears in the solution sets of both equations. Therefore, the point [1.8,3.4] lies on the Bezier curve. In fact, t=0.8 is the t value.</p>
<h3>Multiple solutions</h3>
<p>What if you get multiple t values appearing in multiple solution sets of equations?</p>
<p>Consider the case where p0 is [1,1], p1 is [2,3], and p2 is [1,1]. Notice that the start and end points are the same point. Let&#8217;s say you want to know if the point [1,1] lies on the curve (yes I know it&#8217;s the same point). Substituting all the points, we get:</p>
<p>[1,1] = (1-t)^2 * [1,1] + 2(1-t)t * [2,3] + t^2 * [1,1]</p>
<p>This gives us the 2 equations:<br />
1 = 1 &#8211; 2*t + t^2 + 4*t &#8211; 4*t^2 + t^2<br />
1 = 1 &#8211; 2*t + t^2 + 6*t &#8211; 6*t^2 + t^2</p>
<p>They simplify to:<br />
2*t^2 &#8211; 2*t = 0<br />
4*t^2 &#8211; 4*t = 0</p>
<p>Hey presto! The solution set is t=0 or t=1 for both equations. Therefore, the point [1,1] lies on the curve. In fact, it lies on the curve where t=0 or t=1. And t=0 and t=1 happens to coincide with the start and end points respectively.</p>
<p>The whole point (haha!) is that, as long as you have at least one value of t that appears in the solution sets of <em>all</em> the equations, then said point you&#8217;re checking lies on the curve.</p>
<h3>Higher degree Bezier curves</h3>
<p>This is a toughie. If you have a cubic Bezier curve, then you&#8217;re solving a degree 3 polynomial (of t). If you have a Bezier curve of degree N, then you&#8217;re solving a degree N polynomial.</p>
<p>There are algorithms to solve generic degree polynomials, but they are out of scope here. Assuming the highest degree of Bezier curves you&#8217;ll ever work with is 3 (cubic), then this <a href="http://en.wikipedia.org/wiki/Cubic_function">Wikipedia article on cubic functions</a> will help. Remember, cubic Bezier curve equations are still cubic equations.</p>
<h3>Higher dimensionality</h3>
<p>The number of dimensions you&#8217;re working with determines the number of equations you need to solve. If you&#8217;re working with 5 dimensional points, then you need to solve for 5 equations.</p>
<p>For example, if you&#8217;re working with cubic Bezier curves and using 5 dimensional points, then you need to solve 5 cubic functions. You will have possibly 3 (unique) t values for each equation. Let&#8217;s say your solution sets are as follows:<br />
t = -1, 3, 5<br />
t = 0, 1, 3<br />
t = -2, 2, 3<br />
t = 3, 3, 4 (yay repeated values!)<br />
t = 3, 6, 8</p>
<p>The value t=3 appears in all 5 sets of solutions, therefore your point lies on the curve.</p>
<h3>Keep it real</h3>
<p>In the process of solving your equations, there&#8217;s a possibility that you might get imaginary solutions. You know, those involving the square root of -1. Dismiss them.</p>
<p>Your Bezier curve is in the real world. The point you&#8217;re checking must therefore also lie in the real world.</p>
<p>Unless you&#8217;re working with some abstract imaginary Bezier curves on an advanced maths paper. Then good luck to you! The logic above for solving still applies.</p>
<h3>Actual applications</h3>
<p>When applying the above, you don&#8217;t usually get nice numbers like [1.8,3.4] lying on the curve with t=0.8. You get numbers with lots of numbers behind the decimal point that seems to continue forever. <strong>You don&#8217;t get exact values.</strong></p>
<p>What if you get a t=0.798 for one equation, and t=0.802 for another equation?</p>
<p>Use your common sense. Set an error margin for what is acceptable.</p>
<p>My suggestion is to NOT use the values of t to check for the margin. Substitute the values of t into the equation, and then check the <em>points</em> if they&#8217;re within the error margin.</p>
<p>This means you don&#8217;t check the difference between t=0.798 and t=0.802, which is 0.04. Is 0.04 within your error margin? Maybe. But you&#8217;re not checking for this.</p>
<p>You substitute t=0.798 and t=0.802 into the equation, and you get 2 points: [1.798,3.40198] and [1.802,3.39798]</p>
<p>Then you say, &#8220;Are these points close enough that I consider them to be the same point?&#8221; Use whatever you think is appropriate. I think the Euclidean distance norm works fine. Then check if that &#8220;close enough&#8221; criteria is within your error margin.</p>
<p>If you&#8217;re checking for [1.8,3.4], then ask yourself, &#8220;Is [1.8,3.4] close enough to [1.798,3.40198]? And is [1.8,3.4] close enough to [1.802,3.39798]?&#8221;</p>
<p>Obviously, doing this by hand sucks big time. Good thing you&#8217;re a programmer.</p>
<p>So in case you didn&#8217;t know, you can ask me specific questions or pointers to some problem you&#8217;re facing. I&#8217;m offering <a href="http://polymathprogrammer.com/code-help-session/">Code Help Session</a>. Be it peer review, pointers on how to get started or going, explanations of code. Whatever. Just letting you know.</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2012/04/03/does-point-lie-on-bezier-curve/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimal width and height after image rotation</title>
		<link>http://polymathprogrammer.com/2012/02/22/optimal-width-height-after-image-rotation/</link>
		<comments>http://polymathprogrammer.com/2012/02/22/optimal-width-height-after-image-rotation/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 13:06:53 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[best-fit]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[image rotation]]></category>
		<category><![CDATA[optimal]]></category>
		<category><![CDATA[rotation]]></category>
		<category><![CDATA[symmetry]]></category>
		<category><![CDATA[width]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=3373</guid>
		<description><![CDATA[A while ago, a blog reader Fabien sent me some code (you can read it here. Thanks Fabien!). The PHP code is a modification of my image rotation code with some upgrades. I was looking through his code (French variable names!) and was puzzled by the initial section. I believe he based his code on [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, a blog reader Fabien sent me some code (<a href="http://polymathprogrammer.com/2012/02/02/image-rotation-bilinear-interpolation-alpha-progressive-borders/">you can read it here</a>. Thanks Fabien!). The PHP code is a modification of my image rotation code with some upgrades.</p>
<p>I was looking through his code (French variable names!) and was puzzled by the initial section. I believe he based his code on my code where the <a href="http://polymathprogrammer.com/2010/04/05/image-rotation-with-bilinear-interpolation-and-no-clipping/">resulting image wasn&#8217;t clipped after rotation</a>, meaning the whole image was still in the picture/bitmap (though rotated).</p>
<p>In that piece of code, I just used the diagonal length of the image (from top-left corner to bottom-right corner) as the final length and breadth of the resulting image. This gave the simplest resulting image dimension without doing complicated maths calculations (a square in this case).</p>
<p>However, <strong>what if you want to know the optimal width and height of the resulting image after rotation?</strong> Meaning the best-fit width and height that just manages to contain the resulting rotated image. For that, I need to tell you some basic trigonometry and geometry.</p>
<p><img src="http://polymathprogrammer.com/images/blog/201202/imgrotationwidthheight.png" alt="Image rotation, optimal width and height" /></p>
<p>Suppose you have a rectangle with L as the length and H as the height. It is rotated t angles. I&#8217;m not going to explain the maths behind it. It involves complementary angles, supplementary angles, rotation symmetry and trigonometry with sines and cosines. Convince yourself that the diagram is true.</p>
<p>So after rotating t angles, the optimal width is <strong>L * cos(t) + H * cos(90 &#8211; t)</strong></p>
<p>The optimal height is <strong>L * sin(t) + H * sin(90 &#8211; t)</strong></p>
<p>Short digression: You might notice that any lengths that lie parallel to the x-axis usually involve cosines, and lengths that lie parallel to the y-axis usually involve sines. It&#8217;s just the way trigonometry works.</p>
<p>Now, although the image rotation is carried out with respect to the image&#8217;s centre, rotating by the top-left corner will result in the same optimal width and height. Again, this is basic maths so you&#8217;ll just have to convince yourself it&#8217;s true (and that I don&#8217;t really want to explain it&#8230;).</p>
<p>But that&#8217;s if t is an acute angle. What about other angles?</p>
<p><img src="http://polymathprogrammer.com/images/blog/201202/imgrotationwidthheight2.png" alt="Image rotation, optimal width and height" /></p>
<p>For those angles, we just need to calculate the acute angle based on the initial rotation angle. After that, just substitute that calculated acute angle into our formula above. I have absolute confidence in your ability to check which quadrant in the <a href="http://polymathprogrammer.com/2008/09/01/cartesian-coordinates-and-transformation-matrices/">Cartesian coordinate system</a> does your rotation angle lie in.</p>
<p><strong>UPDATE</strong>: In case you are unable to view images, if your rotation angle is in the 2nd quadrant, the calculated angle is (180 &#8211; t). If in the 3rd quadrant, it&#8217;s (t &#8211; 180). And if in the 4th quadrant, it&#8217;s (360 &#8211; t).</p>
<p>In practice, you might still want to pad a couple of pixels around. But that should give you the smallest image dimension which can still contain your rotated image.</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2012/02/22/optimal-width-height-after-image-rotation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quadratic Bezier curve control point calculation demo</title>
		<link>http://polymathprogrammer.com/2012/01/16/quadratic-bezier-curve-control-point-calculation-demo/</link>
		<comments>http://polymathprogrammer.com/2012/01/16/quadratic-bezier-curve-control-point-calculation-demo/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 11:07:55 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[bezier]]></category>
		<category><![CDATA[control point]]></category>
		<category><![CDATA[curve]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[quadratic]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=3319</guid>
		<description><![CDATA[MacGile made a video to demonstrate the calculation of control points of a quadratic Bezier curve. The algorithm is based on what I wrote here. That looks awesome! Thanks MacGile!]]></description>
			<content:encoded><![CDATA[<p>MacGile made a video to demonstrate the calculation of control points of a quadratic Bezier curve. The algorithm is based on <a href="http://polymathprogrammer.com/2010/05/03/reverse-engineering-quadratic-bezier-curves/">what I wrote here</a>.</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/s1ALgNnRi6Q" frameborder="0" allowfullscreen></iframe></p>
<p>That looks awesome! Thanks MacGile!</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2012/01/16/quadratic-bezier-curve-control-point-calculation-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bezier curves prefer tea</title>
		<link>http://polymathprogrammer.com/2011/12/11/bezier-curves-prefer-tea/</link>
		<comments>http://polymathprogrammer.com/2011/12/11/bezier-curves-prefer-tea/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 12:03:12 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[bezier]]></category>
		<category><![CDATA[calculation]]></category>
		<category><![CDATA[cartesian]]></category>
		<category><![CDATA[curve]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=3196</guid>
		<description><![CDATA[My maths professor was hammering on the fact that Citroen used Bezier curves to make sure their cars have aesthetically pleasing curves. Again. (This is not a sponsored post from the automaker). While I appreciate his effort in trying to make what I&#8217;m learning relevant to the real world, I kinda got the idea that [...]]]></description>
			<content:encoded><![CDATA[<p>My maths professor was hammering on the fact that Citroen used Bezier curves to make sure their cars have aesthetically pleasing curves. Again. (This is not a sponsored post from the automaker).</p>
<p>While I appreciate his effort in trying to make what I&#8217;m learning relevant to the real world, I kinda got the idea that Citroen used Bezier curves in their design process. Right about the 3rd tutorial lesson.</p>
<p>My professor then went on to give us homework. &#8220;Us&#8221; meaning 5 of us. It was an honours degree course. It wasn&#8217;t like there was a stampede to take post-graduate advanced maths lessons, you know.</p>
<p>Oh yes, homework. My professor, with wisdom acquired over years of teaching, gave a blend of theoretical and calculation-based questions. Any question that had the words &#8220;prove&#8221;, &#8220;justify&#8221;, &#8220;show&#8221; are probably theoretical questions. Calculation-based questions are like &#8220;What is 1 + 1?&#8221;. Everyone, at least theoretically (haha!), should be able to do the calculation-based questions. The theoretical questions would require more thinking (&#8220;Prove that such and such Bezier curve is actually equal to such and such.&#8221;).</p>
<p>My friend, who took the course with me, loved calculation-based questions. She&#8217;d sit patiently and hammer at the numbers and the calculator. I can&#8217;t say I love them. My professor once gave a question that amounted to solving a system of 5 linear equations with 5 unknowns, which amounted to solving a 5 by 5 matrix. <strong>By hand.</strong> (It involves 15 divisions, 50 multiplications and 50 subtractions. There&#8217;s a reason why linear algebra and numerical methods were pre-requisites) I wanted to scream in frustration, throw my foolscap paper at him, and strangle him. Not necessarily in that order.</p>
<p>This coming from someone who is fine with writing a C program doing memory allocations (using the malloc function. And then manually freeing the pointer with the memory allocation. We didn&#8217;t have garbage collection, ok?) to simulate an N-sized matrix, and then perform Gauss-Jordan elimination on the matrix. I used that program to solve a 100 by 100 matrix. But I dreaded solving a 5 by 5 matrix by hand.</p>
<p>It probably explains why I remember Bezier curves so much.</p>
<p>Anyway, a while ago, someone sent me a question (through Facebook, of all channels). He asked, <strong>for a given &#8220;y&#8221; value of a Bezier curve, how do you find the &#8220;x&#8221; value?</strong></p>
<p>That is a question without a simple answer. The answer is, there&#8217;s no guarantee there&#8217;s only <em>one</em> &#8220;x&#8221; value. A cubic Bezier curve has a possibility of having 1, 2 or 3 &#8220;x&#8221; values (given a &#8220;y&#8221;). Here&#8217;s the &#8220;worst&#8221; case scenario:</p>
<p><img src="http://polymathprogrammer.com/images/blog/201112/multixvalues.png" alt="Multi x values" /></p>
<p>So you can have at most 3 &#8220;x&#8221; values. In the case of the person who asked the question, this is not just wrong, but actually <em>dangerous</em>. The person was an engineer, working on software that cuts metal (or wood). The software had a Bezier curve in it, which it used to calculate (x,y) coordinate values to direct the laser beam (or whatever cutting tool) to the next point (and thus cut the material).</p>
<p>If a &#8220;y&#8221; value has multiple &#8220;x&#8221; values, the software won&#8217;t know which &#8220;x&#8221; value you want. And thus cut the material wrongly.</p>
<p><strong>The only way a Bezier curve has only 1 value, is if it&#8217;s monotonically increasing/decreasing.</strong> That means for all values of x and y such that x <= y [or x >= y], that f(x) <= f(y) [or f(x) >= f(y)].</p>
<p>Bezier curves don&#8217;t work well in the Cartesian plane. They work fine after you&#8217;ve used them to calculate values, and then transfer onto the Cartesian plane. Bezier curves prefer to work with values of t.</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2011/12/11/bezier-curves-prefer-tea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Negative sales targets and percentage commissions</title>
		<link>http://polymathprogrammer.com/2011/08/24/negative-sales-targets-percentage-commissions/</link>
		<comments>http://polymathprogrammer.com/2011/08/24/negative-sales-targets-percentage-commissions/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 13:06:06 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[calculation]]></category>
		<category><![CDATA[commission]]></category>
		<category><![CDATA[formula]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[negative]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[sales]]></category>
		<category><![CDATA[target]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=3014</guid>
		<description><![CDATA[A while ago, I received an email from a distraught salesman. He believed his sales commissions were wrongly calculated, and asked me to shed some light. Note that I&#8217;m not using the exact numbers he gave in his email. The story goes that Michael (as I&#8217;ll call him) and his colleagues were given sales targets [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, I received an email from a distraught salesman. He believed his sales commissions were wrongly calculated, and asked me to shed some light.</p>
<p>Note that I&#8217;m not using the exact numbers he gave in his email.</p>
<p>The story goes that Michael (as I&#8217;ll call him) and his colleagues were given sales targets that were negative. <strong>How could sales targets be negative?</strong> Shouldn&#8217;t you be trying to sell something? The reason given was that the current economy was disastrous, and basically each sales person was <em>trying to not lose sales</em>.</p>
<p>You&#8217;re gonna bleed. It&#8217;s how much you bled.</p>
<p>Anyway, given Michael&#8217;s negative sales target, he managed to exceed it. He didn&#8217;t manage to bring in sales (positive sales numbers), <strong>but</strong> he didn&#8217;t lose <em>too</em> much money (slight negative sales numbers). But his sales commissions didn&#8217;t reflect that.</p>
<p>Now I&#8217;m not going to discuss how that works out. I can&#8217;t presume to understand the business logic behind the sales commission in this case, but I&#8217;ll discuss the mathematics behind the numbers.</p>
<h3>The normal sales targets and commission</h3>
<p>Let&#8217;s say your sales target for this month is $1000. This means you&#8217;re expected to sell about $1000 worth of products or services. We&#8217;ll ignore the condition that you will get <em>some</em> commission based on what you sell, regardless of how much you sold (my brother&#8217;s a sales person), as well as other types of commissions.</p>
<p>Let&#8217;s say the sales commission is based on how much <em>extra</em> you sold beyond your sales target. Makes sense, right? Let&#8217;s use simple percentages.</p>
<p>If you sold $1100 worth of products or services, then your percentage commission might be calculated as follows:<br />
(Difference between Your Sales and Your Sales Target) / (Your Sales Target)</p>
<p>Or ($1100 &#8211; $1000) / ($1000) = 10% commission.</p>
<p>This is assuming that your sales amount exceeded the sales target, of course.</p>
<h3>The case of negative sales targets</h3>
<p>Now if the sales target is negative, as in Michael&#8217;s case, the mathematical formula still applies. But you have to note the negative sign. For some reason, &#8220;business&#8221; people (no offense to business people) tend to see -4567 as <em>larger</em> than 12, even though 12 > -4567. They see the magnitude first, not the value itself. (It&#8217;s also why I get emails about calculations involving negative numbers&#8230; anyway&#8230;)</p>
<p>Let&#8217;s say the sales target is -$1000. Everyone&#8217;s expected to lose money, but you try not to lose more than $1000. At least that&#8217;s what I&#8217;m interpreting it as.</p>
<p>Let&#8217;s say Michael managed to lose only $50. Or -$50 to be clear. The formula<br />
(Difference between Your Sales and Your Sales Target) / (Your Sales Target)</p>
<p>have to be modified to this<br />
(Difference between Your Sales and Your Sales Target) / (Magnitude of Your Sales Target)</p>
<p>In maths and programming terms, the &#8220;magnitude&#8221; part refers to the absolute function. Meaning you ignore any negative signs. Actually, the modified version works for the normal case too (which is why you should use it for the normal version anyway to take care of weird cases like this but I digress&#8230;).</p>
<p>So, we get (-$50 &#8211; [-$1000]) / abs(-$1000) = $950 / $1000<br />
= 95%</p>
<p>Actually, you should use this:<br />
abs( [Your Sales] &#8211; [Your Sales Target] ) / abs(Your Sales Target)</p>
<p>That&#8217;s the &#8220;foolproof&#8221; version. Consider it a bonus for reading this far. Frankly speaking, any competent programmer should be able to come up with that formula, even without much maths background. You just need to think about the situation a little carefully (ask &#8220;what if?&#8221; more often).</p>
<h3>Michael&#8217;s calculated commission</h3>
<p>When Michael wrote to me, he said his commission was calculated as follows (given that he only lost $50):<br />
-$50 / -$1000 = 5%</p>
<p>Let&#8217;s say someone else lost -$900 that month. With the above calculation, that person gets:<br />
-$900 / -$1000 = 90%</p>
<p>Clearly it makes more sense to lose more money! This was why Michael wrote to me.</p>
<p>I don&#8217;t propose the method I gave is correct, business-logic-wise. Michael didn&#8217;t give me any details on what he&#8217;s selling, or what his company is (or even why it&#8217;s acceptable to have negative sales targets, regardless of the economy). So I cannot give any help other than from a pure mathematical point of view. But I hope it&#8217;ll at least give Michael a fairer commission amount.</p>
<h3>Questions</h3>
<p>Given Michael&#8217;s situation, what do you think is an appropriate calculation formula?</p>
<p>Can you think of (or know of) a realistic situation where a negative sales target is acceptable? I say &#8220;acceptable&#8221;, but seriously, no company should &#8220;accept&#8221; that they lose money every month.</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2011/08/24/negative-sales-targets-percentage-commissions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cantor sets and Invisibility cloaks</title>
		<link>http://polymathprogrammer.com/2011/07/25/cantor-set/</link>
		<comments>http://polymathprogrammer.com/2011/07/25/cantor-set/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 12:54:59 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[cantor set]]></category>
		<category><![CDATA[cantor ternary set]]></category>
		<category><![CDATA[chaos theory]]></category>
		<category><![CDATA[clopen set]]></category>
		<category><![CDATA[closed set]]></category>
		<category><![CDATA[fractal]]></category>
		<category><![CDATA[georg cantor]]></category>
		<category><![CDATA[mathematics]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[open set]]></category>
		<category><![CDATA[real line]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=2976</guid>
		<description><![CDATA[More specifically, it&#8217;s the Cantor ternary set.]]></description>
			<content:encoded><![CDATA[<p><iframe width="560" height="349" src="http://www.youtube.com/embed/ZkgXuE4NIfw" frameborder="0" allowfullscreen></iframe></p>
<p>More specifically, it&#8217;s the Cantor ternary set.</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2011/07/25/cantor-set/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Revenue sharing and operations research – part 2</title>
		<link>http://polymathprogrammer.com/2011/07/16/revenue-sharing-operations-research-part2/</link>
		<comments>http://polymathprogrammer.com/2011/07/16/revenue-sharing-operations-research-part2/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 12:51:35 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[linear inequalities]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[operations research]]></category>
		<category><![CDATA[revenue sharing]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=2957</guid>
		<description><![CDATA[This is a mini-series on how revenue sharing and operations research are linked. You might want to read part 1 on the specific business problem I was solving. In this part, I&#8217;ll be telling you about the maths behind the business solution. But first, I have to tell you about a couple of maths concepts. [...]]]></description>
			<content:encoded><![CDATA[<p>This is a mini-series on how revenue sharing and operations research are linked. You might want to read <a href="http://polymathprogrammer.com/2011/07/15/revenue-sharing-operations-research-part1/">part 1</a> on the specific business problem I was solving. In this part, I&#8217;ll be telling you about the maths behind the business solution.</p>
<p>But first, I have to tell you about a couple of maths concepts.</p>
<h3>Converging from opposite directions</h3>
<p>Let&#8217;s say someone asked you how tall you are. Instead of giving a straight answer, you decide to give a simple maths puzzle. You say you are at least 6 feet tall. Then you also say you are at most 6 feet tall. So what&#8217;s your height? Let&#8217;s put those 2 conditions into mathematical form:</p>
<ul>
<li>H >= 6</li>
<li>H <= 6</li>
</ul>
<p>To satisfy those 2 conditions, there&#8217;s only 1 answer: You must be 6 feet tall.</p>
<p>It looks elementary, but it will come into play later on. Just keep in mind that an equality can be split into 2 inequalities. This actually reminds me of the <a href="http://en.wikipedia.org/wiki/Squeeze_theorem">squeeze theorem</a>, but I digress.</p>
<h3>Reversing the direction of an inequality</h3>
<p>The next maths concept is how to reverse the direction of an inequality. For example, we have</p>
<p>x >= 5</p>
<p>This can also be expressed as</p>
<p>-x <= -5</p>
<p>This will also come in handy later on.</p>
<h3>System of linear inequalities</h3>
<p>My experience in operations research had been confined to course work in an academic semester. Operations research mainly is about maximising or minimising some objective. You are given a series of conditions to fulfill. Then you&#8217;re given an objective to maximise or minimise. And you&#8217;re to translate those conditions and objective into a mathematical model formulation. Let&#8217;s look at an example.</p>
<p>Jake&#8217;s mom gave him $15 to buy some sweets (because he did awesomely in a maths test. Parental note: I don&#8217;t think this is a good reward, but hey, it&#8217;s your kid). But mom told Jake that he cannot buy more than 3 lollipops (although Jake already decided he&#8217;s not buying more than 4). There&#8217;s this contest where if you submit wrappers from peppermints and lollipops, you win an iPad (I&#8217;m totally making this up!). Jake needed just 4 more wrappers, and he didn&#8217;t want more than 4 because he wanted to buy more chocolates. Also, Jake had secretly decided to buy at least $10 worth of sweets.</p>
<p>Now, chocolates cost $2 each. Peppermints cost $1 each. And lollipops cost $3 each.</p>
<p>Let C be the number of chocolates bought.<br />
Let P be the number of peppermints bought.<br />
Let L be the number of lollipops bought.</p>
<p>Let the objective be to maximise the number of sweets bought. So in maths form, we typically write it as:<br />
max C + P + L</p>
<p>Let&#8217;s formulate the conditions:<br />
2C + P + 3L <= 15 (mom only gave Jake $15)<br />
L <= 3 (mom said Jake can't buy more than 3 lollipops)<br />
L <= 4 (Jake independently decided he's not buying more than 4)<br />
P + L = 4 (Jake just wanted 4 more wrappers)<br />
2C + P + 3L >= 10 (Jake wanted to waste at least $10)</p>
<p>Now, logically speaking the condition for the number of wrappers doesn&#8217;t make sense. We could say the number of wrappers for peppermints and lollipops be at least 4, which makes better sense. But this is a hypothetical example. More to the point, it&#8217;s <em>my</em> hypothetical example, and I needed an equality condition. So there.</p>
<p>You might also note that there are redundant conditions.<br />
L <= 3<br />
L <= 4</p>
<p>can be represented by just<br />
L <= 3<br />
because if it's satisfied, then L is definitely <= 4. This is to show you that in your mathematical formulation, you can get redundant conditions. It's up to you to eliminate them so you work with less conditions. Real life problems are messy, don't you know?</p>
<p>Let's clean up the formulation.</p>
<p>Objective: max C + P + L<br />
2C + P + 3L <= 15<br />
-2C - P - 3L <= -10<br />
P + L <= 4<br />
-P - L <= -4<br />
L <= 3</p>
<p>I've rearranged the conditions a little for clarity. Note the inequality reversal for the "more than $10" condition. Note the split of the equality to 2 inequalities. Why are we doing this? So we get the general form Ax <= B where<br />
A is the coefficient matrix<br />
x is the variable vector<br />
B is the value vector</p>
<p>We need to do the inequality reversal so the "direction" for all the inequalities is the same. Otherwise we cannot have Ax <= B.</p>
<p>In this case, A is<br />
| 2  1  3 |<br />
|-2 -1 -3 |<br />
| 0  1  1 |<br />
| 0 -1 -1 |<br />
| 0  0  1 |</p>
<p>x is<br />
| C |<br />
| P |<br />
| L |</p>
<p>B is<br />
| 15 |<br />
|-10 |<br />
|  4 |<br />
| -4 |<br />
|  3 |</p>
<p>With this Ax <= B form, we're dealing with matrices and vectors. That means we can use all the mathematical techniques for solving such formulations, such as <a href="http://en.wikipedia.org/wiki/Gaussian_elimination">Gaussian elimination</a> or even <a href="http://en.wikipedia.org/wiki/Gauss%E2%80%93Jordan_elimination">Gauss-Jordan elimination</a>. The idea is to solve all of our unknowns at one go.</p>
<p>You might notice that we have more inequalities than unknowns. This means we have multiple solutions.</p>
<p>For example, a possible solution for (C, P, L) is (2, 3, 1). That solution satisfies all the conditions. It doesn&#8217;t mean it&#8217;s optimal, but it&#8217;s <em>a</em> solution. This means solutions exist for the problem (sometimes just knowing this is reassuring&#8230;).</p>
<h3>The dual</h3>
<p>I want you to know that the objective can always be stated in the opposite manner. If the objective is to &#8220;maximise X&#8221;, it is equivalent to &#8220;minimising -X&#8221;. This is known as the <a href="http://en.wikipedia.org/wiki/Dual_problem">dual</a> of the problem. For example, maximising profit is equivalent to minimising the negative value of profit. <strong>NOTE</strong>: Maximising profit is NOT equivalent to minimising cost. Profit and cost are generally not the opposite of each other (they&#8217;re different business terms), even if they sound like they are (and sometimes give the same solutions). The mathematical formulation and solution is different for both of them. Know what you&#8217;re solving.</p>
<p>This duality property is useful if your program is optimised to solve only minimisation problems. So you just convert a maximisation problem to a minimisation problem, and your program works just fine!</p>
<h3>Linearity</h3>
<p>And you might also note that the objective and the conditions are all linear, meaning unknowns are up to power of 1 (as opposed to quadratic or cubic). Sometimes you get a non-linear condition, and depending on the situation, you might be able to form linear conditions that are equivalent to that non-linear condition.</p>
<p>For example, CP = 2 (number of chocolates multiply by number of peppermints equal to 2).<br />
This set of conditions might be equivalent:</p>
<ul>
<li>C >= 1</li>
<li>P >= 1</li>
<li>C <= 2</li>
<li>P <= 2</li>
<li>C + P = 3</li>
</ul>
<p>The first 2 conditions are inferred from the fact that C and P cannot be zero. If they are, then CP = 2 is never satisfied. If they&#8217;re never zero, then they must be at least 1.</p>
<p>The 3rd and 4th conditions are inferred from the fact that C and P cannot be more than 2. If they are, then the other unknown is fractional. For example, if C is 4, then P must be 1/2. But these are number of items, so they must be integer. Therefore, C and P must be at most 2.</p>
<p>Based on the first 4 conditions, C and P can only take on either 1 or 2 as values. The only combination of permutations that still satisfies the &#8220;CP = 2&#8243; condition is one unknown must be 1 and the other unknown be 2. Hence the sum of the two unknowns must be equal to 3.</p>
<p>Not all non-linear conditions can be translated into linear conditions. Go ask an operations research professor for more.</p>
<h3>Integral conditions</h3>
<p>And we come to the worst part. All the unknowns must be integer (you can&#8217;t buy 2.37 chocolates. Well, at least not without the candy store owner going crazy). This integral condition makes the problem much harder to solve. If you solve the Ax <= B form, you generally get fractional values for the unknowns. This is the optimum solution, but doesn't satisfy the integral condition.</p>
<p>If I remember correctly, you solve Ax <= B as usual. Then you take one of the unknowns and work with the 2 integers that are the floor and ceiling values of that unknown. Then you solve iteratively again, with reduced and reformulated conditions for Py <= Q.</p>
<p>For example, if you get C = 2.37, then you split off 2 scenarios with C = 2 and C = 3 as the optimum solutions. Scenario 1 is</p>
<p>Objective: max P + L<br />
P + 3L <= 11<br />
-P - 3L <= -6<br />
P + L <= 4<br />
-P - L <= -4<br />
L <= 3</p>
<p>Scenario 2 is</p>
<p>Objective: max P + L<br />
P + 3L <= 9<br />
-P - 3L <= -4<br />
P + L <= 4<br />
-P - L <= -4<br />
L <= 3</p>
<p>Basically, you just substitute C = 2 and C = 3. For each scenario, you continue splitting with the other unknowns. There are 3 unknowns, so there are eventually 8 scenarios (2^3 = 8). It's a binary tree. Well, it's at most 8 scenarios, because you might get lucky and hit an original optimised solution with one or more of the unknowns having an original value that's already an integer (now that's a long sentence...).</p>
<p>For each of the scenarios, you either get a solution or you get a contradiction somewhere (meaning it's unsolvable). The contradiction can come from the splitting, because when you substitute a possible value into one of the unknowns, the resulting set of conditions contain a contradiction. For example, out of the set of conditions, you get 2 conditions as follows:</p>
<p>x <= 4<br />
-x <= -8 ( meaning x >= 8 )</p>
<p>Since an unknown variable cannot be both (less than or equal to 4) AND be (more than or equal to 8), the scenario becomes unsolvable.</p>
<p>Then you examine all those scenarios with solutions, substitute the solutions to the unknowns, and compare the result. If it&#8217;s a maximising problem, you check which scenario gave a solution that&#8217;s the largest. If it&#8217;s a minimisation problem, you check which scenario gave a solution that&#8217;s the smallest. And that particular solution becomes the optimum integral solution.</p>
<p>Let me tell you, you do <em>not </em>want to do this by hand. This is why software is written to handle the Gaussian eliminations and checking all the possible scenarios due to the integral condition. With just 3 unknowns, you&#8217;re expected to do 9 Gaussian eliminations (1 for the original, 8 for the branch scenarios), and check through all 8 scenarios. Imagine having hundreds of variables and conditions&#8230;</p>
<p>Mathematics and programming in one. Having skills in one but not the other makes writing the software quite difficult. Imagine a mathematician who cannot express his ideas in programming code, or a programmer who cannot understand the maths involved.</p>
<h3>Back to the business problem</h3>
<p>After that extremely long mathematical discussion, we can now turn back to the original business problem. If you haven&#8217;t read <a href="http://polymathprogrammer.com/2011/07/15/revenue-sharing-operations-research-part1/">part 1</a>, you should do so now, otherwise you&#8217;d be lost.</p>
<p>Let R be the total revenue for a content provider for that particular month<br />
Let R1 be the total revenue for ProductA<br />
Let R2 be the total revenue for ProductB<br />
Let R3 be the total revenue for ProductC<br />
(so R1 + R2 + R3 = R)<br />
Let X1 be the revenue share for the telecommunications company for ProductA<br />
Let X2 be the revenue share for the telecommunications company for ProductB<br />
Let X3 be the revenue share for the telecommunications company for ProductC<br />
Let Y1 be the revenue share for the content provider for ProductA<br />
Let Y2 be the revenue share for the content provider for ProductB<br />
Let Y3 be the revenue share for the content provider for ProductC</p>
<p>Let the revenue sharing split for the telecommunications company be 30%<br />
Let the revenue sharing split for the content provider be 70%</p>
<p>The objective is to minimise rounding errors. Actually, there should be no errors, but we can live with a possible solution first. If it&#8217;s non-zero, <em>then</em> we panic&#8230;</p>
<p>The unknowns in this case are X1, X2, X3, Y1, Y2 and Y3.</p>
<p>Objective: minimise ABS(R &#8211; X1 &#8211; X2 &#8211; X3 &#8211; Y1 &#8211; Y2 &#8211; Y3)<br />
X1 + Y1 = R1<br />
X2 + Y2 = R2<br />
X3 + Y3 = R3<br />
X1 = 0.30 * R1<br />
X2 = 0.30 * R2<br />
X3 = 0.30 * R3<br />
Y1 = 0.70 * R1<br />
Y2 = 0.70 * R2<br />
Y3 = 0.70 * R3</p>
<p>And Xi&#8217;s and Yi&#8217;s must be integers, for i = 1, 2, 3</p>
<p>And ABS stands for the absolute function.</p>
<p>As you can see, there&#8217;s a lot of equal conditions. And it&#8217;s a problem with integer conditions. Frankly speaking, I don&#8217;t want to program a solution either. Just looking at what I&#8217;ve written is already giving me a headache&#8230;</p>
<p>I&#8217;m glad my ex-colleague said no. *whew* This was too complicated to implement. And the content provider might have more products, so the number of unknowns is unknown (no pun intended).</p>
<p>There&#8217;s actually a little bit more to the maths formulation, but I&#8217;ll tell you about it in the 3rd part. I had to come up with a solution that made mathematical sense and could be understood by other people. Mostly, the users (that is, &#8220;normal&#8221; people) must be able to understand the logic behind it.</p>
<p>Leave a comment if you have any questions about the maths involved (or even tell me I&#8217;m wrong), and I&#8217;ll do my best to answer them.</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2011/07/16/revenue-sharing-operations-research-part2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Absolutes and almost every</title>
		<link>http://polymathprogrammer.com/2011/05/30/absolutes-and-almost-every/</link>
		<comments>http://polymathprogrammer.com/2011/05/30/absolutes-and-almost-every/#comments</comments>
		<pubDate>Mon, 30 May 2011 05:00:08 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[absolute]]></category>
		<category><![CDATA[ae]]></category>
		<category><![CDATA[almost every]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[maths]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=2844</guid>
		<description><![CDATA[Back when I was writing my thesis, I came across this abbreviation: a.e. It took me a while, but I eventually found that it meant almost every. This might have been almost everywhere in measure theory, but I don&#8217;t think so. I seem to recall just &#8220;almost every&#8221;. Almost every what, you ask? Well, I [...]]]></description>
			<content:encoded><![CDATA[<p>Back when I was writing my <a href="http://polymathprogrammer.com/2008/03/05/computer-virus-behaviour-thesis/">thesis</a>, I came across this abbreviation: a.e. It took me a while, but I eventually found that it meant <em>almost every</em>. This might have been <em><a href="http://en.wikipedia.org/wiki/Almost_everywhere">almost everywhere</a></em> in <a href="http://en.wikipedia.org/wiki/Measure_theory">measure theory</a>, but I don&#8217;t think so. I seem to recall just &#8220;almost every&#8221;.</p>
<p>Almost every <em>what</em>, you ask?</p>
<p>Well, I was doing research on computer virus behaviour, so I had books from computer security, graph theory, biological viruses, mathematical models (with exponents and ordinary differential equations and such). I think it was in graph theory. An author was talking about a result or theorem and the proof included <em>almost every</em> type of graph, which was good enough.</p>
<p>I thought that was interesting, because I&#8217;ve thought of mathematics as absolute. Maybe this was why I suck at statistics&#8230; The idea of some event having a probability of happening, instead of just <em>be</em> or <em>be not</em>, shakes my world somewhat. Of course, I&#8217;m less shaken now since life isn&#8217;t really absolute&#8230;</p>
<p>My greatest accomplishment came when I was in the computer lab, and a Masters student was around. She&#8217;s from China, and you know those people are wicked clever. She held up a book, looked at me, then walked over to me.</p>
<p>&#8220;Do you know what a.e. means?&#8221;</p>
<p>AHA! Me, honours student, knew something a Masters student didn&#8217;t!</p>
<p>&#8220;I think it means <em>almost every</em>.&#8221;<br />
&#8220;Oh. OHHHH! Thanks!&#8221;</p>
<p>I suspect she asked me because she believed my English was better than hers, and not because I was more knowledgeable in whatever topic that book of hers was about. Have you seen programming books translated to Chinese? I can read the words, but that doesn&#8217;t mean I know what the hashbrown that meant&#8230; She approached me probably (yay statistics) because she believed a.e. stood for something that someone moderately versed in English will know.</p>
<p>Still, it was an accomplishment. I could tell you I went on to brag about it to all my friends, but truth be told, I continued working on my program code&#8230; I was in the computer lab for <em>something</em>, you know&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2011/05/30/absolutes-and-almost-every/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Is there an equation to describe regular polygons?</title>
		<link>http://polymathprogrammer.com/2011/05/29/regular-polygons-equation/</link>
		<comments>http://polymathprogrammer.com/2011/05/29/regular-polygons-equation/#comments</comments>
		<pubDate>Sun, 29 May 2011 12:12:36 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[equation]]></category>
		<category><![CDATA[polygon]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[regular]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=2840</guid>
		<description><![CDATA[So a blog reader, Michael Gmirkin, sent me an in-depth email about the possibility of the existence of a super equation that can describe any regular polygon. I wasn&#8217;t sure. For reference, you might want to check out these 2 blog posts about the equation for a square: question, answer. I was going to just [...]]]></description>
			<content:encoded><![CDATA[<p>So a blog reader, Michael Gmirkin, sent me an in-depth email about the possibility of the existence of a super equation that can describe any regular polygon. I wasn&#8217;t sure. For reference, you might want to check out these 2 blog posts about the equation for a square: <a href="http://polymathprogrammer.com/2010/02/22/quiz-can-you-describe-square-with-1-equation/">question</a>, <a href="http://polymathprogrammer.com/2010/03/01/answered-can-you-describe-a-square-with-1-equation/">answer</a>.</p>
<p>I was going to just ask you here. Then I remembered there&#8217;s a Stack Overflow equivalent for maths. <a href="http://math.stackexchange.com/questions/41940/is-there-an-equation-to-describe-regular-polygons">So I went there and asked the question</a>. So if you know the answer, you can comment here, or go to the maths StackExchange site and earn yourself some points.</p>
<p>You can assume that the centre of the regular polygon in at the origin (0,0). Researching a little on the topic, I also learnt about the <a href="http://en.wikipedia.org/wiki/Apothem">apothem</a>, which is also the shortest distance from the centre to a polygon&#8217;s side. The &#8220;normal&#8221; radius is the distance from the centre to one of the regular polygon&#8217;s vertex.</p>
<p>If you trace 2 circles, one with the apothem and one with the radius, you get an inscribed circle and circumscribed circle respectively.</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2011/05/29/regular-polygons-equation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t rely on just the average!</title>
		<link>http://polymathprogrammer.com/2011/04/18/dont-rely-on-just-the-average/</link>
		<comments>http://polymathprogrammer.com/2011/04/18/dont-rely-on-just-the-average/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 13:08:45 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[arithmetic]]></category>
		<category><![CDATA[average]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[mathematics]]></category>
		<category><![CDATA[mean]]></category>
		<category><![CDATA[median]]></category>
		<category><![CDATA[metric]]></category>
		<category><![CDATA[mode]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://polymathprogrammer.com/?p=2760</guid>
		<description><![CDATA[I made this video because I&#8217;ve always been skeptical about reports (such as population census and surveys) with the average as the only statistical measurement.]]></description>
			<content:encoded><![CDATA[<p><iframe title="YouTube video player" width="560" height="349" src="http://www.youtube.com/embed/-Rw7lhj-yfk" frameborder="0" allowfullscreen></iframe></p>
<p>I made this video because I&#8217;ve always been skeptical about reports (such as population census and surveys) with the average as the only statistical measurement.</p>
]]></content:encoded>
			<wfw:commentRss>http://polymathprogrammer.com/2011/04/18/dont-rely-on-just-the-average/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

