Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript. Tricky: Are all array values consistent? (ie: does a = [a,a,a,a]) for any size array
    primarykey
    data
    text
    <p>This is rather conceptual, and I'm hoping someone can help. I have a script, that when you insert coordinates (x,y, from 0 -> 800) in to it, it'll return lists of pre-plotted coordinates that are within 3 separate ranges.</p> <p>ie: I enter 200,200. I receive a list for each of the following: Plots that are within a radius of 25, a radius of 60, a radius of 150.</p> <p>The code if you're curious / for context: </p> <pre><code> display(coords[n][1] + ", " + coords[n][2]); if(n==0){ for(var i=0; i &lt; data.length; i++) { var xs = 0; var xy = 0; xs = xPlot - data[i][0]; ys = yPlot - data[i][1]; xs = xs * xs; ys = ys * ys; distance = Math.sqrt(xs + ys); if (distance &lt;= 25){ display2(data[i][0] + ", " + data[i][1] + " - " + alliance); } else if(distance &lt;= 60){ display3(data[i][0] + ", " + data[i][1] + " - " + alliance); } else if(distance &lt;= 150){ display4(data[i][0] + ", " + data[i][1] + " - " + alliance); } } </code></pre> <p>Easy enough.</p> <p>Now, when I input another set of coordinates another multidimensional array is created, I want to check for intersecting points within the two (well, 6) circles.</p> <p>I thought of using an array for my checking. If 2 coords are entered, and a point is found within both inner (green) circles, a = [g,g]. If a point is found within an inner of one, but a mid (blue) of the other, set a = [g,b] You get the idea. Red being the outer circle.</p> <p>When 3 coords are entered things get trickier. Let's say a point is within two inners, and one mid. Then a = [g,g,b]. The purpose of the 3 lists, is to organize the returned values in groups of best to worst. So in an example with 4 inputs, the lists are to be organised in the following way:</p> <p>List 1 / List 2 / List 3 <br/> gggg / gggb / bbbr <br/> ------- / ggbb / bbrr <br/> ------- / gbbb / brrr <br/> ------- / bbbb / rrrr</p> <p>How would I build check my array in a scalable way so if I had 5 inputs, I'd be able to place my results in the appropriate columns? </p> <p>I've started with this sofar:</p> <pre><code>else if(n&gt;0){ for(var i=0; i &lt; data.length; i++) { for(var j=0; j &lt; coords.length; j++) { var xs = 0; var ys = 0; xs = coords[j][1] - data[i][0]; ys = coords[j][2] - data[i][1]; xs = xs * xs; ys = ys * ys; distance = Math.sqrt(xs + ys); if (distance &lt;= 25){ a[j] = [,[g]]; } else if (distance &lt;= 60){ a[j] = [,[b]]; } else if (distance &lt;= 150){ a[j] = [,[r]]; } } if($.inArray('g', a) &amp;&amp; (!($.inArray('b', a)))){ display2(data[i][0] + ", " + data[i][1] + " - " + alliance); </code></pre> <p>}</p> <p>Would this last line execute if a contained g, but NOT b?? (jquery) Am I on the right track?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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