Sunday, February 12, 2012

Area Strategy

I've started rewiring things in preparation for the new control panel board. I don't want to do too much because I'll eventually get to the point where I disable the mill and as soon as I do that, I'll need it to make something. I'd like to test the new board before disabling the mill, and even then I'll do it in such a way that it won't be terribly difficult to restore the current circuitry if the new board has a major problem.

I pulled the limit switches off and rewired them with the new shielded cable I got to fix the noise problems. I need a junction box to connect all the wires in. I have a huge chunk of RenShape from which I thought I'd make the box. The box design is very simple, 2" x 2 1/4" x 1/2" with a large pocket and a few holes coming in from the sides to insert the wires into.

Now I could write a routine to do a rectangular pocket easy enough, even a circular pocket. If you've ever done any Turtle Graphics programming you can see how I'd do it. But eventually I'm going to need to mill pockets in arbitrary shapes. A spiral cutting pattern from inside to out makes for a pretty efficient strategy. To do this I need to create a series polygons inset within the shape. This sort of thing has been done many times by others and there is no need for me to do it again. I spent most of the afternoon looking for a Java library for 2D geometry. The Toxiclibs library I'm doing the 3D work with has 2D functions but I couldn't find an inset (also known as a buffer).

I found the JTS Topology Suite. I imagine JTS stands for Java Topology Suite which means the full name is Java Topology Suite Topology Suite. I suppose it's like saying you are going to get money from the ATM machine. Anyway, I found it fairly easy to get started with the offsets I needed:


The blue line is the area to be machined. I've drawn a line on top of the blue one by creating an outset from the first inset. This gives the rounded corners and helps visualize the area that will actually be cut by the mill. The yellow circle represents the cutting head. I generated insets of a fixed distance until the last inset no longer fully encloses the mill cutter.

It should be easy enough to connect these insets in a spiral shape. I think I'll start with a spiral circle twice the size of the cutting head and plunge into it.

This will give me a generic spiral area function with broad applications. 

[Update #1]

I converted the insets into a spiral path. This wasn't as easy at is seemed because the relative start points of each inset were not aligned. So long as the next inset had the same number of points as the previous inset it was fine, but when the next inset drops a point (from 4 to three in this case) the start point "changed position" and messed up the continuity of the spiral. So I wrote a function to "align" the start points. This turned out to be pretty easy because JTS provides a tool to find the closest points between 2 objects. So the start point of the outer inset was compared to the inner inset to get the closest point. Then I just shifted the points in the sequence by the index of the closest point. Then I connected all the points from inside to outside:




No comments:

Post a Comment