2010-09-28 4 views
8

Je voudrais tracer une courbe reliant trois points dans mon écran
Pointa = (480,46) PointB = (160137) PointC = (0.228)Dessine une courbe parfaite reliant trois points

Comment dessiner la courbe en utilisant les API Android?
S'il vous plaît aider ..

Merci,
Sen

+2

Quel type de courbe? Un arc de cercle? –

+0

Je dois dessiner un arc parfait – Sen

+0

Vous ne pouvez pas dessiner un cercle parfait en utilisant 2 courbes de Bézier, mais vous pouvez en ajouter d'autres pour l'approximer –

Répondre

13

Tout ce que je voulais, je pouvais pour le produire en utilisant le code suivant:

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

Ceci trouvera les deux côtés de l'écran (Mode Paysage) et dessine une courbe parfaite sur l'écran.

Questions connexes