PDA

View Full Version : painter's drawPie() function how to draw few sensible PIEZ..



salmanmanekia
27th August 2008, 12:01
Hi
i have been trying to show the progress as a pie through drawPie function in Painter,so the pie is shown in 4 stages on first button click it is required to be drawn upto 90 degress ,on second button click it is required to draw upto 180 degress and in the same way when fourth button is clicked it should show a whole circle..
Now what i have achive is the same thing through drawPie but my code is realy messy and the value of cordinates doesnt makes sense,so i have to copy paste my code couple of time


painter.drawPie( (MID_POINT_OUTER_X -40 ), (MID_POINT_OUTER_Y-70) ,
( OUTER_ELLIPSE_WIDTH - (6*INNER_ELLIPSE_WIDTH) ) ,
( OUTER_ELLIPSE_HEIGHT - (4.5*INNER_ELLIPSE_HEIGHT ) ) ,
90*16 , -90*16 );
painter.drawPie((MID_POINT_OUTER_X -40 ), (MID_POINT_OUTER_Y-68) ,
( OUTER_ELLIPSE_WIDTH - (6*INNER_ELLIPSE_WIDTH) ) ,
( OUTER_ELLIPSE_HEIGHT - (4*INNER_ELLIPSE_HEIGHT ) ) ,
0*16 , -90*16 );
..
painter.drawPie( (MID_POINT_OUTER_X -69 ), (MID_POINT_OUTER_Y-70) ,
( OUTER_ELLIPSE_WIDTH - (6*INNER_ELLIPSE_WIDTH) ) ,
( OUTER_ELLIPSE_HEIGHT - (4.5*INNER_ELLIPSE_HEIGHT ) ) ,
-180*16 , -90*16 );

what i require here is that some how i can build a single function and just pass painter pointer and the starting and ending angle as paramters to that fuction but the first four parameters of drawPie in my case dont follow any sensible pattern or sequence so i have to pass seven parameters and do some mess in function,which doesnt make any sense...any idea on this..

wysota
27th August 2008, 12:57
What do all these constants stand for? What are those 70, 68, etc.? The worst you might need are functions such as tg and ctg to calculate the bounding rectangle of the pie based on the angle you want to draw.

salmanmanekia
27th August 2008, 13:08
i just used the constant because i thought the value of constant would be perfect for every parameter but when i ran my application i saw a few randomly distributed pies,so i started to adjust the cordinate by subtracting the 'MID_POINT..'constant with numbers (69,70 etc)so i can achieve what i want ...this was based on hit and try method and it worked but without any logic
sorry i cannot understand what you meant by this..

The worst you might need are functions such as tg and ctg to calculate the bounding rectangle of the pie based on the angle you want to draw.
what is tg and ctg..?

wysota
27th August 2008, 13:27
what is tg and ctg..?

Tangent and co-tangent (trigonometric functions). They will let you calculate offsets from the center of the pie. Just take a piece of paper, draw an arbitrary pie (assuming you know its angle) and try to calculate bounding rectangle of the pie. Then simply transfer the same calculations into your application.

salmanmanekia
28th August 2008, 08:19
ok,this some how seems to be a good idea,but i cannot understand it fully...
i understand that i should draw a pie on a piece of paper with an starting and ending angle,it's x and y cordinates and width and height and then i will calculate tan() and inverse tan()...but how can i calculate it ,i mean mathematically i can only calculate these things for a triangle..waiting...

aamer4yu
28th August 2008, 09:28
Hint : what is a triangle ? A set of 3 points ;)

salmanmanekia
28th August 2008, 11:10
i understand...but i m afraid what does it means:rolleyes:

salmanmanekia
28th August 2008, 15:24
any idea of how to implement the tangent and co-tangent .....

wysota
28th August 2008, 16:13
You don't have to implement them, they are in standard math library.

Here is a drawing for you... You have to calculate "x" and "y" given all the angles and "l". What is y/a? What is a/l? What is y/l? What is the mysterious angle?

salmanmanekia
28th August 2008, 22:04
thanks for the hint,
actually in my case i have to draw a 90 degree pie so i suppose 'alpha' would be 90 degree am i right and since i have to calculate y/a so it seems that it means it is perp./base. which is equal to tan..but i am afraid all the three values are unknown or atleast y and a are unknown if i consider 'Q(theta)' to be 45 ,as the sum of all angle is 180 for straight line and since pie is already 90 degree so i can suppose the other two angle to be 45 degree each ..but still its supposition..:eek:

wysota
29th August 2008, 08:30
You don't have to assume anything here, you have all the values you need. Answer all my questions from the previous post and you will see. Especially think what is y/l and for a 90deg. pie you'll almost have a final answer.

salmanmanekia
29th August 2008, 13:51
i am still confused maybe i am not getting the point what you are trying to say..!!

salmanmanekia
29th August 2008, 13:52
maybe it seems y/l = 1..if i consider the angle to be 45 degree..is it somehow useful..!!

wysota
30th August 2008, 13:39
Good. y/l is always 1, regardless of the angle. So now if you have "l" and the "?" angle, you can calculate "a". And having that you can calculate "x". You already have "y" (which equals "l"), so you have all values needed to pass to drawPie().

salmanmanekia
31st August 2008, 12:00
y/l is always 1, regardless of the angle.
hmm..ok..it seems fine

So now if you have "l" and the "?" angle, you can calculate "a".
I have supposed the value of "l" to be 10 and angle "?" to be 45,so is it what i should do i mean supposition or should i calculte these values from some other parameters ?

And having that you can calculate "x".
since in the above scenario i have considred "l" to be 10 so the value of "x" should be 20 ,am i right

You already have "y" (which equals "l"),
if all above things are rite then i guess that this is quite the value i was looking for..

wysota
31st August 2008, 16:52
You don't have to assume anything. I take it that you know either "y" or "l" (which is the same) because you know how "big" your pie is to be. The rest can be calculated using trigonometric functions as I have shown above.