# XOR

6 messages
Open this post in threaded view
|

## XOR

 Hi everybody, I just made a xor module to accompany union, intersection and difference. After drawing some truth tables I figured out that the difference of union and intersection should give xor, or in OpenSCAD code: module xor(){   difference(){     for(i = [0 : \$children - 1])       child(i);     intersection_for(i = [0: \$children -1])       child(i);   }                                 } Maybe this is of use for someone. Regards Johannes -- Johannes Reinhardt <[hidden email]>
Open this post in threaded view
|

## Re: XOR

 XOR doesn't really make sense with more than two objects. Difference takes the first object and subtracts all the others from it, so for consistency with that, I would recommend unioning all of the children after the first before feeding it to the function that you have defined. As you have written it, only areas included in all objects will be subtracted. On Sunday, July 15, 2012 at 9:41 AM, Johannes Reinhardt wrote: Hi everybody,I just made a xor module to accompany union, intersection anddifference. After drawing some truth tables I figured out that thedifference of union and intersection should give xor, or in OpenSCADcode:module xor(){ difference(){ for(i = [0 : \$children - 1]) child(i); intersection_for(i = [0: \$children -1]) child(i); } }Maybe this is of use for someone.RegardsJohannes-- Johannes Reinhardt <[hidden email]>_______________________________________________OpenSCAD mailing list[hidden email]http://rocklinux.net/mailman/listinfo/openscad
Open this post in threaded view
|

## Re: XOR

 In reply to this post by Johannes Reinhardt Johannes that is very cool, If this is needed by a lot of people maybe there could be a builtin 'xor' or 'symmetric_difference' function added to OpenSCAD? CGAL itself actually has  'symmetric difference'  code inside of it, its just not exposed by OpenSCAD. http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Boolean_set_operations_2/Chapter_main.htmlhttp://en.wikipedia.org/wiki/Symmetric_differencehttp://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3/Chapter_main.html-DB On Sun, Jul 15, 2012 at 11:41 AM, Johannes Reinhardt <[hidden email]> wrote: > Hi everybody, > > I just made a xor module to accompany union, intersection and > difference. After drawing some truth tables I figured out that the > difference of union and intersection should give xor, or in OpenSCAD > code: > > module xor(){ >   difference(){ >     for(i = [0 : \$children - 1]) >       child(i); >     intersection_for(i = [0: \$children -1]) >       child(i); >   } > } > > Maybe this is of use for someone. > > Regards > > Johannes > > > -- > Johannes Reinhardt <[hidden email]> > _______________________________________________ > OpenSCAD mailing list > [hidden email] > http://rocklinux.net/mailman/listinfo/openscad> http://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|