Draw a perfect curve connecting three points
Asked Answered
A

1

8

I would like to draw a curve connecting three points in my screen

PointA = (480,46)
PointB = (160,137)
PointC = (0,228)

How to draw the curve using Android APIs?

Audrieaudris answered 28/9, 2010 at 9:46 Comment(2)
What kind of curve? An arc of a circle?Rations
You can't draw a perfect circle using 2 Bezier curves, but you can add more to approximate itMuscular
A
13

Whatever i wanted, i could to produce it by using the following code :

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

    PointF mPoint1 = new PointF(w/1.2F, h/1.2F);
    PointF mPoint2 = new PointF(w/24, h/1.2F);
    Path myPath1 = new Path();
    Paint paint  = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Style.STROKE);
    paint.setStrokeWidth(2);
    paint.setColor(Color.WHITE);

    myPath1 = drawCurve(canvas, paint, mPoint1, mPoint2);
    canvas.drawPath(myPath1, paint);

}

private Path drawCurve(Canvas canvas, Paint paint, PointF mPointa, PointF mPointb) {

    Path myPath = new Path();
    myPath.moveTo(63*w/64, h/10);
    myPath.quadTo(mPointa.x, mPointa.y, mPointb.x, mPointb.y);
    return myPath;  
}

This will find the two sides of the screen (Landscape mode) and will draw a perfect curve across the screen.

Audrieaudris answered 28/9, 2010 at 13:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.