title: Android: Canvas scaling in different coordinate system
body: <p>I'm kinda desperate already =)...</p>
  
  <p>I'am drawing points and lines onto a canvas in Android. The points I'm displaying should be displayed in a mathematical system. So I did canvas.getHeight() - point.y to display the points in the right way.</p>
  
  <p>But if I would like to zoom into the drawn object the y coordinate gets scaled out of my view.
  That's because x = 10 and y = 700. If I scale it with a scale factor of 10, the y make the object disappear.
  I hope you get what I'm talking about...</p>
  
  <p>How do I display my coordinates in the right (mathematical) way without moving the y coordinate far away??</p>
  
  <p>Here is what I do:</p>
  
  <pre><code>        canvas.drawPoint(startPoints[i][0], height-startPoints[i][1], pointColor);
          canvas.drawPoint(endPoints[i][0], height-endPoints[i][1], pointColor);
  </code></pre>
  
  <p>Then my point (x=10, y=10) is going to be displayed as x=10 , y = 714.</p>
  
  <p>Here's my full routine</p>
  
  <pre><code>@Override
  public void onDraw(Canvas canvas) {
      super.onDraw(canvas);
  
      final float[][] startPoints;
  
      final float[][] endPoints;
  
      int count = 0;
      height = canvas.getHeight();
  
      canvas.save();
      canvas.scale(scaleFactor, scaleFactor);
      canvas.translate(translateX / scaleFactor, translateY / scaleFactor);
  
      Paint lineColor = new Paint();
      lineColor.setColor(Color.BLACK);
  
      Paint pointColor = new Paint();
      pointColor.setColor(Color.RED);
      pointColor.setStrokeWidth(5f);
  
      startPoints = data.getStartPoints();
      endPoints = data.getEndPoints();
      count = data.getSize();
  
      for (int i = 0; i &lt; count; i++) {
          canvas.drawLine(startPoints[i][0], height-startPoints[i][1],
                  endPoints[i][0], height-endPoints[i][1], lineColor);
          canvas.drawPoint(startPoints[i][0], height-startPoints[i][1], pointColor);
          canvas.drawPoint(endPoints[i][0], height-endPoints[i][1], pointColor);
      }
  
      canvas.restore();
  }
  
  private class ScaleListener extends
          ScaleGestureDetector.SimpleOnScaleGestureListener {
      @Override
      public boolean onScale(ScaleGestureDetector detector) {
          scaleFactor *= detector.getScaleFactor();
          scaleFactor = Math.max(MIN_ZOOM, Math.min(scaleFactor, MAX_ZOOM));
          return true;
      }
  }
  </code></pre>