Menu

#212 Wrong output when using ctDifference

*
closed
nobody
None
1
2022-03-04
2022-03-01
Anonymous
No

Hello! I found some wrong solution when I use two triangles for test. Subj:[(1, 0),(4, 1.73),(4, -1.73)], Clip:[(1, 0),(4, 1),(4, -1)]. I want to use "ctDifference" function. The C++ output shows no solution. I think there are problems. What should I do to output right solution?

Discussion

  • Anonymous

    Anonymous - 2022-03-01

    I think you'll find that if you sensibly scale your polygons, you'll get the result you're expecting.

     
  • Phil Stopford

    Phil Stopford - 2022-03-02

    To be clearer, ClipperLib works with integers. You'll need to scale up your geometry so that the minimum resolution sits on an integer interval (e.g. if you need to represent 0.001, you'll need to scale all of your geometry by at least 1000). You can then use this scaled geometry with ClipperLib and scale the result back down again afterwards.

    The main reason for this is to avoid errors from floating point precision.

     
  • Anonymous

    Anonymous - 2022-03-04

    I didn't know that it only works with integers. I rewrite the codes and it works! Thank you!

     
  • Angus Johnson

    Angus Johnson - 2022-03-04
    • status: open --> closed
     

Anonymous
Anonymous

Add attachments
Cancel