title: check collision of lines and a circle in canvas android
body: <p>I am trying to check collisions between lines and a circle, if the circle hits the line, it would work change a boolean to true and once its not touched, it would change it back to false. I am using canvas and surface view. </p>
  
  <p>Here is my code for checking collision which didn't work and ended up in error: </p>
  
  <pre><code>@Override
  public void run() {
  while(runnable)
      {
          if(!holder.getSurface().isValid()){
              continue;
          }
          Canvas mCanvas = holder.lockCanvas();
          update(mCanvas);
          values = new Values(mCanvas);
          createPaints();
          drawBackground(mCanvas);
          drawObjects(mCanvas);
          holder.unlockCanvasAndPost(mCanvas);
  
  
      }
  }
  </code></pre>
  
  <p>Now the collision is processed in the update:</p>
  
  <pre><code>private void update(Canvas c) {
      ball.update(c, checkLinesCollision(values.level1, ball.getX(), ball.getY()));
    //takes a canvas, and a boolean
  }
  
  boolean checkLinesCollision(float[] f,float x,float y){
      int c = 0;
      for(int i = 0; i &lt; f.length; i+=4){
          float x1 = f[i];
          float y1 = f[i+1];
          float x2 = f[i+2];
          float y2 = f[i+3];
  
          if (x&gt; x1 &amp;&amp; x&lt;x2 &amp;&amp; y&gt;y1 &amp;&amp; y&gt;y2){
  
              c++;
  
          }
      }
          if(c&gt;0){return true;}else{return false;}
  
  }
  </code></pre>
  
  <p>the values for the level</p>
  
  <pre><code> float yLow = c.getHeight()-c.getHeight()/4;
  
      level1 = new float[]{0,yLow,c.getWidth(),yLow,
                        40,c.getHeight()/2,300,c.getHeight()/2};
  </code></pre>
  
  <p>ball update function:</p>
  
  <pre><code>public void update(Canvas c, boolean b) {
  
      if(b){
  
          dy=-dy;
          b = false;
      }
      y -= dy;
      dy--; 
  }
  </code></pre>
  
  <p>Now according to the logcat the problem is in the main update function.<br>
  I think that I am using the wrong function, what can I do to fix it?</p>
  
  <p>Thanks!</p>