At some point, you might want to attach a rifle to your top-down hero.
And, you might want to shoot it.

My game involves a crosshair that determines the player body's rotation around its origin.
The body's origin is the center of the character's head O.

In other words, the player's head always looks at the crosshair.

The body may have several fixtures which necessarily rotate therewith, for example a gun attached to the primary hand.
As such, the crosshair is used to properly direct every gunshot.

Now, everything's all and well if the rifle's center, the rifle's muzzle and your player's head center are all colinear.
I assume here that each launched bullet follows the ray from the rifle's center to the rifle's muzzle.

In other words, you're fine if you position your gun like this:

So if your head looks at the crosshair, so does the rifle and its muzzle.
But we're not always this lucky, especially if you're after gangsta-pistol layout:

It becomes obvious that if the gun is to look exactly at crosshair, your character's eyes certainly cannot so.
They need to be directed somewhere a little bit different,
in the picture above for example, you'd need to tilt the whole character's body a tiny bit counter-clockwise.

Let us express the problem in mathematical terms - given are points:
O (head), A (rifle center), B (muzzle), C (crosshair).
Let us define a circle whose center is at O and whose radius is OB.
These conditions follow:
1. A lies inside the circle.
2. C lies outside the circle.

Notice that B lies on the circle.

The question becomes:
By what angle should we rotate (around the center of rotation O) points A and B in order to make A, B and C colinear?

Well, I'm not particularly good at geometry but fortunately, Marcel, a friend of mine, came to the rescue!
It took him no more than 15 minutes of scribbling with his compass to come up with a solution:

1. Consider a circle Y whose center is at O and whose radius is OC.
2. Let G be the point of intersection of Y and a ray BA.
3. The angle we're looking for is twice the angle CGA.

Without really trying to validate his mysterious recommendation, I went on to code the damn thing.
And guess what, it works flawlessly!
This is how these hardcore calculations look like in debug drawing mode:

Input A, B and properly rotated A, B
line going through the points A, B, C
angle CGA

And here's what happens if you rotate the player around his head by twice the angle CGA:

Very well. So, from now on, you can shoot your gun with pinpoint accuracy.
I've already got a working recoil prototype, so the bullet is not exactly on the muzzle-crosshair line due to crosshair's displacement after the shot.

Below you can see the code for the angle calculating function.

float colinearize_AB_with_C(vec2 O_center_of_rotation, vec2 A_rifle_center, vec2 B_muzzle, vec2 C_crosshair) {
	auto crosshair_vector = C_crosshair - O_center_of_rotation;
	auto muzzle_vector = B_muzzle - O_center_of_rotation;
	if (crosshair_vector.is_epsilon(1.f))
		crosshair_vector.set(1, 0);

	if (crosshair_vector.length() < muzzle_vector.length() + 1.f)
		crosshair_vector.set_length(muzzle_vector.length() + 1.f);
	C_crosshair = O_center_of_rotation + crosshair_vector;

	auto oc_radius = crosshair_vector.length();
	auto intersection = circle_ray_intersection(B_muzzle, A_rifle_center, O_center_of_rotation, oc_radius);
	auto has_intersection = intersection.first;

	auto G = intersection.second;
	auto CG = C_crosshair - G;
	auto AG = A_rifle_center - G;

	auto final_angle = 2 * CG.angle_between(AG);
		auto& ln = augs::renderer::get_current().logic_lines;

		ln.draw_cyan(O_center_of_rotation, C_crosshair);
		ln.draw_red(O_center_of_rotation, A_rifle_center);
		ln.draw_red(O_center_of_rotation, B_muzzle);
		ln.draw_yellow(O_center_of_rotation, G);
		ln.draw_green(G, A_rifle_center);
		ln.draw_green(G, C_crosshair);

		A_rifle_center.rotate(final_angle, O_center_of_rotation);
		B_muzzle.rotate(final_angle, O_center_of_rotation);

		ln.draw_red(O_center_of_rotation, A_rifle_center);
		ln.draw_red(O_center_of_rotation, B_muzzle);

		ln.draw(A_rifle_center - (B_muzzle - A_rifle_center) * 100, B_muzzle + (B_muzzle - A_rifle_center)*100);

	return final_angle;