<?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>Flassari.is &#187; Math</title>
	<atom:link href="http://flassari.is/category/math/feed/" rel="self" type="application/rss+xml" />
	<link>http://flassari.is</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 19 Jul 2010 16:09:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pie mask in AS3</title>
		<link>http://flassari.is/2009/11/pie-mask-in-as3/</link>
		<comments>http://flassari.is/2009/11/pie-mask-in-as3/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 17:02:17 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[mask]]></category>
		<category><![CDATA[percentage]]></category>
		<category><![CDATA[pie]]></category>
		<category><![CDATA[progress]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=240</guid>
		<description><![CDATA[Sometimes I have the need for a rotational progress bar that acts like a pie growing bigger (or smaller if that strikes your fancy). As usual, I made my own =) [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I have the need for a rotational progress bar that acts like a pie growing bigger (or smaller if that strikes your fancy). As usual, I made my own =)<br />
The function drawPieMask takes first the <strong>graphics</strong> object of the displayObject instance and draws a part of pie on it, <strong>percentage</strong> set&#8217;s how big the part is.<br />
If you want to offset the rotation of the pie (it starts to the right by default) you can set the <strong>rotation</strong> parameter. Note that rotation is in radians, not degrees, but you can multiply your degrees by (Math.PI/180) to convert to radians.<br />
Lastly, the <strong>sides</strong> property determines how many sides the circle drawn in the mask has. You can see an example of different pie masks after the code.</p>
<p>To make the code as customizable as possible, it does not make a call to beginFill in case you want to set your own fill (or gradientfill even?).<br />
If you just want to use it as a basic mask, just call beginFill(0) before and endFill() after the call to drawPieMask.</p>
<pre class="brush: as3">function drawPieMask(graphics:Graphics, percentage:Number, radius:Number = 50, x:Number = 0, y:Number = 0, rotation:Number = 0, sides:int = 6):void {
	// graphics should have its beginFill function already called by now
	graphics.moveTo(x, y);
	if (sides < 3) sides = 3; // 3 sides minimum
	// Increase the length of the radius to cover the whole target
	radius /= Math.cos(1/sides * Math.PI);
	// Shortcut function
	var lineToRadians:Function = function(rads:Number):void {
		graphics.lineTo(Math.cos(rads) * radius + x, Math.sin(rads) * radius + y);
	};
	// Find how many sides we have to draw
	var sidesToDraw:int = Math.floor(percentage * sides);
	for (var i:int = 0; i <= sidesToDraw; i++)
		lineToRadians((i / sides) * (Math.PI * 2) + rotation);
	// Draw the last fractioned side
	if (percentage * sides != sidesToDraw)
		lineToRadians(percentage * (Math.PI * 2) + rotation);
}</pre>
<p>Example of different sides values. The last circle has a pie with 3 sides as a mask.<br />
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="450" height="310"><param name="movie" value="/wp-content/uploads/2009/11/PieMaskExample.swf" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="/wp-content/uploads/2009/11/PieMaskExample.swf" width="450" height="310"><!--<![endif]-->
<div>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
<p><!--[if !IE]>--></object><!--<![endif]--></object></p>
<p>You can get the <a href='http://flassari.is/wp-content/uploads/2009/11/PieMaskExample.zip'>example fla here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2009/11/pie-mask-in-as3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Line-Line Intersection in AS3</title>
		<link>http://flassari.is/2009/04/line-line-intersection-in-as3/</link>
		<comments>http://flassari.is/2009/04/line-line-intersection-in-as3/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 15:34:53 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=104</guid>
		<description><![CDATA[I found a bug in my old Line-Line Intersection in C++ post, and after I fixed it I thought it would be a good idea to port it to AS3: [...]]]></description>
			<content:encoded><![CDATA[<p><center><img src="/wp-content/uploads/2008/11/linesect.png" alt="Line line intersection function explanation" title="linesect" width="259" height="134" class="size-full wp-image-71" /></center></p>
<p>I found a bug in my old <a href="/2008/11/line-line-intersection-in-cplusplus/">Line-Line Intersection in C++ post</a>, and after I fixed it I thought it would be a good idea to port it to AS3:</p>
<pre class="brush: as">function intersection(p1:Point, p2:Point, p3:Point, p4:Point):Point {
    var x1:Number = p1.x, x2:Number = p2.x, x3:Number = p3.x, x4:Number = p4.x;
    var y1:Number = p1.y, y2:Number = p2.y, y3:Number = p3.y, y4:Number = p4.y;
	var z1:Number= (x1 -x2), z2:Number = (x3 - x4), z3:Number = (y1 - y2), z4:Number = (y3 - y4);
    var d:Number = z1 * z4 - z3 * z2;

    // If d is zero, there is no intersection
    if (d == 0) return null;

	// Get the x and y
    var pre:Number = (x1*y2 - y1*x2), post:Number = (x3*y4 - y3*x4);
    var x:Number = ( pre * z2 - z1 * post ) / d;
    var y:Number = ( pre * z4 - z3 * post ) / d;

    // Check if the x and y coordinates are within both lines
    if ( x < Math.min(x1, x2) || x > Math.max(x1, x2) ||
        x < Math.min(x3, x4) || x > Math.max(x3, x4) ) return null;
    if ( y < Math.min(y1, y2) || y > Math.max(y1, y2) ||
        y < Math.min(y3, y4) || y > Math.max(y3, y4) ) return null;

    // Return the point of intersection
    return new Point(x, y);
}</pre>
<p>You can try it here:<br />
<center><object id="myId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="300" height="180"><param name="movie" value="/wp-content/uploads/2009/04/lineline.swf" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="/wp-content/uploads/2009/04/lineline.swf" width="300" height="180"><!--<![endif]-->
<div>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
<p><!--[if !IE]>--></object><!--<![endif]--></object></center></p>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2009/04/line-line-intersection-in-as3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Find the value between two colors</title>
		<link>http://flassari.is/2009/03/find-the-value-between-two-colors/</link>
		<comments>http://flassari.is/2009/03/find-the-value-between-two-colors/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 12:07:37 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.flassari.is/?p=52</guid>
		<description><![CDATA[A handy function I wrote that calculates a color value between two colors: [...]]]></description>
			<content:encoded><![CDATA[<p><center><img src="http://flassari.is/wp-content/uploads/2009/03/colors.png" width="340" height="124" /></center><br />
A handy function I wrote that calculates a color value between two colors.</p>
<pre class="brush: as">function getColor(fromColor:uint, toColor:uint, scale:Number):uint {
    var red:uint = ((fromColor >> 16) + (toColor >> 16) - (fromColor >> 16) * scale) << 16;
    var green:uint = ((fromColor >> 8 &#038; 255) + ((toColor >> 8 &#038; 255) - (fromColor >> 8 &#038; 255)) * scale) << 8;
    var blue:uint = (fromColor &#038; 255) + ((toColor &#038; 255) - (fromColor &#038; 255)) * scale;

    return red + green + blue;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2009/03/find-the-value-between-two-colors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Line-Line Intersection in C++</title>
		<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/</link>
		<comments>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 11:44:43 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.flassari.is/?p=41</guid>
		<description><![CDATA[<img src="http://flassari.com/wp-content/uploads/2008/11/linesect.png" alt="Line line intersection function explanation" title="linesect" width="259" height="134" /><br/>I've just been tasked with creating a function to get the intersection of two lines.
With the help of equations from Wolfram Mathworld I created this nifty function: [...]]]></description>
			<content:encoded><![CDATA[<p><center><img src="http://flassari.com/wp-content/uploads/2008/11/linesect.png" alt="Line line intersection function explanation" title="linesect" width="259" height="134" class="size-full wp-image-71" /></center></p>
<p>I&#8217;ve just been tasked with creating a function to get the intersection of two lines.<br />
With the help of equations from Wolfram Mathworld I created this nifty function:</p>
<pre class="brush: cpp">Point* intersection(Point p1, Point p2, Point p3, Point p4) {
	// Store the values for fast access and easy
	// equations-to-code conversion
	float x1 = p1.x, x2 = p2.x, x3 = p3.x, x4 = p4.x;
	float y1 = p1.y, y2 = p2.y, y3 = p3.y, y4 = p4.y;

	float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
	// If d is zero, there is no intersection
	if (d == 0) return NULL;

	// Get the x and y
	float pre = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4);
	float x = ( pre * (x3 - x4) - (x1 - x2) * post ) / d;
	float y = ( pre * (y3 - y4) - (y1 - y2) * post ) / d;

	// Check if the x and y coordinates are within both lines
	if ( x < min(x1, x2) || x > max(x1, x2) ||
		x < min(x3, x4) || x > max(x3, x4) ) return NULL;
	if ( y < min(y1, y2) || y > max(y1, y2) ||
		y < min(y3, y4) || y > max(y3, y4) ) return NULL;

	// Return the point of intersection
	Point* ret = new Point();
	ret->x = x;
	ret->y = y;
	return ret;
}</pre>
<p>Hope it will be to as good use to you as it is to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
