Xor on two polygons

I am trying to perform an XOR function on two polygons.
I tried using the solution mentioned in the following question and followed instructions on this page:
Here is my attempt on using the EdgeProcessor:

points1 = [pya.Point(0/0.001,-10/0.001), pya.Point(0/0.001,0/0.001), pya.Point(4/0.001,0/0.001), pya.Point(4/0.001, -10/0.001)]
points2 = [pya.Point(-3/0.001,-7/0.001), pya.Point(-3/0.001,0/0.001), pya.Point(5/0.001,0/0.001), pya.Point(5/0.001,-7/0.001)]

a = pya.Polygon(points1)
b = pya.Polygon(points2)
ep = pya.EdgeProcessor()
ep.boolean_p2p(a, b, ep.ModeXor, False, False)

but it gave the following error:

Expected a list or tuple for argument or return type in
EdgeProcessor.boolean_p2p

Thank you for your support.

Jaspreet

Comments

  • edited July 2016

    Figured it out.

    Here is the code:

    from operator import xor
    points1 = [pya.Point(0/0.001,-10/0.001), pya.Point(0/0.001,0/0.001), pya.Point(4/0.001,0/0.001), pya.Point(4/0.001, -10/0.001)]
    points2 = [pya.Point(-3/0.001,-7/0.001), pya.Point(-3/0.001,0/0.001), pya.Point(5/0.001,0/0.001), pya.Point(5/0.001,-7/0.001)]
    
    a = pya.Region(pya.Polygon(points1))
    b = pya.Region(pya.Polygon(points2))
    
    c = xor(a,b)
    
  • edited November -1

    Hi,

    very good :-)

    That is exactly the preferred solution (instead of xor you can write a ^ b). The Region object is a newer one that shields you from the trouble with the edge processor and similar things.

    Matthias

Sign In or Register to comment.