# ZSlicing

**ZSlicing** is the step taken after 3DReading.

# Slicing the objects to make each build layer

RepRap has the objects to be built stored as Java3D BranchGroups. These are lists of triangles in space, stored as the (X, Y, Z) coordinates of their three corners.

At each layer a flat plane at Z = z_{layer} is sliced through this to find the 2D polygons that have to be plotted and filled in for that layer. The RepRap class that does this is in org.reprap.geometry.polygons.STLSlice.

The *BranchGroup* is unpacked by the function *recursiveSetEdges*, which transforms each triangle to its position on the build base and then calls the function *addEdge* with the three triangle coordinates in space as arguments.

The function *addEdgedoes* three things:

- It finds if the triangle has points either side of Z = z
_{layer}. If it does, the line of intersection of the triangle with that plane is computed and its endpoints (stored in a local class called*LineSegment*) are added to a list.

- For such triangles it computes that part of them that lies below the plane. This will either be another triangle or a quadrilateral, in which latter case it is divided into two triangles (the line labeled as a new edge on the figure). Thses triangles are added to a list of all those below the plane Z = z
_{layer}.

- Triangles completely below Z = z
_{layer}are also added to that list.

After all the triangles have been processed there will be a list of line segments that will form the polygons representing this layer of the object to be built. That list is passed onto the End Matching process.

There will also be a list of triangles below the slice plane. This list is put in a *BranchGroup* called `below`. This is subsequently supplied on request to the plotting simulation function as a shell for 3D plotting that represents the object built up to this current layer.

I'm not sure about this, but at the moment the software clicks each (x, y) coordinate of a line-segment end in the plane Z = z_{layer} onto a grid, which is decided by the value returned by Preferences.grid() (currently set to 10 microns). All I will say is that the program works better with this turned on than off...

-- Main.AdrianBowyer - 25 Feb 2008