# Thread: Scripting a constant offset curve over a contoured surface?

1. ## Scripting a constant offset curve over a contoured surface?

Hi,
I'm looking at trying to write a script to generate 5 axis toolpaths in rhino. The area where I'm having trouble is working out how to acheive a constant offset from the outer edge of the surface as a toolpath. I have looked at using the edge curve as a rail and extruding a circle along the curve to form a tube, the next line would be created by using the intersection of the tube and the surface but this dosen't work too well because loops and irregularities can occour in sharp corners. Can anyone suggest how to draw the lines to form a 5 axis toolpath which covers the entire surface?

Thanks
Splint

2. Would offsetting the surface and generating curves from isocurves (on the new surface) work? Seems like you would have to project curves onto whatever you do in order to have a parallel toolpath curves. Sounds like a neat project your into...

3. I'd doubt it would work, it's the sort of thing that needs to have the lines an equal distance (step over of the tool) from the previous pass over all types of shapes and contours. It would start from the outer edge of the surface and then make another line a predetermined distance inward of that line, repeating until the entire surface is covered, then the line is midified to allow the tool move from one pass to the next. Once that is established x,y,z and normal to surface measurements are converted into g-code.
I suspect it may involve a sphere "rolling" around the inside of the line, using the centre of the sphere to draw a curve as it goes. I'm just not clear on how this could be done in rhino. I dont think projecting lines or anything of that nature is the way to do it.

Cheers
Splint

4. I am suggesting that once you offset all of your surfaces, an array of curves could be created, with the desired stepover, and then projected to the offset surfaces. This would give you the effect of the rolling ball, with the curve created at the center of it. Definately a workaround for what could easily be accomplished with 20,000 dollar software.

Your script keeps the toolpath normal to the curve?

That sounds so cool.

• Hello Splint,

In the “Rhino to G-code” thread Dan B posted a snippet of his five axis script that does exactly what you are asking. He offsets the points on the tool path along the surface normal.

I have been playing around with a 5 axis script of my own. It is full of bugs and probably not useful but it does spit out numbers.

You have to project a curve (tool path) on to a surface then run the script and follow the prompts.

Colin

• Originally Posted by spoiledbrat

Your script keeps the toolpath normal to the curve?

That sounds so cool.
The reason for the normal to surface bit is so the g-code includes the B and C position of the tool as well as the X,Y and Z so it is true 5 axis, otherwise the tool would remain in the virtical position and be 3 axis.
Here is a video of the sort of thing I would like to be able to do.

<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/kJl4WgOxzW4"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/kJl4WgOxzW4" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

At this point in time my main issue is getting the consistent step over on a contoured surface, the surface itself that is, not a consistent step over tool path which is then projected onto a surface as the step over changes with the contour of the surface when projected.
On the rhino screen shot I used the contour command which effectively projects a series of lines down onto the surface. In the Top and front views the step over is consistent but in the perspective and right views, the step over changes dramatically on the steep face, this is what I'm trying to sort out, how to get a consistent step over regardless of the shape or angle of the surface. From what I understand any method of projecting lines will result with variable step overs.

Here's a couple more images to help explain what I'm trying to achieve, the pink toolpath would be fine for a 3 axis machine but not for a 5 axis. The green toolpath is a better example of what I would like. When I talk about the rolling ball, what I'm trying to say is that the center of the ball stays at the surface at all times and the outer edge of the surface acts as a border which the ball rolls on. When the ball has done a full lap it moves inboard and uses the newly created line as the border and starts drawing the next line.

Thanks Colin for the tip in Dan Bs script, I have seen that thread but I cant understand exactly how the snipit of script works. I tried out your script but couldn't produce any code, apart from that it looked to be working normally.

Thanks again
Splint

• Ok, the embeded video didn't work, here's a link.

• Could you post some sample models/scripts.
I was thinking OffsetCrvOnSrf in V4 might work but it to makes loops and irregularities (it must be using the intersection of the tube also).

• I dont have any scripts at this point, I'm just trying to work out the mechanics of how to do it, when I have a plan I will work on creating the script.

I had a thaught on an alternative which isn't ideal but may be workable. Create a sphere double the size of the intended step over, move the sphere along the outer edge of the surface in small incriments (center of the sphere on the edge), trim the edge of the surface using the sphere as the cutting tool all the way around the surface until it gets back to the point where it started. Draw a curve or a polyline using object snaps along the new outer egde of the surface. Move the center of the sphere onto the new line and repeat the process over and over until there is no surface left to trim. Add in the lines to step from one path to the next, add in plunge and retract paths, specify the direction of travel (start from the inside for a pocket, start from the outside for an island) specify the reference distance along the lines to take xyzbc data and generate the code from there. Totally confused?

Cheers
Splint

• After playing with the sphere idea I think it may not be as simple as it first looked. Maybe going back to the disk stepping along the edge curves and creating a curve from intersecting surfaces may be the way to go. Perhaps scripting in a condition to ignore intersecting lines may be a way of dealing with the corners.
The picture below is a conceptual drawing of what may work. The red line is the toolpath, the blue disk is oriented to the curve and steps along using the object intersection command to create the reference lines on the part surface. The intersecting reference lines in the corner are ignored.
Alternately it may be possible to take into account the intersecting reference curves and script in a method of deleting the loop which would occour in corners, this may be of use when the tool path creation nears the point where it finishes and may start to loop over itself.

Splint

• Instead of a sphere or disk just use a circle to find where the intersection points are on the surface (_Intersect). Then use InterpCrvOnSrf at these points to get the tool path on the surface.
I have attached a picture to demonstrate what I mean.

What type of tool path are you going to be working on first, Zigzag or offsetting from the surface’s edge curve?

• The reason I'm thinking of a disk is because a line can be created using the object intersection command, the line could then be trimmed to the step over distance, in effect creating a true surface distance rather than a straight line distance from one path to the next. This may create better step over geometry, too complicated to worry about doing in the conceptual stage but worth considering later.
Zig zag or edge curve? I'm really not sure, I think zig zag may be slightly easier to deal with for a start but many of the issues which will arise will more than likely be common to both types of tool path.