Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Velocity</h2> <p>If you look at <a href="http://www.kfish.org/boids/pseudocode.html#ref1" rel="nofollow">their pseudocode</a> for vector addition and subtraction, they are explicitly performing these operations on three-dimensional vectors, e.g.</p> <pre><code>PROCEDURE Vector_Add(Vector v1, Vector v2) Vector v v.x = v1.x + v2.x v.y = v1.y + v2.y v.z = v1.z + v2.z RETURN v END PROCEDURE </code></pre> <p>In the <em>Auxiliary Functions</em> section, it also says:</p> <blockquote> <p>... all the additions and subtractions in the above pseudocode are vector operations</p> </blockquote> <p>So we can assume <code>b.velocity = b.velocity + v1 + v2 + v3 + ...</code> is vector addition for 3D vectors.</p> <h2>Vector Magnitude</h2> <p>The subtraction of the two vectors is called the difference between vectors, and produces a new vector. In your case, let <code>diffB = b.position - bJ.position</code>.</p> <p>Now <code>|b.position - bJ.position|</code> is equivalent to <code>|diffB|</code>, and is taking the magnitude of the difference vector <code>diffB</code>, not the absolute value of a <em>"single value"</em> (called a scalar.) Magnitude is also called vector length, or norm.</p> <p>What may be confusing is that the magnitude of a vector is denoted by the same notation as absolute value. So <code>diffB</code> is a difference vector, and <code>|diffB|</code> is the magnitude of that vector. Magnitude is defined for a vector <code>v</code> in Euclidean space by <code>|v| = sqrt(x1^2 + ... + xn^2)</code>.</p> <p>So, for your 3D vector <code>diffB</code>:</p> <pre><code>|diffB| = sqrt(x1^2 + x2^2 + x3^2) = sqrt(x^2 + y^2 + z^2) </code></pre> <p>Since the result of square root is a scalar, it can clearly satisfy <code>&lt; 100</code>. </p> <hr> <p>So yes, I believe velocity is a 3D vector <code>velocity = {x1, x2, x3}</code>, and while I haven't thoroughly reviewed the boid pseudocode, your data structure appears correct.</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