0

Given a 2D polygon made up of a set of points, I'm looking to draw hatching through the inside of the polygon. By hatching I mean evenly spaces lines, all at around 45 degrees.

I'm having trouble thinking of a way to get this to work that wouldn't be very slow though, having to check each prospective line against all of the polygon edges for intersection.

Does anyone have any idea how to approach this, or any existing techniques that might work?

Thanks.

djcmm476
  • 1,723
  • 6
  • 24
  • 46
  • Have you tried just using `FillPolygon` using an isntance of `HatchBrush` as the brush for the fill? The HatchBrush has a property called `HatchStyle` which has many different styles available, for example `ForwardDiagonal` which draws hatch lines from the upper left to lower right. – Chris Dunaway Oct 08 '14 at 14:56
  • look here http://stackoverflow.com/a/25052821/2521214 – Spektre Oct 08 '14 at 21:22

1 Answers1

0

You can use FillPolygon and a HatchBrush like this:

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    //A using statement on the brush will make sure it is disposed.
    using (var b1 = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Red))
    {
        PointF[] points = methodThatReturnsPointsForAPolygon();
        e.Graphics.FillPolygon(b1, points);
    }
}
Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48
  • I should have been a bit more specific, sorry. The actual graphics is being done using an API (called HOOPS). It has all the usual geometry stuff (lines, curves, polygons, etc, etc) that I think you'd need to work a hatch out, but nothing like what you mentioned above. – djcmm476 Oct 09 '14 at 13:46