Fighting with computers

Computers are not always friendly.

Thursday, May 12, 2016

Dropcutter oddities

A while ago I decided to implement the drop-cutter algorithm as part of an ongoing software project. I found very interesting Anders Wallin website and his Opencamlib software. But the project I was working on was java-based.

Once I had a working implementation I realized that while most of the output made sense, there were a few odds points that were clearly wrong.

In a nutshell, the idea of drop-cutter algorithm is that it works by simulating a tool is being dropped till it touches the 3D model whose tool-path we are trying to obtain.  Using such a tool-path on a CNC machine equipped with the same tool, will render a geometrically accurate copy of the model.

The algorithm checks, for each XY tool location, which is the highest Z-axis value that causes a contact point between the tool tip and the object's 3D model. We use a triangular mesh for our models (STL files).  Three types of checks are performed:

  1. Whether the tool tip touches a triangle's vertex.
  2. Whether the tool tip touches a triangle's edge.
  3. Whether the tool tip touches a triangle's facet.
The contact point closer to the top (zmax) is selected for each XY coordinate tested. 




If we represent the obtained 3d coordinates of these points graphically, we should see that tool tip is never penetrating model mesh but would stay tangent to it.

So once you get your data and some of the points seem to be too-low you wonder what may be wrong. If your calculations are right most of the time, is it some rounding error or what?

After banging my head against the wall for a little while, I realized some of the ideas of my implementation were wrong.

Facet test

To determine the contact point of a tool with a triangle I determine the contact point between the plane the triangle is on and the tool axis. If there is not contact we can ignore that triangle safely. If there is a contact, then,  depending of the geometry of the tool tip, calculate the tool height that corresponds to that contact. Now project that tool coordinate back to the triangle, using the triangle normal inverted, is the tool-triangle contact point inside the triangle? If not ignore the calculated tool height.

Unfortunately I discovered that at times the contact point is outside of the triangle face but for a short margin, due to face-to-tool-axis orientation, and if the point is ignored then the tool path produced will severe that triangle with the tool.  The solution I am using so far is to relay a bit the last check while I figure out a more rigorous check.

Edge test

I am not entirely happy with the way I do the edge test. The basic idea is that I calculate the minimum distance from the edge to the tool axis on a top 2d projection. If the distance is larger than tool radius then there is not contact, but if lower then there is contact. What I reckon is incorrect is to assume the contact point matches the vertical of the perpendicular distance on the 2d top projection.

Update:

I was lucky my friend Rafa was attacking the same problem with a more thorough view, which led him to a better solution that made me aware of what I was doing wrong. What happened was that my edge test was poor. More than a proper test it was a wild hack. It is true that for an edge to be touching the tool it has to be within the vertical projection of it, but that is only a necessary condition. Because my edge test was failing sometimes, I looked toward the facet test as the one to blame but I was wrong, facet test was ok, but with my hack I was making the facet test to detect some of the edges the edge test was failing to catch.

Long story short, we are looking for the tangent point of the edge and tool tip. If we model both as 3d equations we look for the solution that is unique (tangent) as opposed to these others that present two solutions (secant). Things get a bit messy but solvable. Once edge test is done properly I can safely remove my hack from the facet test and it is all good.