We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Shape boolean operation and PDF
Page Index Toggle Pages: 1
Shape boolean operation and PDF (Read 337 times)
Shape boolean operation and PDF
Feb 13th, 2009, 9:48pm
 
Hi forum,
I try to merge shapes with the help of geomerative. It works fine, but I like to write the resulting shape into a pdf.

With the code below it works, but the filling of the resulting shape is a huge group of shapes.

Can anyone gives me a hint how to merge the filling to one single shape?

//PDF
import processing.pdf.*;
////////////////////////////////////////////////////////////////////////
import geomerative.*;
RPolygon c;
void setup(){
 size(800,600);
 smooth();
 RG.init(this);
 RG.setPolygonizer(RG.ADAPTATIVE);
 
 fill(0);
 stroke(0);
 beginRecord(PDF, "test.pdf");
 
 RPolygon c1 = RPolygon.createCircle(0,-20,30);
 RPolygon c2 = RPolygon.createCircle(20,40,45);
 RPolygon c3 = RPolygon.createCircle(-40,-20,40);
 RPolygon c4 = RPolygon.createCircle(0,0,10);

 c = new RPolygon();
 c = c.union(c1);
 c = c.union(c2);
 c = c.union(c3);
 c = c.diff(c4);
}

void draw(){
 background(255);
 translate(width/2,height/2);
 c.draw();

}
//PDF
void mouseReleased() {
 endRecord();
 println("Mouse");
 exit();
}
Re: Shape boolean operation and PDF
Reply #1 - Feb 13th, 2009, 10:38pm
 
I'm speculating here, but:

PDF (and its ancestor, postscript) have a setting called the "fill rule" which determines whether a point is considered to be "inside" a polygon or not.

This doesn't matter for simple polygons like squares or whatever, but it does matter for self-intersectiong polygons (ones that have some edges that cross other edges).

If memory serves (and man, has it been a long time since I had to know this) the two fill rule alternatives are the "non-zero winding rule" and the "even/odd rule".

In one of those rules, the whole polygon gets filled in in the obvious way, but in the other rule the parts of the polygon that overlap the rest turn into "holes" and don't get filled.  I don't remember which is which anymore.

Anyway, you might look for a similar setting in the processing.pdf library.  It's possible that whatever the default setting is for the pdf library isn't matching the rule used internally by processing, in which case what you're seeing in the PDF file may not match what you see in the processing window.
Re: Shape boolean operation and PDF
Reply #2 - Feb 13th, 2009, 10:39pm
 
P.S.  All that matters because what you're doing, by using shape union/difference operators, is creating a complex polygon whose permiter intersects itself.  Hence, the fill rule matters.
Re: Shape boolean operation and PDF
Reply #3 - Feb 14th, 2009, 6:38pm
 
Thanks cloister for your help. I will find out how to change the rules for pdf output to solve it!
Page Index Toggle Pages: 1