2

I am getting quite a few spikes when offsetting Polygons with the clipper library, this is unfortunately not acceptable in my use case and I have no idea how to get rid of it. I have tried all type of join type settings but could not achieve anything. Any help would be greatly appreciated.

My application layers a model and calculates the outline polygons. It then also has to offset the outlines. Layers with a lot of curves in then tend to get one or more spikes each such as this: enter image description here

Now this does not seem to bad but once it happens to a lot of layers a model becomes like this: enter image description here

It is important to note that without offsetting the outlines I get none of these spikes.

Here is a file containing the input polygons: http://sdrv.ms/H7ysUC

Here is a file containing the output polygons: http://sdrv.ms/1fLoZjT

The parameters for the operation were an offset operation with jtRound JointType with default limit. The delta was -25000. I have also tried all the other JoinTypes with limits ranging from 0 to 1000 but they all created the exact same spike. The other JoinTypes though had some other added strange effects.

Community
  • 1
  • 1
Gerharddc
  • 3,921
  • 8
  • 45
  • 83
  • I'm not aware of any significant issues with Clipper's offsetting function so it's pretty hard to help unless you can submit some sample data. An image highlighting the problem would probably help too. – Angus Johnson Oct 19 '13 at 10:29
  • Ok I'll add some pictures once I get to my pc – Gerharddc Oct 19 '13 at 12:24
  • @AngusJohnson I have now added some pictures – Gerharddc Oct 19 '13 at 16:58
  • The images nicely show there's a problem somewhere, but I need some data - ie input polygon coordinates (for just one polygon), the delta and other parameters used in the offset function, and the solution returned by the function (that contain the spike). – Angus Johnson Oct 19 '13 at 17:33
  • @AngusJohnson I have now added text files describing the points on the input and output polygons – Gerharddc Oct 19 '13 at 18:49
  • And what's the delta? Oops, I see it now in your edited post. Thanks. – Angus Johnson Oct 19 '13 at 20:57

1 Answers1

2

OK, I can confirm there's a bug. It happens when adjacent polygon edges are almost collinear.

Here's the fix (that hasn't been heavily tested yet) at about line 4220 in clipper.cs

      void OffsetPoint(JoinType jointype)
      {
          m_sinA = (normals[m_k].X * normals[m_j].Y - normals[m_j].X * normals[m_k].Y);
          if (Math.Abs(m_sinA) < 0.00005) return; //ADD THIS LINE (todo - check this!)
          else if (m_sinA > 1.0) m_sinA = 1.0;
          else if (m_sinA < -1.0) m_sinA = -1.0;

Note: 0.00005 is just a value that's close enough to zero to remove the spike in your supplied sample, but it may need to be readjusted with further testing.

Angus Johnson
  • 4,565
  • 2
  • 26
  • 28