﻿<?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>Keith Hair &#187; ActionScript 3</title>
	<atom:link href="http://keith-hair.net/blog/category/actionscript-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://keith-hair.net/blog</link>
	<description>Scripting is fun like any other hobby</description>
	<lastBuildDate>Sun, 21 Mar 2010 20:08:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Resizing Flash Documents to Fit Contents in JSFL</title>
		<link>http://keith-hair.net/blog/2010/03/21/resizing-flash-documents-to-fit-contents-in-jsfl/</link>
		<comments>http://keith-hair.net/blog/2010/03/21/resizing-flash-documents-to-fit-contents-in-jsfl/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 20:04:56 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash 9]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[JSFL]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[Resize]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=219</guid>
		<description><![CDATA[I use Flex for the majority of my Flash related work, even for writing plain ActionScript. Lately I've barely even used the Flash authoring environment to create stuff. When I do use the Flash authoring environment, it's mostly for automation and prep work of content. If you are like me, you write JSFL to do [...]]]></description>
			<content:encoded><![CDATA[<p>I use Flex for the majority of my Flash related work, even for writing plain ActionScript. Lately I've barely even used the Flash authoring environment to create stuff. When I do use the Flash authoring environment, it's mostly for automation and prep work of content. If you are like me, you write JSFL to do that stuff.</p>
<p>I love automating redundant tasks. One thing that bugs me when importing graphical assets to Flash's stage is having to resize the document to what I imported. I like that I can do this by going to the Document Properties and setting the document to match the content size, but if I have to do this each time I import/export content it becomes a irksome chore. I write JSFL scripts that run tasks on multiple files, having a "match contents"  function would be useful to me in my case...maybe to you as well. I do not see a JSFL way to do this. (Maybe there is and I had a brain fart?). Until then, here is a script I wrote to do it in JSFL...<br />
<span id="more-219"></span></p>
<pre class="brush: jscript;">
/*****************************************************************************************
What:	Document_to_Content_Size.jsfl
		JSFL Command for Flash (8+) that will resize the document to fit the content
		that is on the stage in the authoring environment.

Why:		Yep, this action can also be done by going to the Document Properties
		and setting &quot;match&quot; to &quot;contents&quot;. However, I have not
		found a way to do this same action within JSFL script
		If you know a JSFL way to do this same action easier contact me.		

Date:		March 21, 2010
Author:	Keith Hair
Contact	khos2007@gmail.com
Web:		keith-hair.net		

INSTALL:
		If you deal with JSFL you probably know what to do, but anyway...
		Save this script with a &quot;.jsfl&quot; extension and put in:
		&quot;Your Flash installation folder\en\First Run\Commands&quot; folder
		Or just put it anywhere and double-click the file.

LEGAL STUFF:
		This script is free for whatever, just improve it or say hello! 		

NOTE:
		This is primarily for resizing the Flash
		document to fit content that is imported to the stage.
		Resizing is buggy with Component instances.

******************************************************************************************/
fl.outputPanel.clear();
runApp();
function runApp()
{
	var doc=fl.getDocumentDOM();
	var element;
	var docw=1;
	var doch=1;
	var fn=0;
	var ln=0;
	var en=0;
	var tframes;
	var layer;
	var frame;
	var ox;
	var oy;
	var left=null;
	var right=null;
	var top=null;
	var bottom=null;
	var cf=doc.getTimeline().currentFrame;
	while(ln &lt; doc.getTimeline().layerCount)
	{
		layer=doc.getTimeline().layers[ln];
		tframes=layer.frameCount;
		fn=0;
		while(fn &lt; tframes)
		{
			doc.getTimeline().currentFrame = fn;
			frame=layer.frames[fn];
			en=0;
			while(en &lt; frame.elements.length)
			{
				element = frame.elements[en];
				ox=element.x;
				oy=element.y;
				if(left == null){
					left=ox;
				}
				if(right == null){
					right=ox+element.width;
				}
				if(top == null){
					top=oy;
				}
				if(bottom == null){
					bottom=oy+element.height;
				}

				left=Math.min(ox,left);
				right=Math.max(ox+element.width,right);
				top=Math.min(oy,top);
				bottom=Math.max(oy+element.height,bottom);
				en++;
			}
			fn++;
		}
		ln++;
	}
	fl.trace(&quot;CURRENT SIZE--&gt;\t&quot;+doc.width+&quot; x &quot;+doc.height);
	docw=Math.round(right-left);
	doch=Math.round(bottom-top);
	moveAllElementsBy(-left,-top);
	doc.width=docw;
	doc.height=doch;
	fl.trace(&quot;NEW SIZE--&gt;\t\t\t&quot;+doc.width+&quot; x &quot;+doc.height);
	doc.getTimeline().currentFrame=cf;
}

function moveAllElementsBy(tx,ty)
{
	doc=fl.getDocumentDOM();
	var element;
	var fn=0;
	var ln=0;
	var en=0;
	var tframes;
	var layer;
	var frame;
	var otp;
	while(ln &lt; doc.getTimeline().layerCount)
	{
		layer=doc.getTimeline().layers[ln];
		tframes=layer.frameCount;
		fn=0;
		while(fn &lt; tframes)
		{
			doc.getTimeline().currentFrame = fn;
			frame=layer.frames[fn];
			en=0;
			while(en &lt; frame.elements.length)
			{
				element=frame.elements[en];
				element.x+=tx;
				element.y+=ty;
				if(element.elementType.search(/instance|text/mig) == -1){
					element.x+=element.width/2;
					element.y+=element.height/2;
				}

				en++;
			}
			fn++;
		}
		ln++;
	}

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2010/03/21/resizing-flash-documents-to-fit-contents-in-jsfl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KeyManager Class for Detecting Key Press Combos or Sequences</title>
		<link>http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/</link>
		<comments>http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 23:30:12 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flash 9]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[ASWD]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[dev mode]]></category>
		<category><![CDATA[easter eggs]]></category>
		<category><![CDATA[key press]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[KeyboardEvent]]></category>
		<category><![CDATA[videogames]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=189</guid>
		<description><![CDATA[When I am writing a flash app or game which uses the keyboard to control a character's movement, there is a situation that becomes annoying while controlling the character. I do not know the proper term for it ("sticky keys"?) but I will describe it...
When an app or game is written we "expect" the user [...]]]></description>
			<content:encoded><![CDATA[<p>When I am writing a flash app or game which uses the keyboard to control a character's movement, there is a situation that becomes annoying while controlling the character. I do not know the proper term for it ("sticky keys"?) but I will describe it...<img class="alignright" src="/blog/examples/keycontrol/typing.jpg" alt="keyboard" width="264" height="386" /></p>
<p>When an app or game is written we "expect" the user to precisely press the proper key or key combination at a time to execute programmatic actions. However, most of us have ten fingers and we use more than one finger to press more than one button on the keyboard. The expected program reaction from multiple fingered keyboard input might not occur because you have another function executing when you expect just one at a time.<br />
<span id="more-189"></span></p>
<p><strong>Key Combinations</strong><br />
Imagine you are using the keyboard to play a game. The RIGHT arrow key is for moving your character right, the LEFT arrow key is for moving your character LEFT.<br />
Ok, the action in this game is heating up, you are pressing LEFT to avoid the lasers shooting at you. You successfully dodged the lasers, now you press RIGHT to move in and attack...but in the heat of battle, your other finger is still on the LEFT button. What happens now is your character most likely gets stuck, because both movement keys are pressed telling the character to go in opposite directions!</p>
<p>In some cases allowing multiple key presses is how you want the app to react. For example you want the user to press both UP and RIGHT keys to move the characters in a diagonal direction. When to allow this and when not can be different among all of the control buttons. It becomes messy having to write "If" and "switch" statements to make the KeyboardEvent listeners work according to the different controls needed.</p>
<p><strong>Key Sequences</strong><br />
If you love video games cheats or the easter eggs developers sometimes place in apps you'll remember to access them, you will usually enter in a sequence of key presses. If you entered the sequence successfully you would have access to cool game cheats or some special developer mode of an application.</p>
<p><strong>KeyManager</strong><br />
For the above reasons I've written a KeyManager class to add key control that allows individual keys/keycombos the option to cancel out the any previous key/keycombo that are pressed down...and when key/keycombos are released, whatever key/keycombo that are still pressed will be active again. And for detecting key press sequences the KeyManager class will allow also.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_keycontrol_899720308"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://keith-hair.net/blog/examples/keycontrol/keycontrol.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://keith-hair.net/blog/examples/keycontrol/keycontrol.swf"
			name="fm_keycontrol_899720308"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://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>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>This is a basic example using KeyManager. The "addKey" method is for adding key press combos and the "addKeySequence" is for obviously adding<br />
key press sequences.</p>
<p>In the working flash example, you can click "singular combos" checkbox to false, to see the problem described previously about the character getting stuck when pressing RIGHT and LEFT key at the same time. When you set the checkbox back to true you will notice how each new key press overrides any others that are still down. This results in responsive execution if a user has a habit of holding down other keys while pressing new ones..</p>
<p><em><strong>Also in the working sample above if you enter in the proper key sequence you will be rewarded with an "Easter Egg" to view the source and FLA.</strong></em></p>
<p><strong>Example usage:</strong></p>
<pre class="brush: as3;">
import net.keithhair.KeyManager;

var keyManager:KeyManager;
keyManager=new KeyManager(stage);
keyManager.addKey([&quot;right&quot;], goRight,stopRight,&quot;control1&quot;);
keyManager.addKey([&quot;left&quot;], goLeft,stopLeft,&quot;control2&quot;);
keyManager.addKey([&quot;up&quot;], goUp,stopUp,&quot;control3&quot;);
keyManager.addKey([&quot;down&quot;], goDown,stopDown,&quot;control4&quot;);
keyManager.addKey([&quot;shift&quot;,&quot;w&quot;,&quot;t&quot;], toggleWindow);
keyManager.addKeySequence([&quot;up&quot;,&quot;up&quot;,&quot;down&quot;,&quot;down&quot;,&quot;left&quot;,&quot;right&quot;,&quot;left&quot;,&quot;right&quot;],openEasterEgg);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Different signs of Cosine, Sine, and Tangent functions and radians</title>
		<link>http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/</link>
		<comments>http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 18:27:43 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[cartesian]]></category>
		<category><![CDATA[coordinates]]></category>
		<category><![CDATA[Cosine]]></category>
		<category><![CDATA[quadrants]]></category>
		<category><![CDATA[Sine]]></category>
		<category><![CDATA[Tangent]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=176</guid>
		<description><![CDATA[
This post might seem of little importance to some but today I was thinking back to my high school days and (vaguely) remember the 4 quadrants of a Cartesian coordinate plane discussed in class. Depending on the positive or negative sign of a Point's X and Y value, that point in the Cartesian coordinate plane [...]]]></description>
			<content:encoded><![CDATA[<p>
This post might seem of little importance to some but today I was thinking back to my high school days and (vaguely) remember the 4 quadrants of a Cartesian coordinate plane discussed in class. Depending on the positive or negative sign of a Point's X and Y value, that point in the Cartesian coordinate plane will be located in one of these 4 quadrants.</p>
<blockquote><p><strong>Quadrant 1 = (+,+)<br />
Quadrant 2 = (-,+)<br />
Quadrant 3 = (-,-)<br />
Quadrant 4 = (-,+)</strong></p></blockquote>
<p>My interest in this post is about the positive or negative sign of what the Cosine, Sine, and Tangent functions return for the same angle...the angle from one Point to another Point. The sign of these 3 Math functions are different also whenever a Point is located in one of the 4 quadrants.</p>
<blockquote><p><strong>Quadrant 1 = +Sine,+Cosine,+Tangent<br />
Quadrant 2 = +Sine,-Cosine,-Tangent<br />
Quadrant 3 = -Sine,-Cosine,+Tangent<br />
Quadrant 4 = -Sine,+Cosine,-Tangent</strong></p></blockquote>
<p>Personally I don't think the order or name of the quadrants are important, as long as you keep them consistent with the coordinate system. For my usage, I order my quadrants "1,2,3,4" clockwise since ActionScript's radians values go clockwise.</p>
<p>I feel this will become useful sometime in the future for me when dealing with angles of Points and determining their positions relative to each other.<br />
In a future situation I might not be given X and Y information, but may only have angle data instead. Seeing the difference of signs from the Cosign, Sine, Tangent output of the angle value will be helpful clues.</p>
<p>So some things come back to haunt you, if they are the ghosts of my math teachers, I will surely pay attention in class this time <img src='http://keith-hair.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_quadrants_228266897"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/different_signs/quadrants.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/different_signs/quadrants.swf"
			name="fm_quadrants_228266897"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://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>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
<span id="more-176"></span><br />
Note in Flash/Actionscript, (0,0) is wherever you set your registration point of a MovieClip. In this example I centered the registration point in Flash,<br />
so (0,0) of head's coordinate system will sit directly at the center of the head.</p>
<pre class="brush: as3;">
	/*=========================================================
	Using &quot;Math.atan2&quot; to get the angle (in radians) between
	the &quot;reddot&quot; and &quot;head&quot;.

	This radian is fed into the &quot;getSign&quot; function so
	we can see the difference of signs.
	===========================================================*/

	var radians=Math.atan2(reddot.y-head.y,reddot.x-head.x);
	var signs:Object=getSigns(radians);
	var output:String=&quot;&quot;;

	output+=&quot;Sine:&quot;+signs.sine;
	output+=&quot;\n&quot;;
	output+=&quot;Cosine:&quot;+signs.cosine;
	output+=&quot;\n&quot;;
	output+=&quot;Tangent:&quot;+signs.tangent;
	output+=&quot;\n&quot;;
	output+=&quot;\n&quot;;
	output+=&quot;Radians:&quot;+radians;

	status.text=output;
</pre>
<pre class="brush: as3;">
/*============================================
Returns an object indicating the sign
of the radian's Cosine, Sine and Tangent.
==============================================*/
function getSigns(rad:Number):Object
{
	var o:Object=new Object();
	if(Math.sin(rad) &gt;= 0){
		o.sine=&quot;+&quot;;
	}else{
		o.sine=&quot;-&quot;;
	}
	if(Math.cos(rad) &gt;= 0){
		o.cosine=&quot;+&quot;;
	}else{
		o.cosine=&quot;-&quot;;
	}
	if(Math.tan(rad) &gt;= 0){
		o.tangent=&quot;+&quot;;
	}else{
		o.tangent=&quot;-&quot;;
	}
	return o;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m Testing Foam physics in Flex</title>
		<link>http://keith-hair.net/blog/2009/08/01/im-testing-foam-physics-in-flex/</link>
		<comments>http://keith-hair.net/blog/2009/08/01/im-testing-foam-physics-in-flex/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 05:49:35 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[Foam]]></category>
		<category><![CDATA[Physics Engine]]></category>
		<category><![CDATA[Polygons]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=105</guid>
		<description><![CDATA[There are a lot of Flash physics engines available to use. I've only tried Box2D, APE, and Foam.
Foam is my favorite so far. I actually like the options of Box2D better but it's just not as ActionScript-friendly as Foam. 
Foam sets up the easiest of these 3 engines for an ActionScript only project...In my opinion, [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of Flash physics engines available to use. I've only tried Box2D, APE, and Foam.<br />
<a href="http://drawlogic.com/2007/11/07/as3-foam-2d-physics-engine/">Foam </a>is my favorite so far. I actually like the options of Box2D better but it's just not as ActionScript-friendly as Foam. </p>
<p>Foam sets up the easiest of these 3 engines for an ActionScript only project...In my opinion, setting it up to use in my Flex projects takes a little more work depending on what I use it for. Seeing the end result of it is fun to watch.</p>
<p>Below I'm currently using my <a href="/blog/examples/polygon_physics/">polygon editor</a> to test Foam out in Flex.</p>
<p><a href="http://keith-hair.net/blog/examples/polygon_physics/"><img src="/blog/examples/polygon_physics/physics_polygons.jpg" alt="Click to view example" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/08/01/im-testing-foam-physics-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do you make tools to solve your problems?</title>
		<link>http://keith-hair.net/blog/2009/07/18/do-you-make-tools-to-solve-your-problems/</link>
		<comments>http://keith-hair.net/blog/2009/07/18/do-you-make-tools-to-solve-your-problems/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 07:06:17 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash 9]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[interface]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=89</guid>
		<description><![CDATA[Does anyone out there throw together rough tools to solve eccentric problems that drive you nuts?
I run into problems with point data occasionally and it's hard to find a solution for using the data, when I can only view the problem in messy code format.
This sometimes leaves me wondering if the function I'm writing is [...]]]></description>
			<content:encoded><![CDATA[<p>Does anyone out there throw together rough tools to solve eccentric problems that drive you nuts?</p>
<p>I run into problems with point data occasionally and it's hard to find a solution for using the data, when I can only view the problem in messy code format.<br />
This sometimes leaves me wondering if the function I'm writing is even working correctly or not.<br />
&nbsp;<br />
The example below is a rough tool I made to visualize and edit the Array format of points I usually work with. Over time I have transformed, gutted, and replace its code for different tests I needed it for. (The insides are not pretty.)<br />
Yep it looks like a drawing tool, just not intended for that. I've only added certain "drawing" features I needed to make it easy to visualize the data I'm working on.</p>
<p><a href="http://keith-hair.net/blog/examples/pointtool/"><img src="/blog/examples/pointtool/pointtool.jpg" alt="Click to see example" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/07/18/do-you-make-tools-to-solve-your-problems/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Know where a Point is relevant to a Segment</title>
		<link>http://keith-hair.net/blog/2009/05/28/know-where-a-point-is-relevant-to-a-segment/</link>
		<comments>http://keith-hair.net/blog/2009/05/28/know-where-a-point-is-relevant-to-a-segment/#comments</comments>
		<pubDate>Thu, 28 May 2009 07:35:45 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Intersection]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[Placement]]></category>
		<category><![CDATA[Point]]></category>
		<category><![CDATA[Relavant]]></category>
		<category><![CDATA[Segment]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=68</guid>
		<description><![CDATA[Looking at my previous post I felt the isBehindLine function served it's purpose, but if I get a more complicated problem similar to a raycasting test with imaginary ray of arbitrary width I would need to know more information where a Point is relevant to a Segment. 
The "whereAboutSegment" function will return a String this [...]]]></description>
			<content:encoded><![CDATA[<p>Looking at my previous post I felt the <a href="http://keith-hair.net/blog/2009/05/27/knowing-if-a-point-is-behind-a-line">isBehindLine </a>function served it's purpose, but if I get a more complicated problem similar to a raycasting test with imaginary ray of arbitrary width I would need to know more information where a Point is relevant to a Segment. </p>
<p>The "whereAboutSegment" function will return a String this time, with more detailed info of the Point's where-a-abouts instead of just knowing if its behind a line.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_where_about_segment_1107320201"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/intersections/where_about_segment.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/intersections/where_about_segment.swf"
			name="fm_where_about_segment_1107320201"
			width="550"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><span id="more-68"></span></p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">/*-----------------------------------------------------------------
Returns a String describing where Point P is relevant to line CD:
&quot;left&quot;,&quot;right&quot;,&quot;front&quot; or &quot;behind&quot;
If Point P is a Point on line CD, an empty String is returned.
 ----------------------------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> whereAboutSegment<span style="color: #66cc66;">&#40;</span>P:Point,C:Point,D:Point<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> F:Point;
	<span style="color: #000000; font-weight: bold;">var</span> G:Point;
	<span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">Boolean</span>;
	<span style="color: #000000; font-weight: bold;">var</span> l:<span style="color: #0066CC;">Boolean</span>;
	<span style="color: #000000; font-weight: bold;">var</span> r:<span style="color: #0066CC;">Boolean</span>;
	<span style="color: #000000; font-weight: bold;">var</span> f:<span style="color: #0066CC;">Boolean</span>;
	<span style="color: #000000; font-weight: bold;">var</span> a:<span style="color: #0066CC;">Number</span>=Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>P,C.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> / <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> b:<span style="color: #0066CC;">Number</span>=Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>P,C.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">-1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> / <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	s = a == b;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>a &lt; b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		f=<span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
	F=C.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	G=C.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">-1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	a=Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>P,F.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	b=Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>P,G.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">-1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>a &lt; b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		r=<span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
	F=D.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	G=D.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">-1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	a=Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>P,F.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	b=Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>P,G.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">-1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>a &gt; b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		l=<span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>s &amp;&amp; l &amp;&amp; r<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!f &amp;&amp; l &amp;&amp; r<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;behind&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>f &amp;&amp; l &amp;&amp; r<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;front&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>l<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;left&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>r<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;right&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/05/28/know-where-a-point-is-relevant-to-a-segment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Knowing if a Point is behind a Line</title>
		<link>http://keith-hair.net/blog/2009/05/27/knowing-if-a-point-is-behind-a-line/</link>
		<comments>http://keith-hair.net/blog/2009/05/27/knowing-if-a-point-is-behind-a-line/#comments</comments>
		<pubDate>Wed, 27 May 2009 21:15:01 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[SciFi]]></category>
		<category><![CDATA[Behind]]></category>
		<category><![CDATA[Line]]></category>
		<category><![CDATA[Points]]></category>
		<category><![CDATA[Test]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=58</guid>
		<description><![CDATA[Yea yea, I know Battlestar Galactica is over, but today I thought of the "Daybreak part 1" episode of BSG.
Hera, a little girl has been kidnapped by the Cylons. As part of a desperate plan to save Hera, Admiral Adama draws a red line on the deck, and asks for those willing to risk their [...]]]></description>
			<content:encoded><![CDATA[<p>Yea yea, I know Battlestar Galactica is over, but today I thought of the <a href="http://www.scifi.com/battlestar/episodes/episodes.php?seas=4&#038;ep=421&#038;act=3">"Daybreak part 1" episode of BSG</a>.<br />
Hera, a little girl has been kidnapped by the Cylons. As part of a desperate plan to save Hera, Admiral Adama draws a red line on the deck, and asks for those willing to risk their lives to save her, do so by crossing the line.</p>
<p>I had a similar problem also with my scripts. I wanted to simply know if a Point was behind a Line or not... <img src='http://keith-hair.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_behind_line_863740910"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/intersections/behind_line.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/intersections/behind_line.swf"
			name="fm_behind_line_863740910"
			width="550"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><span id="more-58"></span></p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">/*-----------------------------------------------------------------
Returns true if Point P is behind line defined by Points C and D.
 ----------------------------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> isBehindLine<span style="color: #66cc66;">&#40;</span>P:Point,C:Point,D:Point<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> a:<span style="color: #0066CC;">Number</span>=Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>P,C.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> / <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> b:<span style="color: #0066CC;">Number</span>=Point.<span style="color: #006600;">distance</span><span style="color: #66cc66;">&#40;</span>P,C.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>Point.<span style="color: #006600;">polar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">-1</span>,<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">atan2</span><span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">y</span> - D.<span style="color: #006600;">y</span>,C.<span style="color: #006600;">x</span> - D.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span> / <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">return</span> a &lt; b;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/05/27/knowing-if-a-point-is-behind-a-line/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Find intersection of a Line and Quadratic Curve</title>
		<link>http://keith-hair.net/blog/2009/05/19/find-intersection-of-a-line-and-quadratic-curve/</link>
		<comments>http://keith-hair.net/blog/2009/05/19/find-intersection-of-a-line-and-quadratic-curve/#comments</comments>
		<pubDate>Wed, 20 May 2009 00:21:54 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Curves]]></category>
		<category><![CDATA[Intersection]]></category>
		<category><![CDATA[Line]]></category>
		<category><![CDATA[Point]]></category>
		<category><![CDATA[Quadratic]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=41</guid>
		<description><![CDATA[After writing a function to test intersections of a line to a polygon, another problem came up where I needed
to test an intersection of a line to a curve. I'm sure there is a library someone has wrote that could do this but there is some fun in figuring out puzzles.
There was a recent comment [...]]]></description>
			<content:encoded><![CDATA[<p>After writing a function to test intersections of a line to a polygon, another problem came up where I needed<br />
to test an intersection of a line to a curve. I'm sure there is a library someone has wrote that could do this but there is some fun in figuring out puzzles.<br />
There was a recent comment about curves and intersections so I decided to go ahead an post what I attempted.<br />
I feel using a loop is expensive, but it's all I can think of doing for this, similar to the <a href="http://keith-hair.net/blog/2008/08/08/line-to-polygon-intersection-data/">lineIntersectPoly </a>function.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_line_to_curve_intersection_1047949409"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/curves/line_to_curve_intersection.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/curves/line_to_curve_intersection.swf"
			name="fm_line_to_curve_intersection_1047949409"
			width="550"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
<span id="more-41"></span></p>
<pre class="actionscript">&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------------------------------------------------------
Returns Array of intersection Points on a quadratic curve.
An empty Array is returned if no intersection is found.
&nbsp;
Parameters:
A		-Start Point of a segment to make intersection.
B		-End Point of a segment to make intersection.
sp		-Start Point of curve.
cp		-Control Point of curve.
ep		-End Point of curve.
rez		-The resolution of curve tests
Note: Uses another function for testing the intersections:
&nbsp;
http://keith-hair.net/blog/2008/08/04/find-intersection-point-of-two-lines-in-as3/
&nbsp;
----------------------------------------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> lineToQCurve_Intersect<span style="color: #66cc66;">&#40;</span>A:Point,B:Point,sp:Point,cp:Point,ep:Point,rez:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">80</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Array</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//rez less than 2 is almost &quot;Pointless&quot; LOL.</span>
	<span style="color: #000000; font-weight: bold;">var</span> low:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">2</span>;
	<span style="color: #000000; font-weight: bold;">var</span> high:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">99</span>; <span style="color: #808080; font-style: italic;">//100 causes infinite loop.</span>
	rez=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>low,high<span style="color: #66cc66;">&#41;</span>,rez<span style="color: #66cc66;">&#41;</span>,high<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> t:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> ft:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> n:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">99</span>/rez;
	<span style="color: #000000; font-weight: bold;">var</span> C:Point=<span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> D:Point=<span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> L:Point=<span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> ip:Point;
	<span style="color: #000000; font-weight: bold;">var</span> a:<span style="color: #0066CC;">Array</span>=<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #808080; font-style: italic;">//test possible segment intersections in a loop.</span>
	<span style="color: #000000; font-weight: bold;">var</span> z:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">100</span>;
	<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>z &gt; <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		t=z/<span style="color: #cc66cc;">100</span>;
		C.<span style="color: #006600;">x</span>=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">pow</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>-t,<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>*sp.<span style="color: #006600;">x</span><span style="color: #cc66cc;">+2</span>*<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>-t<span style="color: #66cc66;">&#41;</span>*t*cp.<span style="color: #006600;">x</span>+<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">pow</span><span style="color: #66cc66;">&#40;</span>t,<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>*ep.<span style="color: #006600;">x</span>;
		C.<span style="color: #006600;">y</span>=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">pow</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>-t,<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>*sp.<span style="color: #006600;">y</span><span style="color: #cc66cc;">+2</span>*<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>-t<span style="color: #66cc66;">&#41;</span>*t*cp.<span style="color: #006600;">y</span>+<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">pow</span><span style="color: #66cc66;">&#40;</span>t,<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>*ep.<span style="color: #006600;">y</span>;
		D=L;<span style="color: #808080; font-style: italic;">//Connect start to last end point</span>
		L=C.<span style="color: #006600;">clone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>z == <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			D=ep.<span style="color: #006600;">clone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		ip=lineIntersectLine<span style="color: #66cc66;">&#40;</span>A,B,C,D<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ip != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			a.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>ip<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>a.<span style="color: #0066CC;">length</span> == <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">break</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
		z-=n;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> a;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/05/19/find-intersection-of-a-line-and-quadratic-curve/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Matrix transforms based on an arbitrary registration point</title>
		<link>http://keith-hair.net/blog/2009/01/24/matrix-transforms-based-on-an-arbitrary-registration-point/</link>
		<comments>http://keith-hair.net/blog/2009/01/24/matrix-transforms-based-on-an-arbitrary-registration-point/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 06:05:23 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash 9]]></category>
		<category><![CDATA[Arbitrary]]></category>
		<category><![CDATA[Matrix]]></category>
		<category><![CDATA[Registration Point]]></category>
		<category><![CDATA[Skew]]></category>
		<category><![CDATA[Transform]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=28</guid>
		<description><![CDATA[I was wanting a lightweight function to resize, rotate, and skew DisplayObjects based on a dynamic registration point so I made a function to apply my desired matrix settings.
One thing that bothers me is that I could not figure out how to skew along the X and Y axis at the same time. When I [...]]]></description>
			<content:encoded><![CDATA[<p>I was wanting a lightweight function to resize, rotate, and skew DisplayObjects based on a dynamic registration point so I made a function to apply my desired matrix settings.</p>
<p>One thing that bothers me is that I could not figure out how to skew along the X and Y axis at the same time. When I do set "c" and "b" Matrix properties, one of the skewed axis does not skew parallel like it should. And if I concatenate separate skew Matrices, the last concatenated skew Matrix transforms correctly but not the one before it. I'm trying to avoid using nested DisplayObjects to perform the separate X and Y skews, but that looks like an option I will have to use.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_matrix_example_243716636"
			class="flashmovie"
			width="550"
			height="600">
	<param name="movie" value="/blog/examples/matrix/matrix_example.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/matrix/matrix_example.swf"
			name="fm_matrix_example_243716636"
			width="550"
			height="600">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
<span id="more-28"></span></p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------------------------------------------------------
Sets the transform property of DisplayObject with a customized Matrix.
&nbsp;
display			-An ActionScript DisplayObject.
tx					-Translation x.
ty					-Translation y.
reg				-Registation point from which all transform effects orient from.
ang				-Rotation in in degrees.
scalex				-X scale percentage.
scaley				-Y scale percentage.
skew				-Skew percentage of the DisplayObjects width or height.
axis				-String indicating which axis to skew on.
&nbsp;
Note:	-The &quot;skew&quot; argument only works one axis at a time, If anyone knows
		 how to skew on both X and Y axis at the same time accurately please help me.
&nbsp;
		-The &quot;reg&quot; Registration point get scaled by scalex and scaley.		 
&nbsp;
----------------------------------------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> setDisplayMatrix<span style="color: #66cc66;">&#40;</span>display:DisplayObject,
						  tx:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>,
						  ty:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>,
						  reg:Point=<span style="color: #000000; font-weight: bold;">null</span>,
						  ang:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>,
						  scalex:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">1</span>,
						  scaley:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">1</span>,
						  skew:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>,
						  axis:<span style="color: #0066CC;">String</span>=<span style="color: #ff0000;">&quot;x&quot;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	reg=reg||new Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> curM:Matrix=<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> skewM:Matrix=<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> rotM:Matrix=<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> scaleM:Matrix=<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> rp:Point;
	<span style="color: #000000; font-weight: bold;">var</span> r:<span style="color: #0066CC;">Number</span>=ang*<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>/<span style="color: #cc66cc;">180</span>;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>axis == <span style="color: #ff0000;">&quot;y&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		skewM.<span style="color: #006600;">c</span>=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">tan</span><span style="color: #66cc66;">&#40;</span>skew<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
		skewM.<span style="color: #006600;">b</span>=<span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">tan</span><span style="color: #66cc66;">&#40;</span>skew<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	scaleM.<span style="color: #006600;">scale</span><span style="color: #66cc66;">&#40;</span>scalex,scaley<span style="color: #66cc66;">&#41;</span>;
	rotM.<span style="color: #006600;">rotate</span><span style="color: #66cc66;">&#40;</span>r<span style="color: #66cc66;">&#41;</span>;
	curM.<span style="color: #0066CC;">concat</span><span style="color: #66cc66;">&#40;</span>scaleM<span style="color: #66cc66;">&#41;</span>;
	curM.<span style="color: #0066CC;">concat</span><span style="color: #66cc66;">&#40;</span>skewM<span style="color: #66cc66;">&#41;</span>;
	curM.<span style="color: #0066CC;">concat</span><span style="color: #66cc66;">&#40;</span>rotM<span style="color: #66cc66;">&#41;</span>;
	rp=curM.<span style="color: #006600;">transformPoint</span><span style="color: #66cc66;">&#40;</span>reg<span style="color: #66cc66;">&#41;</span>;
	curM.<span style="color: #006600;">tx</span>=-rp.<span style="color: #006600;">x</span>;
	curM.<span style="color: #006600;">ty</span>=-rp.<span style="color: #006600;">y</span>;
	curM.<span style="color: #006600;">tx</span>+=tx;
	curM.<span style="color: #006600;">ty</span>+=ty;
	display.<span style="color: #006600;">transform</span>.<span style="color: #006600;">matrix</span>=curM;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Here is a diagram I made to show what kind of skew I wanted to achieve instead of only skewing one axis at a time:<br />
<img src="/blog/examples/matrix/skew_diagram.gif" alt="The type of skews I want to achieve." /></p>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/01/24/matrix-transforms-based-on-an-arbitrary-registration-point/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Constrain a Point to a Line</title>
		<link>http://keith-hair.net/blog/2008/12/27/constrain-a-point-to-a-line/</link>
		<comments>http://keith-hair.net/blog/2008/12/27/constrain-a-point-to-a-line/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 17:42:20 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Constrain]]></category>
		<category><![CDATA[Line]]></category>
		<category><![CDATA[Point]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=27</guid>
		<description><![CDATA["Drag and Drop" behavior is easy to do in ActionScript, but sometimes it would be cooler if you could limit or constrain the dragging movement of an object to a line. This opens the door for implementing
more creative interaction design...

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ctoline_582206351"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/constrain/ctoline.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/constrain/ctoline.swf"
			name="fm_ctoline_582206351"
			width="550"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>

&#160;
/*---------------------------------------------------------------------------
Returns the closest Point on Line &#34;AB&#34; to Point &#34;p&#34;:
&#160;
p			-Point, the Point [...]]]></description>
			<content:encoded><![CDATA[<p>"Drag and Drop" behavior is easy to do in ActionScript, but sometimes it would be cooler if you could limit or constrain the dragging movement of an object to a line. This opens the door for implementing<br />
more creative interaction design...</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ctoline_1016704962"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/constrain/ctoline.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/constrain/ctoline.swf"
			name="fm_ctoline_1016704962"
			width="550"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><span id="more-27"></span></p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------------------------------------------------------
Returns the closest Point on Line &quot;AB&quot; to Point &quot;p&quot;:
&nbsp;
p			-Point, the Point to constrain to the line.
A			-Point, beginning Point of Line.
B			-Point, ending Point of Line.
as_seg	-Boolean, limits return Point between endpoints of A and B.
----------------------------------------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> constrainPointToLine<span style="color: #66cc66;">&#40;</span>p:Point,A:Point,B:Point,as_seg:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>:Point
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> cp:Point=<span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> dx:<span style="color: #0066CC;">Number</span>;
    <span style="color: #000000; font-weight: bold;">var</span> dy:<span style="color: #0066CC;">Number</span>;
    <span style="color: #000000; font-weight: bold;">var</span> t:<span style="color: #0066CC;">Number</span>;
&nbsp;
    dx = B.<span style="color: #006600;">x</span> - A.<span style="color: #006600;">x</span>;
    dy = B.<span style="color: #006600;">y</span> - A.<span style="color: #006600;">y</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>dx == <span style="color: #cc66cc;">0</span> &amp;&amp; dy == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        cp.<span style="color: #006600;">x</span> = A.<span style="color: #006600;">x</span>;
        cp.<span style="color: #006600;">y</span> = A.<span style="color: #006600;">y</span>;
    <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
        t = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>p.<span style="color: #006600;">x</span> - A.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span> * dx + <span style="color: #66cc66;">&#40;</span>p.<span style="color: #006600;">y</span> - A.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span> * dy<span style="color: #66cc66;">&#41;</span> / <span style="color: #66cc66;">&#40;</span>dx * dx + dy * dy<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>as_seg<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			t = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,t<span style="color: #66cc66;">&#41;</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
        cp.<span style="color: #006600;">x</span> = A.<span style="color: #006600;">x</span> + t * dx;
        cp.<span style="color: #006600;">y</span> = A.<span style="color: #006600;">y</span> + t * dy;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> cp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2008/12/27/constrain-a-point-to-a-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
