如何使用用户触摸事件创建可调整大小的圆圈?

nic*_*guy 2 android shape android-drawable

我正在尝试创建一个将在onTouchEvent上调整大小的圆形

我关注了可调整大小的矩形帖子,但我认为由于缺乏数学知识,我不知道如何创建可调整大小的圆圈。

我试过改变

canvas.drawRect(
    left + colorballs.get(0).getWidthOfBall() / 2,
    top + colorballs.get(0).getWidthOfBall() / 2, 
    right + colorballs.get(2).getWidthOfBall() / 2, 
    bottom + colorballs.get(2).getWidthOfBall() / 2, paint);
Run Code Online (Sandbox Code Playgroud)

canvas.drawCircle() ; 它创建了圆圈,但不是我想要的。

你能告诉我是否已经实现了这样的东西,或者我应该遵循哪些点来将这个矩形示例转换为可调整大小的圆。

Ale*_*you 5

因此,圆心将是:

float cx = (left + right) / 2f; 
float cy = (top + bottom) / 2f; 
Run Code Online (Sandbox Code Playgroud)

——很明显。可以使用Math.hypot()以下方法计算半径:

float radius = Math.hypot(top - bottom, right - left) / 2f;
Run Code Online (Sandbox Code Playgroud)

因此,我们有圆心和半径来画圆:

drawCircle(cx, cy, radius, paint);
Run Code Online (Sandbox Code Playgroud)