Initial attempt at incorporating Java Area and Polygon classes. Limit…

`…ing potential breakage to DXF writer code.`
clothbot committed Aug 27, 2010
1 parent c801704 commit 8680dbdf8298d4d8873a2999507674502135dcc9
Showing with 169 additions and 3 deletions.
1. +43 −0 Area2D.pde
2. +120 −0 Poly2D.pde
3. +3 −0 SuperSkein.pde
4. +3 −3 config.txt
 @@ -0,0 +1,43 @@ +// Testing 2D boolean operation using Java built-in Area construct. +// - extending example from http://wiki.processing.org/w/Using_AWT's_Polygon_class +import java.awt.geom.AffineTransform; +import java.awt.geom.Area; +import java.awt.geom.PathIterator; +import java.awt.Polygon; + +class Area2D extends Area{ + float gridScale; + public Area2D(Poly2D p) { + super( (Polygon) p ); + gridScale=p.gridScale; + } + public Area2D(float gScale) { + super(); + gridScale=gScale; + } + + boolean contains(int x, int y) { + double dx=x/gridScale; + double dy=y/gridScale; + return super.contains(dx,dy); + } + + boolean contains(double x, double y) { + double dx=x/gridScale; + double dy=y/gridScale; + return super.contains(dx,dy); + } + + void drawMe(){ + PathIterator pathIter=getPathIterator(new AffineTransform()); + beginShape(); + float[] newCoords={0,0}; + while(!pathIter.isDone()) { + pathIter.currentSegment(newCoords); + vertex(gridScale*newCoords[0],gridScale*newCoords[1]); + pathIter.next(); + } + endShape(); + } +} +
 @@ -0,0 +1,120 @@ +// Testing 2D boolean operation using Java built-in Area construct. +// - extending example from http://wiki.processing.org/w/Using_AWT's_Polygon_class + +import java.awt.Polygon; + +/* + The class inherit all the fields, constructors and functions + of the java.awt.Polygon class, including contains(), xpoint,ypoint,npoint +*/ + +class Poly2D extends Polygon{ + float gridScale; + float epsilon; + + public Poly2D(float gScale) { + super(); + gridScale=gScale; + epsilon=gridScale/2; + } + + public Poly2D(float gScale, int[] x,int[] y, int n) { + super(); + gridScale=gScale; + epsilon=gridScale/2; + //call the java.awt.Polygon addPoint function + for(int i=0;i
 @@ -405,6 +405,7 @@ class DXFWriteProc implements Runnable{ output.println("\nmodule dxf_slice(index=0) {"); Slice ThisSlice; + ArrayList PolyArray; float Layers = STLFile.bz2/LayerThickness; int renderWidth=width, renderHeight=height; int sliceCount=0; @@ -418,6 +419,8 @@ class DXFWriteProc implements Runnable{ pgDxf.setLayer(DXFSliceNum); DXFWriteFraction = (ZLevel/(STLFile.bz2-LayerThickness)); ThisSlice = new Slice(STLFile,ZLevel); + Poly2D ThisPoly2D = new Poly2D(0.01); + PolyArray = ThisPoly2D.Slice2Poly2DList(ThisSlice); lin = (Line2D) ThisSlice.Lines.get(0); for(int j = 0;j
 @@ -1,6 +1,6 @@ -CONFIG_SCALE 1.389099 -CONFIG_XROTATE 0.34234 -CONFIG_STLFILE C:\git\SuperSkein\triess_printable03.stl +CONFIG_SCALE 1.39 +CONFIG_XROTATE 0.34 +CONFIG_STLFILE sculpt_dragon.stl MACHINE_OPTEMP 220 MACHINE_FLOWRATE 190 CONFIG_SINK 2.0