Joy Rex
Joy Rex

Reputation: 618

How to draw an arc with varying thickness

I need to draw an arc in android with varying thickness, as represented in the below image,

Arc from from some startDegree to endDegree with varying thickness

Is it possible to draw an arc and clip it? as the arc can be between any degrees (startDegree to endDegree), i can't acheive this with path.

so my requirement is something like this,

example code snippet

Please help me to achieve the above.

Upvotes: 2

Views: 1654

Answers (2)

Kit Swarup
Kit Swarup

Reputation: 1

The following function would work, keeping in mind the angle in degrees for converting into radians. Kindly change the datatype to double:

void spiralArc(int startAngle, ind endAngle, int centreX, int centreY,int radius, int maxThickness)
{
    int iRadius;
    for(int ang=startAngle;ang<=endAngle;ang++)
    {
        iRadius = radius - (int)((double) maxThickness*(double)ang/(double)endAngle);
        drawLine(centreX+(radius*cos(ang)), centreY+(radius*sin(ang)), centreX+(iradius*cos(ang)), centreY+(iradius*sin(ang)))
    }
}

Upvotes: 0

krossovochkin
krossovochkin

Reputation: 12122

I think, you can do this using Path

You arc has edges like:

  • horizontal straight line
  • upper arc
  • vertical straight line
  • lower arc

So, you need to take some math to calculate these coordinates and params.

UPD:
Please, take a look at this question Seems like I found exact formula for this curve there.

UPD 2:
About how to draw spiral on canvas, I think not very bad solution is do like here (there javascript is used, but it doesn't matter – the idea is the same). The only thing: it is needed to write spiral equation in Cartesian coordinate system. Try to do this by yourself. If you fail, then ask me.

UPD 3: Check mentioned above question's UPD2 section to find Cartesian coordinate system parametrization. It might contain mistakes, I didn't check it by myself, but the idea should be clear.

Hope it helps.

Upvotes: 1

Related Questions