Reputation: 618
I need to draw an arc in android with varying thickness, as represented in the below image,
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,
Please help me to achieve the above.
Upvotes: 2
Views: 1654
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
Reputation: 12122
I think, you can do this using Path
You arc has edges like:
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