0

I am new to python and I'm trying to generate a g-code using python. I'm using sympy because I also need to do segments, intersections, and even convex hull.

Given an initial point(s) I need to rotate it(them) +/- 120 degrees from the center (0,0), and my end result should be something like this:

"G0 X0 Y120.4"

I turn evaluate=False to get actual points, but the way I am doing it only works for the initial one and not for the others:

G0 X0 Y120.400000000000

G0 X-301*sqrt(3)/5 Y-301/5

How do I make the other points in the form of the initial Z point?

from sympy import Point, pi
z = Point(0, 120.4, evaluate = False)
x = z.rotate(pi*2/3)
y = z.rotate(-pi*2/3)

print('G0 X{0} Y{1}'.format(z.x,z.y))
print('G0 X{0} Y{1}'.format(x.x,x.y))

1 Answers1

1

Try evaluate the coordinates before or during printing:

>>> Point(0, 120.4) # with evaluate=True, the Float is made Rational
Point(0, 602/5)
>>> _.n()  # evaluate the coordinates
Point(0, 120.400000000000)
>>> print('G0 X{0} Y{1}'.format(x.x.n(),x.y.n()))  # from your example
G0 X-104.269458615646 Y-60.2000000000000
smichr
  • 16,948
  • 2
  • 27
  • 34