Gcode, going to a point but not all the way?

An interrogation came up while I was writing a small file to draw a squareness check pattern.
Bed is 910mmx510mm, I only want to draw the corners of the square on some post-it taped on the bed.
G0 X0 Y0
G0 Z-1
G0 X0 Y15
G0 X15 Y0
G0 X0 Y0
G0 X15 Y15
And so on for the other 3… Diagonals are 45°… it doesn’t matter at all but it made me wonder if there’s a way to ask to go to a point (x0,Y0 to X910,Y510) but only for a definite distance (let say 15mm) or if the only solution is to ask Pythagoras ?

Did not find the answer to this not really usefull question, :slight_smile:

I’m not aware of anything in the g-code language understood by Marlin that would help you with this problem. There is no “scale” command, or “heading” command, or any ability to transform the coordinate system beyond offsetting the origin using in Workspaces. But you don’t need Pythagorean theorem for what I think you are trying to do.

First, note that while your g-code draws a 45-degree line, the diagonal between the points (0,0) and (910,510) is not 45 degrees. A ratio can be used to travel this line. Divide the Y height (510) by the X width (910) and get 0.5604. Now pick an arbitrary X travel distance, say 15.0. Your Y coordinate would be 15 * 0.5604 = 8.407, so your point in the g-code is (15, 8.407). Or if you want to make sure you travel at least 15.0 on the Y, you use the inverse ratio: 910/510 = 1.784, so your X would be 15*1.784 = 26.76, so you would use (26.76, 15) as the point in your g-code.

Edit to add: I’m not sure this simplifies your problem, but Marlin’s g-code has both absolute and relative coordinates (G90,G91). So you can move in absolute coordinates to say 910,510, then use relative coordinates to move to 0,-15 to start drawing the corner.

Hello Eric,
I assume that when you say…

You actually mean…

If that is so then the easiest way to do what you are asking is to use Relative Positioning. Meaning all move commands will be “Relative” to the last known position instead of relative to home/the Origin.

So you could do this…

G28 ;Home All

G0 X0 Y0 ;Go to 0,0
G91 ;Use Relative positioning
;Draw a 15 mm box
G0 X15 Y15 ; Top right corner to start
G0 X0 Y-15 ;lower Right corver
G0 X-15 Y0 ;lower left corner
G0 X0 Y15 ;upper left corner
G0 X15 Y0 ; back to upper right corner
G0 X-15 Y-15 ;Return to 0,0

G90 ;Back to absolute Positioning

Ratio is a good idea, you are right and yes, I’m aware of G90 and G91 but so far I did not realize when this could be usefull… now I know.
as I was entering the code directly, it would have been easier to enter relative values.

Aaryn, bed size is really 910x510

But you bring another good point, I choose to draw only the corner (no special reason) while drawing a square make it easier to duplicate if combined with relative