How to make an Image trace a line?

I’m working on a class project, part of which is showing the position of a train on a train track. I’ve done pixel-perfect detection before but only as a floor like object (for platformers). I can’t figure out how to apply that to a circle that an image needs to follow. Google doesn’t seem to understand what I’m asking haha. If anyone can give me some advice, or a link to a site that explains this it would be much appreciated! Thanks in advance!

Calculate the begin/end of the train, use Math.atan2(dy,dx) to calculate the angle, pass the info to your Graphics2D instance: translate & rotate