<?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>Vershun's Brain Dump &#187; Visualizing Swarms</title>
	<atom:link href="http://www.vershun.com/category/computers/visualizing-swarms/feed" rel="self" type="application/rss+xml" />
	<link>http://www.vershun.com</link>
	<description>Worthless Mind Excretion</description>
	<lastBuildDate>Fri, 02 Sep 2011 02:25:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Boid Algorithm in 10 Dimensions</title>
		<link>http://www.vershun.com/computers/visualizing-swarms/boid-algorithm-in-10-dimensions.html</link>
		<comments>http://www.vershun.com/computers/visualizing-swarms/boid-algorithm-in-10-dimensions.html#comments</comments>
		<pubDate>Thu, 01 Sep 2011 06:36:08 +0000</pubDate>
		<dc:creator>Vershun</dc:creator>
				<category><![CDATA[Visualizing Swarms]]></category>
<category>boids</category><category>emergent behavior</category><category>flex</category>
		<guid isPermaLink="false">http://www.vershun.com/?p=338</guid>
		<description><![CDATA[Click here to the see the visualization &#160; Basic idea and behavior rules I&#8217;ve been interested in emergent behavior since early college.  One of the first algorithms I learned for emergent behavior was the Boid flocking algorithm, created by Craig Reynolds in 1986.   I&#8217;ve always wanted to model this, but I never had any experience <a href='http://www.vershun.com/computers/visualizing-swarms/boid-algorithm-in-10-dimensions.html'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h2 style="padding-left: 30px; text-align: center;"><strong><a title="Boids in ten dimensions" href="http://www.vershun.com/projects/boids/Boids.html"><br />
Click here</a> to the see the visualization</strong></h2>
<p>&nbsp;</p>
<p><strong>Basic idea and behavior rules</strong></p>
<p>I&#8217;ve been interested in emergent behavior since early college.  One of the first algorithms I learned for emergent behavior was the Boid flocking algorithm, created by Craig Reynolds in 1986.   I&#8217;ve always wanted to model this, but I never had any experience in 3d programming until very recently.</p>
<p>The idea behind the boid algorithm (and emergent behavior in general) is complex behavior arises from fairly simple interaction rules.  For this implementation, I applied the following behavior rules to each of the boids (dots):</p>
<ol>
<li>Move toward the center of the mass of the swarm</li>
<li>Avoid other boids</li>
<li>Try to match velocities with other boids</li>
<li>Stay within bounds (I just used a cube for this)</li>
</ol>
<p>Descriptions of these rules and pseudocode to implement it can be found here: <a href="http://www.vergenet.net/~conrad/boids/pseudocode.html">http://www.vergenet.net/~conrad/boids/pseudocode.html</a></p>
<p><strong>Adding more dimensions</strong></p>
<p>At my 9-5 I&#8217;ve been thinking a lot about how to represent  multidimensional data.  I realized the boid behaviors could be easily extended into multiple dimensions if the other dimensions provided good visual cues.  I decided to go with three different 3 dimensional spaces, with each axis a continuous numerical value that could be translated into a visual construct.  The 3D graphs always map the positional locations of the boids, but the 10D graph only pulls the positional elements from the XYZ space.  The following images show the max/min of all the axes.</p>
<p>First 3d space:  positional X, Y, and Z</p>
<div id="attachment_339" class="wp-caption alignnone" style="width: 232px"><img class="size-full wp-image-339 " title="xyzspace" src="http://www.vershun.com/wp-content/uploads/2011/08/xyzspace.jpg" alt="" width="222" height="176" /><p class="wp-caption-text">Positional X, Y, and Z</p></div>
<p>This works exactly as you would imagine.  The coordinates here are simply the 3d positions you&#8217;re used to dealing with.</p>
<p>Second 3d space: Red, Green, and Blue</p>
<div id="attachment_340" class="wp-caption alignnone" style="width: 232px"><img class="size-full wp-image-340 " title="Red, Green, and Blue space" src="http://www.vershun.com/wp-content/uploads/2011/08/rgbspace.jpg" alt="" width="222" height="176" /><p class="wp-caption-text">RGB Space</p></div>
<p>For RGB space, X represents the amount of red in the color (0-255), Y represents the amount of green in the color (0-255), and Z represents the amount of blue in the color (0-255).</p>
<p>Third 3d space: alpha, size, and number of shape vertices</p>
<div id="attachment_341" class="wp-caption alignnone" style="width: 232px"><img class="size-full wp-image-341" title="Alpha Size Vertices" src="http://www.vershun.com/wp-content/uploads/2011/08/asvspace.jpg" alt="" width="222" height="176" /><p class="wp-caption-text">Alpha, Size, and Vertices Space</p></div>
<p>For this space, I used alpha (transparency) for the x value.  You can see the boid on the left is completely black while the one on the right (the minimum negative x value) is faded out.  The y axis scales the size of the boid.  The z axis determines the number of vertices the node shape has (from 3 &#8211; 6).  You can see the minimum z value has a vertex count of 3 (triangle), while the max z almost looks circular (hexagon).</p>
<p>For this example, I&#8217;m running 3 separate boid algorithms on each of the spaces and then combining the output into one 9 dimensional space.  The tenth dimension is time.</p>
<div>
<dl id="attachment_342" class="wp-caption alignnone" style="width: 224px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-342" title="Nine dimensional space" src="http://www.vershun.com/wp-content/uploads/2011/09/allspaces.jpg" alt="" width="214" height="158" /></dt>
<dd class="wp-caption-dd">Combined dimensions</dd>
</dl>
</div>
<p>&nbsp;</p>
<p>To see it all in action, <a title="Boids in ten dimensions" href="http://www.vershun.com/projects/boids/Boids.html">click here</a>.</p>
<p>View sourcehas been enabled.</p>
<div>To compile this yourself, you&#8217;ll need <a href="http://www.away3d.com/download/away3d_3.6.0">Away3D 3.6</a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.vershun.com/computers/visualizing-swarms/boid-algorithm-in-10-dimensions.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Barebones application for visualizing swarms (2D)</title>
		<link>http://www.vershun.com/computers/visualizing-swarms/barebones-application-for-visualizing-swarms-2d.html</link>
		<comments>http://www.vershun.com/computers/visualizing-swarms/barebones-application-for-visualizing-swarms-2d.html#comments</comments>
		<pubDate>Sun, 17 May 2009 04:36:41 +0000</pubDate>
		<dc:creator>Vershun</dc:creator>
				<category><![CDATA[Visualizing Swarms]]></category>

		<guid isPermaLink="false">http://www.vershun.com/?p=254</guid>
		<description><![CDATA[So I&#8217;ve decided to play around a bit for my own giggles and make some swarm stuff.  Emergent behavior is the bee&#8217;s knees and I think it will be a lot of fun to code up some visual representations of it. This is the very first step in the processes.  It&#8217;s not quite a &#8220;framework,&#8221; <a href='http://www.vershun.com/computers/visualizing-swarms/barebones-application-for-visualizing-swarms-2d.html'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve decided to play around a bit for my own giggles and make some swarm stuff.  Emergent behavior is the bee&#8217;s knees and I think it will be a lot of fun to code up some visual representations of it.</p>
<p>This is the very first step in the processes.  It&#8217;s not quite a &#8220;framework,&#8221; but more of a template.  Click to activate the ants, slide to change the speed.</p>
<p><object width="505" height="375" data="http://www.vershun.com/projects/ants_template/ants.swf" type="application/x-shockwave-flash"><param name="quality" value="high" /><param name="bgcolor" value="#869ca7" /><param name="allowScriptAccess" value="sameDomain" /><param name="src" value="http://www.vershun.com/projects/ants_template/srcview" /></object></p>
<p>You can right click and view source.  The code is very rudimentary and the only slightly interesting part is how the ants decide to move.</p>
<blockquote>
<pre>var stuckCounter:int = 90;

do
{
	var randomAngle:uint = rotation + ((Math.random() * stuckCounter) - (stuckCounter / 2));
	var randomDistance:uint = Math.random() * 70 + 10;

	var randX:int = randomDistance * Math.cos(randomAngle * (Ant.TO_RADIANS));
	var randY:int = randomDistance * Math.sin(randomAngle * (Ant.TO_RADIANS));
	stuckCounter++;
} while (environment.isObstructionInPath(x, y, x + randX, y + randY));</pre>
</blockquote>
<p>The code is pretty self explanatory (hopefully), but basically the ant is choosing a random direction within its scope (45 degrees both left and right of it&#8217;s current rotation), generates a random distance to travel, and checks with the environment to make sure there&#8217;s no obstructions within its projected trajectory.  If there&#8217;s an obstruction, add 1 degree to the randomizer and repeat.  Using randomly chosen angles along with a slow increase in the randomized range helps give a more realistic look of obstacle avoidance than other methods (say, flipping rotation).</p>
<p>I&#8217;ll be adding more to this section when I get some motivated down time to play, but this week it&#8217;s all about the R&#038;R.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vershun.com/computers/visualizing-swarms/barebones-application-for-visualizing-swarms-2d.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

