For a more complex but fully documented example that might even cover your use case this might be of interest:
forum.linuxcnc.org/show-your-stuff/49103...-head?start=0#271334
The two kinematic models presented in the zip folder attached to the above post can do a fair bit more than what you need but together with the documentation it will give you an in depth introduction on how to build your own kinematic components.