Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding velocity and implementing Boids algorithm?
    text
    copied!<p>So I'm working on porting Boids to Brightscript, based on the <a href="http://www.kfish.org/boids/pseudocode.html" rel="nofollow">pseudocode here</a>.</p> <p>I'm trying to understand the data structures involved, for example is Velocity a single value, or is it a 3D value? (i.e. <code>velocity={x,y,z}</code>)</p> <p>It seems as if the pseudocode seems to mix this up where sometimes it has an equation that incudes both vectors and single-value items:</p> <pre><code>v1 = rule1(b) v2 = rule2(b) v3 = rule3(b) b.velocity = b.velocity + v1 + v2 + v3 </code></pre> <p>If Velocity is a tripartite value then this would make sense, but I'm not sure. </p> <p>So, my first question: based on the pseudocode above, is this the correct data structure for a single boid?</p> <pre><code>boid={position:{px:0,py:0,pz:0},velocity:{x:0,y:0,z:0},vector:{x:0,y:0,z:0},pc:{x:0,y:0,z:0},pv:{x:0,y:0,z:0}) </code></pre> <p>where <code>pc</code>=perceived center, and <code>pv</code>= perceived velocity.</p> <p>I've implemented a <code>vector_add</code>, <code>vector_sub</code>, <code>vector_div</code>, and vector boolean functions.</p> <p>The reason I'm starting from this pseudocode is I've not been able to find anything else that is as readable, but it still leaves me with lots of questions as the data structures are not explicitly defined for each variable.</p> <p><strong>(edit)</strong> Here's a good example of what I'm talking about:</p> <pre><code>IF |b.position - bJ.position| &lt; 100 THEN </code></pre> <p>if <code>b.position - b[j].position</code> are both 3D coordinates, how can they be considered "less than 100" unless they are <code>&lt; {100,100,100}</code>?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload