OpenCAMLib
Loading...
Searching...
No Matches
OpenCAMLib developer manual

Introduction

This section of the manual describes the computational geometry and algorithms used in OpenCAMLib. Three-dimensional points and vectors are denoted with bold.

Drop-Cutter

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.

General

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:

  • diameter
  • radius
  • length

Cutter shapes:

  • Cylindrical: CylCutter
    • radius = diameter/2
  • Spherical: BallCutter
    • radius = diameter/2
  • Toroidal: BullCutter
    • radius1 = the radius of the cylindrical middle part of the cutter. also called the torus radius
    • radius2 = the tube-radius of the torus
    • radius2 <= radius1 must be true (undefined behavior may occur if radius2>radius1)
  • Conical: ConeCutter
    • diameter = maximum diameter of the cone
    • angle = half-angle of the cone, in radians. For a 90-degree cutter, set angle = pi/4
  • Compound: combinations of the above (restricted to an overall convex cutter shape). For example:
    • ConeConeCutter
    • BallConeCutter
    • BullConeCutter

Vertex test

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:

\[
d = |cl - p| = \sqrt{(cl.x-p.x)^2+(cl.y-p.y)^2}
\]

If $d > radius$ the cutter will not contact the vertex and we return without modifying cl.z. If $d <= radius$ 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)

Facet test

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

\[
a*x + b*y + c*z + d = 0
\]

where the coefficients $(a, b, c) = \bar{n}$. The constant d can be calculated by inserting one vertex into the formula of the plane: $d = -\bar{n}\cdot \bar{p_1}$.

Also calculate and normalize the xy-projection of the normal $\bar{n_{xy}}$. Note that vertical facets with n.z = 0 are a special case which are ignored in the drop-cutter algorithm.

Cylindrical cutter facet test

The contact point with the plane will lie on the periphery of the cutter, a distance $radius$ from $(cl.x, cl.y)$ in the direction $-\bar{n_{xy}}$, so the xy-coordinates of the cc-point are given by:

\[
(cc.x, cc.y) = (cl.x, cl.y) - r*\bar{n_{xy}}
\]

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:

\[
cc.z = (1/c)*(-d-a*cc.x-b*cc.y)
\]

Since the cylindrical endmill is flat, we can also set $cl.z = cc.z$. Note division by $c$ which requires $c = n.z \neq 0$

Spherical cutter facet test

The center of the sphere is located a distance $radius$ from $(cl.x, cl.y)$ in the direction of $-\bar{n}$. We can find out the xy-compontents of the cc point with:

\[
\bar{cc} = \bar{cl} - r*\bar{n}
\]

If this point lies within the facet of the triangle we locate the point on the plane by setting cc.z on the plane:

\[
cc.z = (1/c)*(-d-a*cc.x-b*cc.y)
\]

The tool-tip z-coordinate is now given by $cl.z = cc.z + r*(n\cdot\hat{z})  - r $

Toroidal cutter facet test

Define a vector which points from the cc-point to the center of the toroid. This is a distance $radius2$ along the surface normal \bar{n} and a distance $radius1$ along the XY-normal \bar{n_{xy}}:

\[
\bar{R} = r_2*\bar{n} + r_1* \bar{n_{xy}}
\]

Now the xy-coordinates of the cc-point are given by

\[
\bar{cc} = \bar{cl} - \bar{R}
\]

now check if this cc-point lies in the facet of the plane. If so, the z-coordinate of the cc-point is calculated:

\[
cc.z = (1/c)*(-d-a*cc.x-b*cc.y)
\]

And the tool-tip will be located at $cl.z = cc.z + r_2*n.z - r_2$

Conical cutter facet test

Describe ConeCutter facet test here.

Edge test

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

\[
p1u_y = d
p2u_y = d
\]

where d is the distance, in the XY-plane, from cl to a line through p1 and p2, i.e. $d = cl.xyDistanceToLine(p1, p2) $. We also define, in the XY-plane, the closest point to cl on the line as: $ sc = cl.xyClosestPoint( p1, p2 ) $.

Now the x-coordinates of p1u and p2u are given by:

\[
p1u_x = (p1-sc).dot(v)
p2u_x = (p2-sc).dot(v)
\]

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.

Cylindrical cutter edge test

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

Spherical cutter edge test

Toroidal cutter edge test

Conical cutter edge test

Optimizing drop-cutter

Using a kd-tree for finding triangles under the cutter

Z-slice

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.

Cutting Simulation

Describe cutting simulation here (octree etc).

References

Books

  • O'Rourke, Computational Geometry in C.
  • deBerg, Computational Geometry: Algorithms and Applications
  • Ghali, Introduction to Geometric Computing

<br>