The user clicks a unit to select it for a move. Its going to move to wherever they click next.
It's centre c is point cf They then click a point it is to move to. This is to be where the unit centre moves to ct.
It is simple to work out the bearing between f and t and I know how to work out the delta. What I would like to simulate is a unit wheeling. Think in terms of a napoleonic battalion of a thousand men in 2 or 3 lines. They don't just spin to face the new place they will move to. Turning is handled by wheeling. The unit rotates around the nearest corner until it faces in the direction of ct giving a rotated point rcf and then moves in a straight line finishing with a facing based on the bearing between rcf and ct.
I need to somehow calculate that wheel to get rcf.
My question is: how do I do that?
My first thought was calculate the delta offset from the unit facing and then rotate cf in relation to the nearest corner.
That cannot be right though.
If the unit starts facing directly north and you click west then that delta would be 90 degrees. If you rotate the unit by the left corner by 90 degrees the facing would be out though. The left corner would end up where I want the centre to be.
This is rather like the user is dragging a rectangle projected from the front of the unit around. It rotates around either corner of the unit ending up with it's centre wherever the user clicks.
I'm not using any gaming engine so I'll be writing any c# to do the trig.
Edit.
I don't think my drawing skills are really up to this but I'll see what I can come up with.
The unit must rotate around one corner such that it would move directly forward and end up with it's centre where the user clicks.
One way to work this out would be to calculate the rotated point degree by degree of rotation. Then project out at 90 degrees and see if that hits the required point.
If you imagine opening a door.
There's a stick attached to the centre.
A spot on the floor represents where the unit moves to.
As you open the door the stick moves and will eventually come to that point.
Here's an attempt at a drawing.
Bear in mind units can ( could ) only move straight forward but they can also wheel.
The unit starts off in blue position.
The user clicks at a point where the red arrow head is.
This is not on that blue line which projects at 90 degrees to it's centre which is it's original facing (or bearing).
That means it must wheel.
The delta is to the left so it's going to wheel (hinge) around the left corner.
Those guys on the left of the unit stay where they are. Those on the far end do the most movement.
When a line projected from it's centre crosses that point it needs to go to then it's got the right rotation.
This is represented by the red line.
So the unit starts it's move by wheeling from blue to red state.
That point it wants to get to is now straight ahead of it's centre.
So it can then move straight forward to it.
The dotted line is to exaggerate the fact I'm looking to somehow calculate where that central point has to be after it's wheeled and is ready to move directly forward.
Any ideas?