2014-06-16 42 views
0

考慮兩個圓((0,0)爲中心,110和210分別爲半徑...如何使對象在圓形路徑中移動?

即我有CENTER爲(0,0)和CIRCLE 1半徑爲110和CIRCLE 2半徑爲210。 現在我需要在這兩個圈子之間移動一個物體tball

這是我的代碼 -

public void run() { 

     while (isitok == true) { 
      // perform drawing 
      if (!holder.getSurface().isValid()) { 
       continue; 
      } 
      Canvas canvas = holder.lockCanvas(); 
      canvas.drawARGB(255, 150, 150, 10); 

      // System.out.println("Canvas matrix -" + canvas.getm)); 
      Paint p = new Paint(); 

      // canvas.drawBitmap(tball, (x - tball.getWidth())/2, 
      // (y - tball.getHeight())/2, p); 

      p.setStyle(Paint.Style.STROKE); 
      p.setColor(Color.WHITE); 
      p.setColor(Color.parseColor("#0101DF")); 

      canvas.drawCircle(canvas.getWidth()/2, 
        canvas.getHeight()/2, 60, p); 
      canvas.drawCircle(canvas.getWidth()/2, 
        canvas.getHeight()/2, 110, p); 

      float x = (canvas.getWidth()/2) - (tball.getWidth()/2); 
      float y = (canvas.getHeight()/2) - 110 + (110 - 60)/2 
        - (tball.getHeight()/2); 

      canvas.drawBitmap(tball, x, y, p); 

      float movingpts[]; 

      holder.unlockCanvasAndPost(canvas); 
     } 
    } 
+0

我想這個'public void run()':) –

回答

0

圈的座標

X = MX + R * cos(angle) 
Y = MY + R * sin(angle) 

其中(MX,MY)是圓的中心或中點,R是半徑。對於屏幕座標,有時更好使用

Y = MY - R * sin(angle) 

以獲得與數學慣例有關的圓角方向的角度一致。