I want to draw such a path and fill it:
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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With