ship_dir =point_on_heading-ship_pos(ition) //vector ship is heading in
mouse_dir=mouse_pos-ship_pos // vector from ship to mouse position
You can find the angle between these two vectors;
ship_dir.Normalize(); //divide by length
mouse_dir.Normalize();//divide by length
dot_prod=DotProduct(ship_dir,mouse_dir);
angle=acos(dot_prod); //cos-1, this will give angle between two vectors
BUT that doesn't tell you which way to turn (left or right)(positive or negative)(clockwise or anti-clockwise).
You also need to consider the normal to the mouse_dir. The dot product between two vectors is positive if the angle is less than 90deg.
mouse_normal=(-mouse_dir.y,mouse_dir.x);
dot_prod=DotProduct(ship_dir,mouse_normal);
if(dot_prod>0) //+ive value means the angle is <90deg therefore, ship_dir is on 'left'side of mouse dir, so clockwise is shortest route
rotate clockwise;
else
rotate anti_clockwise;