Parabola in G code

The following Python script produces a parabola in G-code.

#This code produces g-code for a parabola using the equation
#(y - k)2 = 4a(x - h). The parabola is open to positive x.
#a = x coor of focus
#k = x coor of back of parabola
#h = y coor of focus
#r = resolution
#ymax, ymax = limits of iteration
a = 2.0
k = 0.0
h = 0.0
ymax = 5.0
ymin = 0.0
resolution = 0.1
lastx = 0.0
lasty = h
def frange3(start, end=None, inc=None):
"""
A range function, that accepts float increments...
http://code.activestate.com/recipes/66472/
"""
import math

if end == None:
end = start + 0.0
start = 0.0
else: start += 0.0 # force it to be a float

if inc == None:
inc = 1.0
count = int(math.ceil((end - start) / inc))

L = [None,] * count

L[0] = start
for i in xrange(1,count):
L[i] = L[i-1] + inc
return L

#top half
for ystep in frange3(ymax+resolution,ymin,-resolution):
x = ( ((ystep - k)*(ystep - k)) + 4*a*h ) / (4*a)
print "G01 X"+str(x) +" Y"+str(ystep)#+"\n"
print "G01 X"+str(lastx) +" Y"+str(lasty)#+"\n"
#bottom half
for ystep in frange3(ymin,-(ymax+resolution),-resolution):
x = ( ((ystep - k)*(ystep - k)) + 4*a*h ) / (4*a)
print "G01 X"+str(x) +" Y"+str(ystep)#+"\n"

Comments

Anonymous said…
Thanks, I couldn't find this code online anywhere else!

Popular posts from this blog

DIY CNC Milling Machine Control Panel for EMC2

Power Supply for CNC

Maintenance of a 30 Year Old CNC Milling Machine