CNC Lathe trigonometry

Hi there,

I've made a cnc lathe and so far its all working out great. I'm currently working on adding a few new features to make it function like a manual lathe.

  • The current feature I'm working on is a 'virtual' compound slide. Basically moving the tool at a desired angle to the axis of the lathe.

  • This move is an interpolated move because its moving the X and Z axes simultaneously.

  • The lathe has two handwheels similar to a manual lathe, just with mpgs. I will use one of these to do the compound move.

The way I'm doing it now is to take the input from the handwheel (int. counter) "PosX" to directly drive the X axis and then the Z axis is calculated from there.

stepperZ.moveTo(posX * tan(angle) + posZ);

This works great up to 45° - exactly how you would expect. After 45° the Z axis needs to move more than the X axis to make the steeper angle. But because the X axis is the "driver" it becomes very unstable the close you get to 90° as one turn of the handle is a massive Z move.

I've tried dividing the PosX input by the angle to kind of slow it down the more the angle increases but it was just a hack that wasn't optimal.

What would be better is to somehow drive both axis along the hypotenuse using the input as distance along the path, independent of the axes. So whatever the angle, the handle moves the tool at the same speed.

This is probably a simple trig problem but I just cant get my head around it. I have however managed to do the same thing for circles, punch in a diameter and the tool cuts perfect radii. But this one is beyond me.

Any thoughts how I should better approach this?


It seems to me that you want to do a logarithmic cut instead of a linear cut, am I correct?
If so I suggest watching this video to get a better idea, it may help. It's a bit lenghty though.


Are you aware you are re-inventing the wheel? This has been done countless times over the last 15 years or more, even on Arduinos. Google "electronic lathe leadscrew". There is even an excellent, inexpensive kit you can buy that does about a million other functions as well: Electronic Lead Screw Main Page

Ray L.

Hi, thanks for the replies and links.

Yes, I am aware this has been done before, but for me its a learning project. For the time and money I have in this project I could have easily bought a cnc lathe and been finished with it. But that's not the point here.

I have a trigonometry problem that I would like to solve:

  • for a given angle and distance from origin, what are the x,y coordinates along the vector.

just writing this has given me a few ideas.

any input appreciated


that’s all?

google polar to rectangular conversion


thank you, just the answer I was looking for!

A simple change to the code but a massive improvement.

stepperX.moveTo(posX * (cos(angle)));
stepperZ.moveTo(posX * (sin(angle))+ posZ);


I didn’t answer earlier. I thought you were trying to solve a problem with “manual pulse generator” input, where a steep angle would mean less than one turn on X would shoot up on that vector with insufficient ability to finely control the motion.

Still may be your (a) problem, but seems easy enough to work out somehow.


Yeah that was the problem. Or the problem was I was driving the z axis with the x axis! So like you said, the steeper the angle the harder it was to control.

Now the function uses the "radius" or length of the vector to drive both axes. Which means it doesn't matter how close I get to 90° or 0° the resulting tool movement is always the same.

This still uses a MPG to drive it but its super stable.