XOR

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

XOR

Johannes Reinhardt
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]>

Reply | Threaded
Open this post in threaded view
|

Re: XOR

Whosawhatsis
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 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

Reply | Threaded
Open this post in threaded view
|

Re: XOR

donbright
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.html

http://en.wikipedia.org/wiki/Symmetric_difference

http://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

Reply | Threaded
Open this post in threaded view
|

Re: XOR

Brad Pitcher
This openscad implementation causes non 2-manifold errors for me, with something as simple as two intersecting spheres:

xor() {

sphere(10);

translate([19, 0, 0]) sphere(10);

}


Do you know if this CGAL implementation would fix that problem?

On Sun, Jul 15, 2012 at 1:45 PM, Don Bright <[hidden email]> wrote:
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.html

http://en.wikipedia.org/wiki/Symmetric_difference

http://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
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: XOR

Whosawhatsis
I was afraid of that. This method virtually guarantees that you will have two solids with abutting edges, which is a bad thing. The CGAL implementation won't change this fact, which is probably why it was left out of OpenSCAD in the first place.

On Sunday, July 15, 2012 at 2:07 PM, Brad Pitcher wrote:

This openscad implementation causes non 2-manifold errors for me, with something as simple as two intersecting spheres:

xor() {

sphere(10);

translate([19, 0, 0]) sphere(10);

}


Do you know if this CGAL implementation would fix that problem?

On Sun, Jul 15, 2012 at 1:45 PM, Don Bright <[hidden email]> wrote:
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.html

http://en.wikipedia.org/wiki/Symmetric_difference

http://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
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


Reply | Threaded
Open this post in threaded view
|

Re: XOR

Giles Bathgate-2
In reply to this post by Johannes Reinhardt

I am not sure but I think this may be the same as symmetric_difference which is provided by CGAL. I've exposed this in rapcad for anyone wanting a reference implementation.

Regards

Giles

On Jul 15, 2012 7:55 PM, "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