考虑两个圆圈,其中(0,0)为中心,110和210分别为半径...
即我将CENTER设为(0,0),将CIRCLE 1半径设为110,将CIRCLE 2半径设为210。 现在我需要在这两个圈子之间移动一个对象。
这是我的代码 -
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 :(得分:0)
圆坐标是
X = MX + R * cos( angle )
Y = MY + R * sin( angle )
其中(MX,MY)是圆的中心或中点,R是半径。对于屏幕坐标,有时最好使用
Y = MY - R * sin( angle )
使角度与圆形方向的数学约定一致。