OpenCAMLib
|
This section of the manual describes the computational geometry and algorithms used in OpenCAMLib. Three-dimensional points and vectors are denoted with bold.
The drop cutter algorithm drops a cutter, positioned at a predefined (x,y) location down along the z-axis until it makes contact with a triangle. The algorithm is split into three parts, testing the cutter separately against the three vertices ( vertexDrop() ), three edges ( edgeDrop() ), and the facet ( facetDrop() )of the triangle. In general the vertex test is trivial, the facet test easy, and the edge test is the most difficult.
A cutter-location cl point is a point where the cutter tip can be located when in contact with the surface, but without interfering with the STL-surface. A cutter-contact (cc) point is the point where the cutter makes contact with the STL-surface. The user specifies the (cl.x, cl.y) coordinates of the cutter, and an initial value cl.z for the cl z-coordinate. The task for the vertex, facet, and edge tests is to update the height of the cutter cl.z. When each vertex, edge, and facet of each triangle under the cutter positioned at (cl.x, cl.y) has been tested, the resulting cl.z is the correct and final (maximum) height of the cutter we want. If no test finds a contact between the cutter and a triangle, then cl.z and cc are left unmodified.
The following milling cutters are supported by opencamlib. They all inherit from the base-class MillingCutter. The CompoundCutter class allows specifying any shape similar to a general APT-type cutter.
All cutters share common data-fields:
Cutter shapes:
Milling cutters are symmetrical around their axis of rotation (the z-axis in 3-axis milling), so the vertex test only depends on the distance between the cutter axis and the test-vertex. Given cl and a vertex p to test, calculate the distance d in the xy-plane from cl to p:
If the cutter will not contact the vertex and we return without modifying cl.z. If
the cutter will make contact with the vertex.
- Cylindrical cutters are flat we can set \f$cl.z = p.z\f$ - For a Spherical cutter (see FigureX) \f$h = r - \sqrt{ r^2 - d^2 }\f$ and we set \f$cl.z = p.z - h\f$ - For Toroidal cutters: - If \f$d < r_1\f$ we are in the cylindrical part of the cutter and set \f$cl.z = p.z\f$ - If \f$r_1 < d < r\f$ we are in the toroidal part and \f$ h = r_2 - \sqrt{ r_2^2 - (d-r_1)^2 }\f$ and then \f$cl.z = p.z - h\f$ - For Conical cutters: - \f$h = d/tan(angle)\f$ and set \f$cl.z = p.z - h\f$
In all cases cc = p. (TODO: insert image of vertex test here)
Call the three vertices of the triangle p1, p2, and p3. The facet test is really a test against the whole plane which contains the triangle facet. First calculate the normal n of the facet, and normalize its length to one. The equation for the plane is given by
where the coefficients . The constant d can be calculated by inserting one vertex into the formula of the plane:
.
Also calculate and normalize the xy-projection of the normal . Note that vertical facets with n.z = 0 are a special case which are ignored in the drop-cutter algorithm.
The contact point with the plane will lie on the periphery of the cutter, a distance from
in the direction
, so the xy-coordinates of the cc-point are given by:
This cc-point lies on the plane, but not necessarily in the facet of the triangle. If the cc-point is contained within the triangle (in the xy-plane), we can calculate its z-coordinate by inserting into the equation of the plane:
Since the cylindrical endmill is flat, we can also set . Note division by
which requires
The center of the sphere is located a distance from
in the direction of
. We can find out the xy-compontents of the cc point with:
If this point lies within the facet of the triangle we locate the point on the plane by setting cc.z on the plane:
The tool-tip z-coordinate is now given by
Define a vector which points from the cc-point to the center of the toroid. This is a distance along the surface normal \bar{n} and a distance
along the XY-normal \bar{n_{xy}}:
Now the xy-coordinates of the cc-point are given by
now check if this cc-point lies in the facet of the plane. If so, the z-coordinate of the cc-point is calculated:
And the tool-tip will be located at
Describe ConeCutter facet test here.
Each test loops through all three edges of the triangle. The edge is defined by its startpoint p1 and its endpoint p2.
It is easier to do the tests in a translated and rotated coordinate system where the cl-point is at (0,0) and the edge is rotated to be parallel with the X-axis. We call the new endpoints of the edge p1u and p2u. These are found by noting that
where d is the distance, in the XY-plane, from cl to a line through p1 and p2, i.e. . We also define, in the XY-plane, the closest point to cl on the line as:
.
Now the x-coordinates of p1u and p2u are given by:
where v is a normalized vector in the direction of the edge, or v=(p2-p1).xyNormalize()
The tests find a contact between the cutter and an infinite line which contains the edge we are testing against. Once the contact cc-point is found we check whether this cc-point is actually in the edge.
In the XY-plane we want to find the intersection between an infinite line and a circle. This is described e.g. here: see http://mathworld.wolfram.com/Circle-LineIntersection.html
An algorithm for 'slicing' an STL surface at a defined Z-coordinate. Produces waterline type paths. These contours can be used as a starting point for area-clearing algorithms in roughing operations.
Describe cutting simulation here (octree etc).