I'm building a visualisation where I have a body that is moving along-a-path, which is comprised of multiple segments, each with an arbitrary angle.
The body is moving along the path and:
- When the body's centre reaches the end of each segment it stops.
- It then rotates around it's centre to align itself with the next segment .
- It starts moving again along the next segment.
I can get this working just fine when the rotation point is the body's centre.
Here's an animation of the body rotating by it's centre (blue dot):
However now I'd like to rotate the body from a pivot point.
How can I calculate the distance I should cover in each segment before I stop and start turning around my pivot, so when the rotation ends my body's centre lies exactly in the centre of the next segment?
In short, when the body is moving it's centre must always lie on the segment line it moves on.
Here's an animation of the body rotating by it's pivot point (red dots):
In the above example the body overshoots the position on each segment where it should stop and start rotating, thus when it starts moving again - it's centre doesn't lie on the path.
FWIW I've got some code for this working in a browser sandbox, available here