Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw a perfect curve connecting three points

Tags:

android

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 ?
Please Help..

Thanks,
Sen

like image 271
Navaneeth Sen Avatar asked Sep 28 '10 09:09

Navaneeth Sen


1 Answers

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.

like image 170
Navaneeth Sen Avatar answered Nov 06 '22 01:11

Navaneeth Sen