【问题标题】:Creating a concave path with arcTo in Android在 Android 中使用 arcTo 创建凹路径
【发布时间】:2015-05-20 15:37:36
【问题描述】:

我想画这样一条路径并填充它:

如果原点是带有 (x, y) 坐标的红点。我应该在下面用三个点写什么来绘制这条路径。我已经尝试了很多,但无法弄清楚 arcTo 是如何工作的。

    path.moveTo(x, y);
    path.arcTo(...);
    path.arcTo(...);
    canvas.drawPath(path, paint);

【问题讨论】:

    标签: android path android-canvas


    【解决方案1】:

    ArcTo 绘制矩形内切椭圆的弧,从起始角到角+扫角。其余的都是纯几何。

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.rgb(255, 139, 40));
    
        float x = 500, y = 500, r = 500, angle = 50;
    
        Path path = new Path();
    
        path.arcTo(new RectF(x, y-r, x+2*r, y+r),180,angle);
        path.lineTo((float) (x - r * (1 - Math.cos(Math.toRadians(angle)))), (float) (y - r * Math.sin(Math.toRadians(angle))));
        path.arcTo(new RectF(x - 2 * r, y - r, x, y + r), -angle, angle);
        path.close();
    
    
        canvas.drawPath(path,paint);
    

    【讨论】:

    • 如果起始坐标与当前路径坐标不匹配,arcTo 会自动执行 lineTo,我认为您根本不需要 lineTo 调用,为您节省一些数学:)
    猜你喜欢
    • 1970-01-01
    • 2017-10-31
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    相关资源
    最近更新 更多