Drawing Arcs via putpixel routine

Hello out there,



I would like to draw Arcs

( Like the ones you see when you call

Arc( x, y, stAngle, endAngle, Radius ),

but i want to draw the Arc pixel by pixel



Are there some wizards who can help me out ?



And please don't misunderstand me, i know how to put a pixel on the screen, i'm interested in the formula to calculate the x and y values which are needed to create a Arc



Tnx in advance






Comments

  • I think you can use the cos and sin functions to calculate the coordinate of a particular point on the arc at an angle.



    X and Y are the center point.



    for Angle := start_angle to end_angle do

    NewX = X + (radius * cos(Angle))

    NewY = Y - (radius * sin(Angle))

    end;



    *The reason I do Y-(...) is because of screen coordinate, Y value increase as you go down, opposite of the cartesian coordinate system.



    I guess you can do something like that, but I just wrote that here, so I don't have a chance to test it.



    Good Luck

    Phase_Zero


  • Yep,

    that can do the job with a few modifications, but i would like to draw the Arc with an algorithm. I've found some stuff about Bresenhams Midpoint Algorithm which can be used to draw a Circle.

    I don't know how to modify this to draw an Arc the same way.



    I've been surfing for about 10 hours and didn't find a way, so maybe someone else with a fresh look at the problem has an idea ?



    Tnx in advance


  • i don't know what that algorithm you mentioned is, but if you have the source for it then you can tell how it works, and, say, if it draws pixel by pixel in a straight order then just make it draw only a quarter of the way.



    i still don't know why you can't settle for the standard ARC, perhaps you want to put different colors in between..



    anyway, try putting pixels from an X to an X and as for the Y's you increase or decrease when the index reaches certain numbers like if it divides by 2 with no remainder or something, i don't know exactly how it would look but play with it..



    or from a certain Y to a certain Y and change the X values along the way in a similar fashion.



    i do think that cos and sin would be the best way to go about this but maybe you can find a new formula that works for these things..



    the important thing is to keep trying..

    //Noam


  • I have heard of the Bresenham's alogarithm, but only for drawing straight lines, so I don't know if the one you are referring to "Bresenhams Midpoint Alogarithm" is the same one. Anyway, it was a long time ago when I saw that alogarithm and I don't use it often (why would I) so I don't remember every key points in the alogarithm. All I know is that the B alogarithm looks for a suitable point (X,Y) to plot based on how close it is from a given line segment. Now, all this does it that it will draw a more accurate line, as for drawing curves, maybe you can somehow modify it to fix your needs. Good Luck.



    Phase Zero




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories