<?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</title>
	<atom:link href="http://keith-hair.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://keith-hair.net/blog</link>
	<description>Scripting is fun like any other hobby</description>
	<lastBuildDate>Mon, 08 Jun 2009 23:56:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Follow Freeman!</title>
		<link>http://keith-hair.net/blog/2009/06/08/follow-freeman/</link>
		<comments>http://keith-hair.net/blog/2009/06/08/follow-freeman/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 23:51:21 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Episode 3]]></category>
		<category><![CDATA[Gordon Freeman]]></category>
		<category><![CDATA[Half Life 2]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=80</guid>
		<description><![CDATA[I played some Half-Life 2 today, there's a lot of creativity that went into this game. As I played it again today it gave me a few laughs.
If you played the first installment of Half-Life 2, you may remember the NPC characters frequently shouting "Follow Freeman".
As the NPC characters stood around idle, they would make [...]]]></description>
			<content:encoded><![CDATA[<p>I played some Half-Life 2 today, there's a lot of creativity that went into this game. As I played it again today it gave me a few laughs.</p>
<p>If you played the first installment of Half-Life 2, you may remember the NPC characters frequently shouting "Follow Freeman".<br />
As the NPC characters stood around idle, they would make comments that sound as if they where on Twitter. LOL</p>
<p><img src="http://keith-hair.net/images/follow_freeman.jpg" alt="Follow Freeman!" /></p>
</p>
<p>Way back when the original Half-Life game came out and I played it on my ancient 3Dfx Voodoo card, the graphics blew me away. I've been loving the whole Half Life series and wait in anticipation for the next episode.<br />
I was disappointed that there was not much news of Half-Life 2 Episode 3 this year, so lately I been going back into time to enjoy the beginning of Half Life 2. I thought Half-Life 1 set the bar.<br />
This game set the bar again, the experience is so well done, that the replay value is good even for single player mode. I have lots PC games, once I finish one, I uninstall it. This is one of the few games I have worthy of staying installed for years.</p>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/06/08/follow-freeman/feed/</wfw:commentRss>
		<slash:comments>0</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	type="application/x-shockwave-flash"
			data="/blog/examples/intersections/where_about_segment.swf"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/intersections/where_about_segment.swf" />
</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	type="application/x-shockwave-flash"
			data="/blog/examples/intersections/behind_line.swf"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/intersections/behind_line.swf" />
</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	type="application/x-shockwave-flash"
			data="/blog/examples/curves/line_to_curve_intersection.swf"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/curves/line_to_curve_intersection.swf" />
</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:
http://keith-hair.net/blog/2008/08/04/find-intersection-point-of-two-lines-in-as3/
----------------------------------------------------------------------------*/</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>Letting DisplayObjects Find the Main WindowedApplication in AIR</title>
		<link>http://keith-hair.net/blog/2009/04/30/letting-displayobjects-find-the-main-windowedapplication-in-air/</link>
		<comments>http://keith-hair.net/blog/2009/04/30/letting-displayobjects-find-the-main-windowedapplication-in-air/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 20:48:59 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Cursor]]></category>
		<category><![CDATA[WindowedApplication]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=29</guid>
		<description><![CDATA[Here is a way to let a DisplayObject find the main WindowedApplication on its own...
In my AIR application I have other AIR Windows floating over the main AIR Window.
I wanted one of my UIComponents to be draggable like a cursor, but when my mouse dragged the object
over the other floating windows I wanted my original [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a way to let a DisplayObject find the main WindowedApplication on its own...</p>
<p>In my AIR application I have other AIR Windows floating over the main AIR Window.<br />
I wanted one of my UIComponents to be draggable like a cursor, but when my mouse dragged the object<br />
over the other floating windows I wanted my original cursor to show again and hide my dragged UIComponent.</p>
<p>The reason behind this is if I wanted to apply "context sensitive" behaviors depending on what or which window the mouse is in.</p>
<p>To do this, the main WindowedApplication needed some ROLL_OUT and ROLL_OVER events added to it to detect when the mouse rolls in and out.<br />
The "getAIRAppWindow" method below finds the main WindowedApplication so I can add the listeners to it from there.</p>
<p>Here are some snippets explaining what I did:</p>
<p><span id="more-29"></span></p>
<p><strong>The method needed to find main WindowedApplication</strong></p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">/*----------------------------------------------------------
Finds the main WindowedApplication of an AIR application
from any UIComponent and returns it.
------------------------------------------------------------*/</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getAIRAppWindow<span style="color: #66cc66;">&#40;</span>p:DisplayObjectContainer<span style="color: #66cc66;">&#41;</span>:WindowedApplication
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> c:*=p;
	<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>c.<span style="color: #006600;">parent</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>c is WindowedApplication<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
					<span style="color: #b1b100;">return</span> WindowedApplication<span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
			c=c.<span style="color: #006600;">parent</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p><strong><br />
Adding events to detect mouse in main Windowed Application</strong></p>
<pre class="actionscript">&nbsp;
_windowedApp=getAIRAppWindow<span style="color: #66cc66;">&#40;</span>parent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
_windowedApp.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">ROLL_OUT</span>,__onMouseOutWorkSpace<span style="color: #66cc66;">&#41;</span>;
_windowedApp.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">ROLL_OVER</span>,__onMouseInWorkSpace<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p><strong><br />
Example of actions to apply on ROLL_OUT and ROLL_OVER</strong></p>
<pre class="actionscript">&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __onMouseOutWorkSpace<span style="color: #66cc66;">&#40;</span>evt:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/*--------------------------------------------------------
	When your mouse rolls out of the main WindowedApplication
	(and into other nested Windows) you can make your regular
	mouse cursor show again here, while hiding your custom cursor.
	----------------------------------------------------------*/</span>
	yourCustomCursor.<span style="color: #0066CC;">visible</span>=<span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #0066CC;">Mouse</span>.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __onMouseInWorkSpace<span style="color: #66cc66;">&#40;</span>evt:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/*--------------------------------------------------------
	When your mouse rolls back in the main WindowedApplication
	(and out of other nested Windows) you can hide your regular
	mouse cursor, while showing your custom cursor again.
	----------------------------------------------------------*/</span>
	yourCustomCursor.<span style="color: #0066CC;">visible</span>=<span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #0066CC;">Mouse</span>.<span style="color: #0066CC;">hide</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/04/30/letting-displayobjects-find-the-main-windowedapplication-in-air/feed/</wfw:commentRss>
		<slash:comments>0</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	type="application/x-shockwave-flash"
			data="/blog/examples/matrix/matrix_example.swf"
			width="550"
			height="600">
	<param name="movie" value="/blog/examples/matrix/matrix_example.swf" />
</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>3</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	type="application/x-shockwave-flash"
			data="/blog/examples/constrain/ctoline.swf"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/constrain/ctoline.swf" />
</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	type="application/x-shockwave-flash"
			data="/blog/examples/constrain/ctoline.swf"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/constrain/ctoline.swf" />
</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>
		<item>
		<title>Cylons vs Terminators</title>
		<link>http://keith-hair.net/blog/2008/10/15/cylons-vs-terminators/</link>
		<comments>http://keith-hair.net/blog/2008/10/15/cylons-vs-terminators/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 01:36:19 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[SciFi]]></category>
		<category><![CDATA[Cylons]]></category>
		<category><![CDATA[polls]]></category>
		<category><![CDATA[Terminator]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=26</guid>
		<description><![CDATA[ Judging by intelligence and strength, which robot life form would win in a battle to extinction?    (  polls)Both machines have demonstrated creative uses of intelligent strategy and brute force in various movies and TV shows.
All specs and info from movies and literature is fair game...so who do you'd think would [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript" language="javascript" src="http://s3.polldaddy.com/p/1000117.js"></script><noscript> <a href ="http://answers.polldaddy.com/poll/1000117/" >Judging by intelligence and strength, which robot life form would win in a battle to extinction?</a>  <br/> <span style="font-size:9px;"> (<a href ="http://www.polldaddy.com">  polls</a>)</span></noscript>Both machines have demonstrated creative uses of intelligent strategy and brute force in various movies and TV shows.<br />
All specs and info from movies and literature is fair game...so who do you'd think would win and why.</p>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2008/10/15/cylons-vs-terminators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resizing width and height proportionately</title>
		<link>http://keith-hair.net/blog/2008/10/13/resizing-width-and-height-proportionately/</link>
		<comments>http://keith-hair.net/blog/2008/10/13/resizing-width-and-height-proportionately/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 06:06:36 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Constrain Proportion]]></category>
		<category><![CDATA[Porportional]]></category>
		<category><![CDATA[Resize]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=25</guid>
		<description><![CDATA[If you use Photoshop you probably appreciate the "Constrain Proportions" checkbox found in some of the application's dialogs and menus.
I like to have this same ability when I'm writing ActionScript to resize objects proportionately too.
Here I use the functions to set the sizes so when I set width, height is changed accordingly.
The same for setting [...]]]></description>
			<content:encoded><![CDATA[<p>If you use Photoshop you probably appreciate the "Constrain Proportions" checkbox found in some of the application's dialogs and menus.</p>
<p>I like to have this same ability when I'm writing ActionScript to resize objects proportionately too.<br />
Here I use the functions to set the sizes so when I set width, height is changed accordingly.<br />
The same for setting height, the width is changed accordingly.</p>
<p><em>*Note: I set the inputs to limit the width and height to 500.</em><br />

<object	type="application/x-shockwave-flash"
			data="/blog/examples/sizing/constrain_size.swf"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/sizing/constrain_size.swf" />
</object>
<p>Here are two functions for performing proportional resizing by both width and height...<br />
<span id="more-25"></span></p>
<pre class="actionscript"><span style="color: #808080; font-style: italic;">/*---------------------------------------------
Resize proportionately by width.
Returns an Object with new proportionate &quot;width&quot; and &quot;height&quot; properties.
After passing the current width, current height and  a new width.
-----------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> constrainSizeToWidth<span style="color: #66cc66;">&#40;</span>oldW:<span style="color: #0066CC;">Number</span>,oldH:<span style="color: #0066CC;">Number</span>,newW:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">width</span>:newW,<span style="color: #0066CC;">height</span>:newW / oldW * oldH<span style="color: #66cc66;">&#125;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------------------------
Resize proportionately by height.
Returns an Object with new proportionate &quot;width&quot; and &quot;height&quot; properties.
After passing the current width, current height and  a new height.
-----------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> constrainSizeToHeight<span style="color: #66cc66;">&#40;</span>oldW:<span style="color: #0066CC;">Number</span>,oldH:<span style="color: #0066CC;">Number</span>,newH:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">width</span>:newH / oldH * oldW,<span style="color: #0066CC;">height</span>:newH<span style="color: #66cc66;">&#125;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2008/10/13/resizing-width-and-height-proportionately/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Line to Polygon intersection data</title>
		<link>http://keith-hair.net/blog/2008/08/08/line-to-polygon-intersection-data/</link>
		<comments>http://keith-hair.net/blog/2008/08/08/line-to-polygon-intersection-data/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 03:59:24 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Intersection]]></category>
		<category><![CDATA[Line]]></category>
		<category><![CDATA[Point]]></category>
		<category><![CDATA[Polygon]]></category>

		<guid isPermaLink="false">http://keith-hair.com/blog/?p=24</guid>
		<description><![CDATA[This Actionscript 3 function returns some properties that are about a line-to-polygon intersection.
It's useful for knowing all intersection points of a segment intersecting with a polygon, and knowing if the end points of the segment are inside the polygon.

<object	type="application/x-shockwave-flash"
			data="/blog/examples/intersections/line_to_polygon_intersection.swf"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/intersections/line_to_polygon_intersection.swf" />
</object>

This uses the "lineIntersectLine" function of the earlier post.
&#160;
/*---------------------------------------------------------------------------
Returns an Object with the [...]]]></description>
			<content:encoded><![CDATA[<p>This Actionscript 3 function returns some properties that are about a line-to-polygon intersection.<br />
It's useful for knowing all intersection points of a segment intersecting with a polygon, and knowing if the end points of the segment are inside the polygon.</p>

<object	type="application/x-shockwave-flash"
			data="/blog/examples/intersections/line_to_polygon_intersection.swf"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/intersections/line_to_polygon_intersection.swf" />
</object>
<p><span id="more-24"></span></p>
<p>This uses the "<a href="http://keith-hair.net/blog/2008/08/04/find-intersection-point-of-two-lines-in-as3/">lineIntersectLine</a>" function of the earlier post.</p>
<pre class="actionscript">&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------------------------------------------------------
Returns an Object with the following properties:
intersects        -Boolean indicating if an intersection exists.
start_inside      -Boolean indicating if Point A is inside of the polygon.
end_inside       -Boolean indicating if Point B is inside of the polygon.
intersections    -Array of intersection Points along the polygon.
centroid          -A Point indicating &quot;center of mass&quot; of the polygon.
&nbsp;
&quot;pa&quot; is an Array of Points.
----------------------------------------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> lineIntersectPoly<span style="color: #66cc66;">&#40;</span>A : Point, B : Point, pa:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> An:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">1</span>;
	<span style="color: #000000; font-weight: bold;">var</span> Bn:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">1</span>;
	<span style="color: #000000; font-weight: bold;">var</span> C:Point;
	<span style="color: #000000; font-weight: bold;">var</span> D:Point;
	<span style="color: #000000; font-weight: bold;">var</span> i:Point;
	<span style="color: #000000; font-weight: bold;">var</span> cx:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> cy:<span style="color: #0066CC;">Number</span>=<span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> result:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	pa.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>pa<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	result.<span style="color: #006600;">intersects</span> = <span style="color: #000000; font-weight: bold;">false</span>;
	result.<span style="color: #006600;">intersections</span>=<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
	result.<span style="color: #006600;">start_inside</span>=<span style="color: #000000; font-weight: bold;">false</span>;
	result.<span style="color: #006600;">end_inside</span>=<span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #000000; font-weight: bold;">var</span> n:<span style="color: #0066CC;">int</span>=pa.<span style="color: #006600;">length</span><span style="color: #cc66cc;">-1</span>;
	<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>n &gt; <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		C=Point<span style="color: #66cc66;">&#40;</span>pa<span style="color: #66cc66;">&#91;</span>n<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>n &gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			cx+=C.<span style="color: #006600;">x</span>;
			cy+=C.<span style="color: #006600;">y</span>;
			D=Point<span style="color: #66cc66;">&#40;</span>pa<span style="color: #66cc66;">&#91;</span>n<span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>||Point<span style="color: #66cc66;">&#40;</span>pa<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			i=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>i != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				result.<span style="color: #006600;">intersections</span>.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>lineIntersectLine<span style="color: #66cc66;">&#40;</span>A,<span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">x</span>+D.<span style="color: #006600;">x</span>,A.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>,C,D<span style="color: #66cc66;">&#41;</span> != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				An++;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>lineIntersectLine<span style="color: #66cc66;">&#40;</span>B,<span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>C.<span style="color: #006600;">x</span>+D.<span style="color: #006600;">x</span>,B.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span>,C,D<span style="color: #66cc66;">&#41;</span> != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				Bn++;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
		n--;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>An % <span style="color: #cc66cc;">2</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		result.<span style="color: #006600;">start_inside</span>=<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>Bn % <span style="color: #cc66cc;">2</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		result.<span style="color: #006600;">end_inside</span>=<span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
	result.<span style="color: #006600;">centroid</span>=<span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>cx/<span style="color: #66cc66;">&#40;</span>pa.<span style="color: #006600;">length</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>,cy/<span style="color: #66cc66;">&#40;</span>pa.<span style="color: #006600;">length</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	result.<span style="color: #006600;">intersects</span> = result.<span style="color: #006600;">intersections</span>.<span style="color: #0066CC;">length</span> &gt; <span style="color: #cc66cc;">0</span>;
	<span style="color: #b1b100;">return</span> result;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2008/08/08/line-to-polygon-intersection-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
