<?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>AlecMcE.com &#187; math</title>
	<atom:link href="http://alecmce.com/category/math/feed" rel="self" type="application/rss+xml" />
	<link>http://alecmce.com</link>
	<description>Coding on the Flash Platform</description>
	<lastBuildDate>Thu, 12 Aug 2010 21:32:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Parabolas and Quadratic Bezier Curves</title>
		<link>http://alecmce.com/as3/parabolas-and-quadratic-bezier-curves</link>
		<comments>http://alecmce.com/as3/parabolas-and-quadratic-bezier-curves#comments</comments>
		<pubDate>Tue, 10 Aug 2010 15:00:34 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=923</guid>
		<description><![CDATA[As a follow-up to my as3geometry update on parabolas and quadratic bezier curves, I wanted to record the mathematics used to make the translation from parabola to quadratic bezier curve. Hoping to avoid the work of thinking about this for myself, I went online to understand the relationship, but could not find the calculation explained [...]]]></description>
			<content:encoded><![CDATA[<p>As a follow-up to my <a href="http://github.com/alecmce/as3geometry">as3geometry</a> update on parabolas and quadratic bezier curves, I wanted to record the mathematics used to make the translation from parabola to quadratic bezier curve. Hoping to avoid the work of thinking about this for myself, I went online to understand the relationship, but could not find the calculation explained anywhere. The answer presented itself once I started to draw this diagram in Illustrator. It is amazing how a well-drawn, careful diagram can give you the insights you need!</p>
<p><img src="http://alecmce.com/wp-content/uploads/2010/08/parabola-quadratic_bezier1.png" alt="" title="Parabola &amp; Quadratic Bezier Curve" width="276" height="341" style="float: left; border: 0px; padding-top: 5px; padding-bottom: 5px; padding-right: 20px" /></p>
<p>The parabola is defined by the directrix AB and the focus C</p>
<p>It was apparent from the diagram that:</p>
<ul>
<li>H is the midpoint of the line segment AC;</li>
<li>AD is perpendicular to AB, and HD is perpendicular to AC, so D can be calculated as the intersection of these lines;</li>
<li>J is the midpoint of the line segment BC;</li>
<li>BE is perpendicular to AB and JE is perpendicular to BC, so E can be calculated as the intersection of these lines;</li>
<li>K is the intersection of the lines JE and HD, so E can be calculated as the intersection of these lines;</li>
<li>The parabolic segment defined by the line segment directrix AB and the focus C is also defined by a quadratic bezier curve with the start point D, the end point E and the control point K.</li>
</ul>
<p>The full calculation (with some different variable names I&#8217;m afraid!) was codified in the <a href="http://github.com/alecmce/as3geometry/blob/master/src/as3geometry/geom2D/ui/ParabolaDrawer.as">ParabolaDrawer.as</a> class.</p>
<p><br clear="all" /></p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/parabolas-and-quadratic-bezier-curves/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>as3geometry &#8211; Parabolas</title>
		<link>http://alecmce.com/as3/as3geometry-parabolas</link>
		<comments>http://alecmce.com/as3/as3geometry-parabolas#comments</comments>
		<pubDate>Mon, 09 Aug 2010 15:00:33 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=913</guid>
		<description><![CDATA[The as3geometry library has been neglected of late, but I have managed to push out a couple of important updates this week: the invalidation manager and parabola handling. I will discuss the invalidation manager later in the week since it is quite a technical and complex update. The implementation of parabolas is rather more straightforward. [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://github.com/alecmce/as3geometry">as3geometry</a> library has been neglected of late, but I have managed to push out a couple of important updates this week: the invalidation manager and parabola handling. I will discuss the invalidation manager later in the week since it is quite a technical and complex update. The implementation of parabolas is rather more straightforward.</p>
<p>Parabola defined by a line and vertex</p>
<div style="text-align: center; padding-bottom: 20px; font-size: small;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="640" height="480" align="center">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2010/08/ParabolaFromLineAndVertex1.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2010/08/ParabolaFromLineAndVertex1.swf" width="640" height="480" align="center">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="http://github.com/alecmce/as3geometry/blob/master/src/examples/ParabolaFromSegmentAndVertex.as">view source</a> | click-and-drag the red points to interact</div>
<p>Parabola segment defined by a line segment and vertex:</p>
<div style="text-align: center; padding-bottom: 20px; font-size: small;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="640" height="480" align="center">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2010/08/ParabolaFromSegmentAndVertex1.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2010/08/ParabolaFromSegmentAndVertex1.swf" width="640" height="480" align="center">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="http://github.com/alecmce/as3geometry/blob/master/src/examples/ParabolaFromLineAndVertex.as">view source</a> | click-and-drag the red points to interact</div>
<p>Usefully, a parabola (which, precisely, is &#8220;the locus of points equidistant from a point and a line&#8221;) can be expressed as a quadratic bezier curve. The implementation &#8216;simply&#8217; finds the three control points of a quadratic bezier curve and then uses the Flash Player&#8217;s Graphics.curveTo method to draw.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/as3geometry-parabolas/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gotcha &#8211; transform.matrix and scaleX/Y</title>
		<link>http://alecmce.com/as3/gotcha-transform-scale</link>
		<comments>http://alecmce.com/as3/gotcha-transform-scale#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:00:47 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=720</guid>
		<description><![CDATA[I came across this gotcha for the first time today. Praise-be to ASUnit, without which this could have been extremely difficult to unearth: // given two sprites called &#34;a&#34; and &#34;b&#34;... a.transform.matrix = new Matrix(-.5, 0, 0, -.5, a.x, a.y); b.scaleX = b.scaleY = -.5; trace(a.scaleX, a.scaleY, b.scaleX, b.scaleY); // outputs: 0.5, 0.5, -0.5, -0.5 [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this gotcha for the first time today. Praise-be to <a href="http://asunit.org/">ASUnit</a>, without which this could have been extremely difficult to unearth:</p>
<pre class="brush: as3;">
// given two sprites called &quot;a&quot; and &quot;b&quot;...

a.transform.matrix = new Matrix(-.5, 0, 0, -.5, a.x, a.y);
b.scaleX = b.scaleY = -.5;

trace(a.scaleX, a.scaleY, b.scaleX, b.scaleY); // outputs: 0.5, 0.5, -0.5, -0.5
</pre>
<p>Both clips have been scaled by -0.5, but because the transform was used to produce the scale for a, the scaleX/Y variables do not reflect the object&#8217;s true scale.</p>
<p>Now, just to confuse yourself, add a third sprite to the stage:</p>
<pre class="brush: as3;">
// given another sprite called &quot;c&quot;...

c.transform.matrix = new Matrix(-.5, 0, 0, -.5, c.x, c.y);
c.scaleX = c.scaleY = -.5;
</pre>
<p>Curiouser and curiouser! This needed a more complete experimentation&#8230;</p>
<div style="text-align: center;">

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="550" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2010/02/scaleAndTransform.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2010/02/scaleAndTransform.swf" width="550" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

</div>
<p>The source for this experiment can be found here: <a href='http://alecmce.com/wp-content/uploads/2010/02/scaleAndTransform.zip'>scaleAndTransform</a>. The buttons call the following methods:</p>
<pre class="brush: as3;">
function onGo(event:Event):void
{
	a.transform.matrix = new Matrix(-.5, 0, 0, -.5, a.x, a.y);

	b.scaleX = b.scaleY = -.5;

	c.transform.matrix = new Matrix(-.5, 0, 0, -.5, c.x, c.y);
	c.scaleX = c.scaleY = -.5;
}

function onResetScale(event:Event):void
{
	a.scaleX = a.scaleY = 1;
	b.scaleX = b.scaleY = 1;
	c.scaleX = c.scaleY = 1;
}

function onResetTransform(event:Event):void
{
	a.transform.matrix = new Matrix(1, 0, 0, 1, a.x, a.y);
	b.transform.matrix = new Matrix(1, 0, 0, 1, b.x, b.y);
	c.transform.matrix = new Matrix(1, 0, 0, 1, c.x, c.y);
}
</pre>
<h2>What Is Going On?</h2>
<p>If you apply a transformation matrix then a scale, the magnitude of the scale is applied, but the direction is determined by the product of the transformation and the scalar&#8230; which is to say that:</p>
<pre class="brush: as3;">a.realScaleX = (a.transform.matrix.a * a.scaleX &gt; 0 ? 1 : -1) * a.scaleX;</pre>
<p>If however you apply a scale then a transformation, the scale is defined by the transformation only!</p>
<pre class="brush: as3;">a.realScaleX = a.transform.matrix.a;</pre>
<h2>Bug?</h2>
<p>Does this qualify as a bug? I haven&#8217;t thought about this for long enough. The conditions in which a transformation matrix rotates and skews the MovieClip confuse me; how would I define scaleX and scaleY in that scenario? I need to give this some thought; perhaps you the community can give me some help! I am reluctant to call anything a bug immediately now, after my experience with my <a href="http://alecmce.com/as3/the-problem-with-vector">The Problem With Vector.&lt;T&gt;</a> post, where I was just plain wrong!</p>
<p>A similar bug exists in Adobe JIRA: <a href="http://bugs.adobe.com/jira/browse/SDK-25247"> UIComponent.scaleX, scaleY differ from transform.matrix.a,d</a>. You&#8217;ll need an account to look at this &#8211; it&#8217;s free, and once you&#8217;ve got it you can pester Adobe with your bugs too.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/gotcha-transform-scale/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Circle Segments</title>
		<link>http://alecmce.com/as3/circle-segments</link>
		<comments>http://alecmce.com/as3/circle-segments#comments</comments>
		<pubDate>Mon, 21 Dec 2009 13:01:04 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=643</guid>
		<description><![CDATA[I&#8217;ve added circle segments to the as3geometry library. The two examples below demonstrate the definition of a segment by two vertices constrained to the circle radius and by a line and circle: Circle Segment By Vertices view source &#124; click-and-drag the red points to interact Circle Segment By Line And Circle view source &#124; click-and-drag [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve added circle segments to the <a href="http://github.com/alecmce/as3geometry">as3geometry library</a>. The two examples below demonstrate the definition of a segment by two vertices constrained to the circle radius and by a line and circle:</p>
<h2>Circle Segment By Vertices</h2>
<div style="text-align: center; padding-bottom: 20px; font-size: small;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_3" width="550" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2009/12/CircleSegmentByVertices.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2009/12/CircleSegmentByVertices.swf" width="550" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="http://github.com/alecmce/as3geometry/blob/master/src/examples/CircleSegmentByVertices.as">view source</a> | click-and-drag the red points to interact</div>
<h2>Circle Segment By Line And Circle</h2>
<div style="text-align: center; padding-bottom: 20px; font-size: small;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_4" width="550" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2009/12/CircleSegmentFromCircleAndLine.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2009/12/CircleSegmentFromCircleAndLine.swf" width="550" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="http://github.com/alecmce/as3geometry/blob/master/src/examples/CircleSegmentFromCircleAndLine.as">view source</a> | click-and-drag the red points to interact</div>
<p>The library update also includes some preliminary work on the intersection of two polygons, but I haven&#8217;t yet sorted out the mutability yet, because it&#8217;s pretty complicated, and because I&#8217;m furiously busy this December preparing to move from the UK to the USA! Expect more udpates from late January onwards, once I&#8217;m settled in.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/circle-segments/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>as3geometry &#8211; line &amp; circle intersection</title>
		<link>http://alecmce.com/as3/as3geometry-line-circle-intersection</link>
		<comments>http://alecmce.com/as3/as3geometry-line-circle-intersection#comments</comments>
		<pubDate>Wed, 02 Dec 2009 21:32:24 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=604</guid>
		<description><![CDATA[Addition to my as3geometry library, the intersection between a line and a circle view source &#124; click-and-drag the red points to interact]]></description>
			<content:encoded><![CDATA[<p>Addition to my <a href="http://github.com/alecmce/as3geometry">as3geometry library</a>, the intersection between a line and a circle</p>
<div style="text-align: center; padding-bottom: 20px; font-size: small;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_5" width="550" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2009/12/IntersectCircleAndLine.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2009/12/IntersectCircleAndLine.swf" width="550" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="http://github.com/alecmce/as3geometry/blob/master/src/examples/IntersectCircleAndLine.as">view source</a> | click-and-drag the red points to interact</div>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/as3geometry-line-circle-intersection/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>as3geometry &#8211; line &amp; line intersection</title>
		<link>http://alecmce.com/as3/as3geometry-line-line-intersection</link>
		<comments>http://alecmce.com/as3/as3geometry-line-line-intersection#comments</comments>
		<pubDate>Wed, 02 Dec 2009 21:32:08 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[as3geometry]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=612</guid>
		<description><![CDATA[Addition to my as3geometry library, the Intersection between two lines (though in this case the lines are a ray and a segment!) view source &#124; click-and-drag the red points to interact]]></description>
			<content:encoded><![CDATA[<p>Addition to my <a href="http://github.com/alecmce/as3geometry">as3geometry library</a>, the Intersection between two lines (though in this case the lines are a ray and a segment!)</p>
<div style="text-align: center; padding-bottom: 20px; font-size: small;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_6" width="550" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2009/12/IntersectLineAndLine.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2009/12/IntersectLineAndLine.swf" width="550" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="http://github.com/alecmce/as3geometry/blob/master/src/examples/IntersectLineAndLine.as">view source</a> | click-and-drag the red points to interact</div>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/as3geometry-line-line-intersection/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>as3geometry Update</title>
		<link>http://alecmce.com/as3/as3geometry-update</link>
		<comments>http://alecmce.com/as3/as3geometry-update#comments</comments>
		<pubDate>Wed, 25 Nov 2009 23:03:22 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[as3geometry]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=539</guid>
		<description><![CDATA[I&#8217;ve been working on a GitHub geometry library recently. view source &#124; click-and-drag the red points to interact I&#8217;ve created various of these over the years, AS1, AS2, AS3, and now AS3+as3signals. It is gratifying to finally have the means to define events in interfaces! The work uses the alpha of ASUnit version 4 (Rob [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a <a href="http://github.com/alecmce/as3geometry">GitHub geometry library</a> recently.</p>
<div style="text-align: center; padding-bottom: 20px; font-size: small;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_7" width="550" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2009/11/ThreePoints.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2009/11/ThreePoints.swf" width="550" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="http://github.com/alecmce/as3geometry/blob/master/src/examples/ThreePoints.as">view source</a> | click-and-drag the red points to interact</div>
<p>I&#8217;ve created various of these over the years, AS1, AS2, AS3, and now AS3+<a href="http://github.com/robertpenner/as3-signals">as3signals</a>. It is gratifying to finally have the means to define events in interfaces!</p>
<p>The work uses the alpha of ASUnit version 4 (Rob Penner&#8217;s <a href="http://github.com/robertpenner/asunit/tree/freerunner">&#8216;Free Runner&#8217; implementation</a>, though it is not purely <em>Test-Driven Development</em> because in some cases I am refactoring old hitherto-private code. However, the classes in the test repository might serve as a useful example of the upcoming ASUnit library.</p>
<p>The work aims for elegance of structure rather than speed, and I will be concentrating on the Euclidean 2D for the time-being, though may look at extending it into 3D or non-Euclidean plane structures if I ever have the time.</p>
<p style="text-align: center"><a href="http://github.com/alecmce/as3geometry">http://github.com/alecmce/as3geometry</a></p>
<h2>Next Steps</h2>
<ul>
<li>Circle-Line intersections</li>
<li>Polygon-Polygon intersections (Vertices)</li>
<li>Polygon-Polygon intersections (Polygons)</li>
<li>Circle-Circle intersection (Vertices)</li>
<li>Circle-Line intersection</li>
<li>Circle Sectors</li>
<li>Circle Rays</li>
<li>Circle-Circle intersection (Lens)</li>
<li>Circle-Circle intersection</li>
<li>Bezier Curves</li>
<li>Parabola</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/as3geometry-update/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Vector &#8211; Annoying Naming Conventions</title>
		<link>http://alecmce.com/as3/vector-annoying-naming-conventions</link>
		<comments>http://alecmce.com/as3/vector-annoying-naming-conventions#comments</comments>
		<pubDate>Mon, 31 Aug 2009 14:39:22 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[naming conventions]]></category>
		<category><![CDATA[voronoi]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=306</guid>
		<description><![CDATA[When Adobe released the Flash Player 10 last year, it facilitated a new class, a strongly-typed array: Vector.&#60;T&#62;. I suppose we should all be grateful; now we can finally type arrays, leading to more robust code. I don&#8217;t feel very grateful, though. Adobe has given me a headache. In Geometry the word &#8220;vector&#8221; has a [...]]]></description>
			<content:encoded><![CDATA[<p>When Adobe released the Flash Player 10 last year, it facilitated a new class, a strongly-typed array: <a href="http://livedocs.adobe.com/flex/gumbo/langref/Vector.html"><code>Vector.&lt;T&gt;</code></a>. I suppose we should all be grateful; now we can finally type arrays, leading to more robust code. I don&#8217;t feel very grateful, though. Adobe has given me a headache.</p>
<p>In Geometry the word &#8220;vector&#8221; has a clear meaning: a vector describes a translation in space. To differentiate from other uses of the word, Wikipedia offer the terms <a href="http://en.wikipedia.org/wiki/Euclidean_vector">Euclidean, Spatial or Geometric Vector</a>. We recognise this use of the word because every single Flash coder understands the distinction between vector graphics and raster (or bitmap) graphics.</p>
<p>I have been working on a Geometric library recently (<a href="http://code.google.com/p/as3voronoi/">my as3voronoi library</a>), and have found the need to create an interface to encapsulate a translation in Cartesian space. What will I call it? It&#8217;s a vector, but &#8220;Vector&#8221; is going to cause a lot of headaches, because Adobe&#8217;s new Vector class is in the default namespace.</p>
<p>Which leads me to an utterly futile question: why on earth would they call their strongly-typed array class &#8220;Vector&#8221;? Why not facilitate the strong-typing of Arrays, since Array is the existing term? Untyped Arrays could be considered functionally equivalent to <code>Array.&lt;*&gt;</code> or <code>Array.&lt;Object&gt;</code>. I realise that Adobe cannot change this decision now it has been made, but why did they do it in the first place?</p>
<p>The only answer that I can see is that the vector class is in the C++ standard template library as a one-dimensional array. Was the decision made on the basis that if it&#8217;s good enough for C++, then it&#8217;s good enough for Flash? I hope not, because the Array class is not like the C++ array, and I don&#8217;t see &#8220;bitset&#8221;, &#8220;deque&#8221;, &#8220;list&#8221;, &#8220;map&#8221;, &#8220;queue&#8221;, &#8220;set&#8221;, or &#8220;stack&#8221; anywhere in the Flash library. Why adopt the C++ convention in just this context?</p>
<p>Flash has a different context to C++. Flash is a word used to describe a player that uses ActionScript and a <em>vector drawing tool</em> rolled into one. Surely the word &#8220;vector&#8221; has particular significance for the users of Adobe technology?</p>
<p>So what do I call my vector interface? &#8220;Vector2D&#8221;? &#8220;EuclideanVector&#8221;? I haven&#8217;t called my Polygon interface &#8220;Polygon2D&#8221; or &#8220;EuclideanPolygon&#8221;, nor my line interface &#8220;Line2D&#8221; or &#8220;EuclideanLine&#8221;. I don&#8217;t need to. The terse name does the job perfectly well. If I only target Flash Player 9 I don&#8217;t need to call my vector interface anything other than &#8220;Vector&#8221;.</p>
<p>The headache is unresolved; I am stuck with wanting an array to be an <code>Array</code> and a vector to be a <code>Vector</code>, but will have to accept that an array will be a <code>Vector</code> and a vector &#8230; something else.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/vector-annoying-naming-conventions/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Permutations in AS3</title>
		<link>http://alecmce.com/as3/permutations-in-as3</link>
		<comments>http://alecmce.com/as3/permutations-in-as3#comments</comments>
		<pubDate>Mon, 17 Aug 2009 11:05:51 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=271</guid>
		<description><![CDATA[I needed a method to find permutations of elements within an Array, for a little something that I&#8217;m working on. I couldn&#8217;t find one &#8216;off the shelf&#8217;, and while it&#8217;s easy enough to do yourself, it&#8217;s easier to use someone else&#8217;s. If you&#8217;re not very familiar with the concept of permutations, please be sure to [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a method to find permutations of elements within an Array, for a little something that I&#8217;m working on. I couldn&#8217;t find one &#8216;off the shelf&#8217;, and while it&#8217;s easy enough to do yourself, it&#8217;s easier to use someone else&#8217;s. If you&#8217;re not very familiar with the concept of permutations, please be sure to read the method header if you intend to use this method.</p>
<pre class="brush: as3;">
/**
 * Finds the permutations of an array by recursively permutating sub-arrays
 *
 * WARNING! For n elements there are n! permutations - ie. if you have
 * 6 elements in your array you will find returned an array containing
 * 6*5*4*3*2 = 720 arrays of your elements. 10 elements returns an
 * array containing more than 3.5 million arrays, which is not
 * recommended.
 *
 * @param elements The elements to be permutated
 * @return An array of all of the permutations of the elements in the array.
 */
public function permutate(elements:Array):Array
{
	if (elements.length == 1)
		return [elements[0]];

	var permutations:Array = [];
	var length:int = elements.length;

	var i:int, j:int;
	var tmp:Array;
	var sub:Array;

	i = length;
	while (i--)
	{
		tmp = elements.slice(0, i).concat(elements.slice(i + 1, length));
		sub = permutate(tmp);

		j = sub.length;
		while (j--)
		{
			tmp = [elements[i]].concat(sub[j]);
			permutations.push(tmp);
		}
	}

	return permutations;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/permutations-in-as3/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
