嗨,我在弧的两端(开始和结束)上画点有困难

虽然我可以在 Canvas 上画圆弧。这是我绘制圆弧的示例代码。

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float width = (float) getWidth();
    float height = (float) getHeight();
    float radius;

    if (width > height) {
        radius = height / 4;
    } else {
        radius = width / 4;
    }

    float center_x, center_y;
    final RectF oval = new RectF();

    center_x = width / 2;
    center_y = height / 2;

    oval.set(center_x - radius,
            center_y - radius,
            center_x + radius,
            center_y + radius);

    float percent = 25;
    float arcRadius = 360;
    float angle = arcRadius * (percent/100);

    canvas.drawArc(oval, 270, 360, false, trackpaint);
    canvas.drawArc(oval, 270, angle, false, arcPaint);
}

唯一缺少的是在圆弧的起点和终点放置圆圈。我试过这个链接,但它不起作用 Calculate Arc Center Point, Knowing It's Start and End Degrees 。任何帮助都感激不尽。谢谢

最佳答案

起点坐标为:

double startX = Math.cos(Math.toRadians(270)) * radius + center_x;

double startY = Math.sin(Math.toRadians(270)) * radius + center_y;

终点坐标为:
double endX = Math.cos(Math.toRadians(270 + angle)) * radius + center_x;

double endY = Math.sin(Math.toRadians(270 + angle)) * radius + center_y;

然后您可以使用起点和终点绘制圆:
canvas.drawCircle(startX, startY, 10, paint);

canvas.drawCircle(endX, endY, 10, paint);

10-08 18:37