Results 1 to 11 of 11

Thread: [RESOLVED] Spikes Appear Using DrawEllipse When Pen Thickness Goes High

  1. #1

    Thread Starter
    Fanatic Member EntityX's Avatar
    Join Date
    Feb 2007
    Location
    Omnipresence
    Posts
    798

    Resolved [RESOLVED] Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    I have a graphics program and in it I use DrawEllipse plenty and when the pen thickness gets high like around 12 pixels or above you start to see these spikes. I'm using a PictureBox so double buffering is being used. Is there anything I can do to get rid of the "spikes". In the screenshot at top the pen thickness is at 19 and is 28 in the lower.
    Attached Images Attached Images   
    Last edited by EntityX; Oct 21st, 2011 at 05:32 PM.
    Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

    "Persistence is the magic of success." Paramahansa Yogananda

  2. #2
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    Have seen similar things when drawing svg... But anyway...

    Instead of draw elipse... Have you tried adding them to a graphics path and rendering that?

    Kris

  3. #3

    Thread Starter
    Fanatic Member EntityX's Avatar
    Join Date
    Feb 2007
    Location
    Omnipresence
    Posts
    798

    Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    I use graphics paths also but here I want to use DrawEllipse. Perhaps there's no way to correct that problem. By greatly increasing the number of lines and then using a lower pen thickness I could get the same image but it would take a lot more computing power and probably run a lot slower.
    Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

    "Persistence is the magic of success." Paramahansa Yogananda

  4. #4
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    I mean like this:

    vb Code:
    1. Module GraphicsExt
    2.  
    3.     <System.Runtime.CompilerServices.Extension()> _
    4.     Public Sub DrawPathEllipse(ByVal sender As Graphics, ByVal p As Pen, ByVal Rect As RectangleF)
    5.         Using gp As New System.Drawing.Drawing2D.GraphicsPath
    6.             gp.AddEllipse(Rect)
    7.             sender.DrawPath(p, gp)
    8.         End Using
    9.     End Sub
    10.  
    11. End Module

    Then instead of calling graphics.DrawEllipse call graphics.DrawPathEllipse...

    Try that and let me know
    Kris

  5. #5

    Thread Starter
    Fanatic Member EntityX's Avatar
    Join Date
    Feb 2007
    Location
    Omnipresence
    Posts
    798

    Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    I appreciate the effort. I tried it but I get an identical result. I used screenshots to compare and went to the exact same frame using the two different methods and there's no improvement.
    Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

    "Persistence is the magic of success." Paramahansa Yogananda

  6. #6
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    It looks like the spikes are only appearing when they are drawn Facing 0 90 180 and 270 degrees, might it not be that there is some error in your drawing code that is causing this ?

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  7. #7

  8. #8
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    Graphics.DrawEllipse produces increasingly angular results when you use a pen which is wider than the minor axis of the ellipse. It just wasn't designed for that eventuality! For example:

    vb Code:
    1. Using pn As New Pen(Brushes.Blue, 20)
    2.     e.Graphics.DrawEllipse(pn, 100, 100, 50, 1)
    3. End Using
    result:
    Name:  spikyEllipse1.jpg
Views: 288
Size:  1.9 KB

    Clearly your ellipses are approaching this kind of limit near the horizontal and vertical extremities of the loops. You can reduce the length of the spikes by setting the pen's MiterLimit to a smaller value (I think the default is 10), although the result still isn't exactly pretty:
    vb Code:
    1. pn.MiterLimit = 1
    2. e.Graphics.DrawEllipse(pn, 100, 150, 50, 1)
    result:
    Name:  spikyEllipse2.jpg
Views: 298
Size:  1.1 KB

    If you are able to look at GraphicsPath.AddEllipse/Graphics.DrawPath as an alternative, you might get better results by using the GraphicsPath.Flatten method with a small value (e.g. 0.05. I think the default is 0.25) to get more path points. On the whole, the best way to avoid this kind of thing would be to start using WPF instead of GDI+. But that's a whole 'nother story.

    Afterthought: maybe the simplest way to fix this would be to switch to using FillEllipse when the eccentricity (ratio of x to y dimension) goes past a chosen upper or lower limit. Obviously you'd have to adjust the size of the filled ellipses to allow for the intended pen thickness.

    BB

  9. #9

    Thread Starter
    Fanatic Member EntityX's Avatar
    Join Date
    Feb 2007
    Location
    Omnipresence
    Posts
    798

    Re: Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    Boops, it was less than 500 billion eons before you helped me out again. I thought it was going to be at least 100 billion eons. I am indebted to you once again. Dropping the MiterLimit for the pen to 1 has as far as I'm concerned completely fixed the problem. I noticed that you can set MiterLimit to fractional values and it responds to fractional values. I can see a difference between 1.5 and 1 but not between 1 and 0.5. Using 1 seems to work quite well.

    The MiterLimits in the below screenshots are from top to bottom 5 which looks about the same as before, 2 and 1 which looks best.
    Attached Images Attached Images    
    Last edited by EntityX; Oct 22nd, 2011 at 10:11 AM.
    Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

    "Persistence is the magic of success." Paramahansa Yogananda

  10. #10

    Thread Starter
    Fanatic Member EntityX's Avatar
    Join Date
    Feb 2007
    Location
    Omnipresence
    Posts
    798

    Re: [RESOLVED] Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    I did notice setting MiterLimit to 1 can sometimes create undesireable changes. In most cases I'm adjusting MiterLimit down but not in all cases. I found that you can set MiterLimit to -999 without any problem occurring and it appears you get the same result as setting it to 1. As far as I can see 1 and anything below 1 is all the same thing. I'm using this code in many places in my program.

    MyPen.MiterLimit = 11 - PenWidth

    If PenWidth is 1 then MiterLimit will be at 10 and if PenWidth is 50 then MiterLimit would be -39 which would be the same thing as 1.
    Last edited by EntityX; Oct 22nd, 2011 at 02:32 PM.
    Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

    "Persistence is the magic of success." Paramahansa Yogananda

  11. #11
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: [RESOLVED] Spikes Appear Using DrawEllipse When Pen Thickness Goes High

    Been a while since i've looked @ this ... but how about drawing a perfect circle each time ... but transforming it to be the actual size you need? - i am sure this would work

    Kris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width