简体   繁体   English

如何在圆弧的末端画一条线?

[英]How to draw a line at the end of an arc?

How do I draw a line at the end of an arc like so? 我如何像这样在弧的末端画一条线?

示例图片

Here is the code I'm currently using to draw the arc 这是我当前用来绘制弧线的代码

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
        canvasWidth = MeasureSpec.getSize(widthMeasureSpec);
        canvasHeight = MeasureSpec.getSize(heightMeasureSpec);
        padding = strokeWidth * 0.9f;
        arcAngle = 360 * 0.8f;
        rectF.set(padding, padding, canvasWidth - padding, canvasHeight - padding);
        arcRadius = (canvasWidth - padding) / 2f;
        arcBottomHeight = arcRadius * (float) (1 - Math.cos(angle / 180 * Math.PI));
    }
protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        float startAngle = 270 - arcAngle / 2f;
        float finishedSweepAngle = progress / (float) getMax() * arcAngle;
        float finishedStartAngle = startAngle;

        canvas.drawArc(rectF, startAngle, arcAngle, false, unfinishedPaint);
        canvas.drawArc(rectF, finishedStartAngle, finishedSweepAngle, false, finishedPaint);
}

This draws 2 arcs on top of each other, with the colored arc (finishedPaint) representing the progress. 这将在彼此的顶部绘制2个圆弧,彩色圆弧(finishedPaint)表示进度。

I want to use canvas.drawLine() to draw the line at the end of the arc, but am unsure how to get the coordinates to specify the start and stop coordinates of the line. 我想使用canvas.drawLine()在圆弧的末端绘制线条,但是不确定如何获取坐标以指定线条的开始和结束坐标。

Use trig. 使用触发。 You know the radius of the arc and the angle it ends at. 您知道圆弧的半径及其结束的角度。 The x is radius*sin(endangle)+xcenter , the y is radius*cos(endangle)+ycenter . x为radius*sin(endangle)+xcenter ,y为radius*cos(endangle)+ycenter Then draw the line at that same angle where that lies. 然后以相同的角度画线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM