How to draw a curved line between 2 points on canvas?

前端 未结 3 766
借酒劲吻你
借酒劲吻你 2021-01-02 17:14

I have tried a lot of different approaches from examples around the web, but I can\'t seem to get this to work. I am trying to make a method that draws a curved line between

3条回答
  •  迷失自我
    2021-01-02 18:05

    I think you are using wrong method for this purpose, one of the solutions that I can suggest is below

    float radius = 20;
    final RectF oval = new RectF();
    oval.set(point1.x - radius, point1.y - radius, point1.x + radius, point1.y+   radius);
    Path myPath = new Path();
    myPath.arcTo(oval, startAngle, -(float) sweepAngle, true);
    

    and for calculation of startAngle you will need

    int startAngle = (int) (180 / Math.PI * Math.atan2(point.y - point1.y, point.x - point1.x));
    

    for sweepAngle you can find detailed description here.

提交回复
热议问题