Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a concave path with arcTo in Android

I want to draw such a path and fill it:

enter image description here

If the origin point is red dot with (x, y) coordinates. What should I write in triple dots below to draw this path. I have tried much but cannot figure out how arcTo works.

    path.moveTo(x, y);
    path.arcTo(...);
    path.arcTo(...);
    canvas.drawPath(path, paint);
like image 269
Dorukhan Arslan Avatar asked Mar 18 '15 00:03

Dorukhan Arslan


1 Answers

ArcTo draw arc of oval inscribed in the rectangle from start angle to angle + sweep angle. All the rest is a pure geometry.

    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);

enter image description here

like image 181
Kolchuga Avatar answered Sep 29 '22 14:09

Kolchuga