We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Drawing thick circle segments
Page Index Toggle Pages: 1
Drawing thick circle segments (Read 910 times)
Drawing thick circle segments
Nov 18th, 2008, 1:05pm
 
Hello,

I'd like to draw a circle segment with a variable thickness, that is, like a pie chart with a hole in the middle.
So far, I've been able to do it using strokes, like this:

Code:

void drawSegment( int x, int y, int rad1, int rad2, float a1, float a2 )
{
arc( x, y, rad1*2, rad1*2, a1, a2 );
line( x+cos(a2)*rad2, y+sin(a2)*rad2, x+cos(a2)*rad1, y+sin(a2)*rad1 );
arc( x, y, rad2*2, rad2*2, a1, a2 );
line( x+cos(a1)*rad1, y+sin(a1)*rad1, x+cos(a1)*rad2, y+sin(a1)*rad2 );
}


void setup()
{
size( 400, 400 );
noFill();
drawSegment( 200, 200, 80, 90, 0, (TWO_PI/24) );
}


However, as you can see i'm not drawing correctly since the second arc, in order to follow the logical drawing sequence, should draw from angle2 to angle 1. This becomes evident when using a fill(). The reason I did it like this is because I can't draw an arc counterclockwise.

Any idea on how i could do this?

Thanks!
Re: Drawing thick circle segments
Reply #1 - Nov 20th, 2008, 9:21pm
 
This will let you fill an arc with a selected color. I'm not certain this is what you were trying to do, though.

(edit: a little easier to read, I hope)

Quote:
void drawSegment( int x, int y, int rad1, int rad2, float a1, float a2 )
{
 arc( x, y, rad2*2, rad2*2, a1, a2 );
}

void setup()
{
 size( 400, 400 );
 noFill();
 
 //add these
 color somecolor = color(0,128,255);//light blue
 stroke(somecolor);
 strokeWeight(15);//15 pixels thick
 strokeCap(SQUARE);//sharp edges
 //--------
 
 drawSegment( 200, 200, 80, 90, 0, (TWO_PI/6) );// made the arc a little larger just for fun :p
}

Re: Drawing thick circle segments
Reply #2 - Nov 20th, 2008, 11:06pm
 
Yes, Noah, it was my first idea, but the base remark of protozoo is valid, somehow Processing's arc command misses the large-arc and sweep flags of SVG, that would allow a finer control of path.

Another way to do the intended goal, although convoluted and not usable on complex background, is to draw a full arc section in intended color, then a smaller in the background color.
In both cases, the outline can be drawn afterward...
Re: Drawing thick circle segments
Reply #3 - Nov 21st, 2008, 10:02am
 
Hi there!

thanks both for your replies.
Noah's solution solved my needs in this case.

Thanks again!
Page Index Toggle Pages: 1