# Mathematical transformation of a heading angle to a roll angle

I'm trying to understand a function in a SIMULINK example of a path following UAV simulation. The gist is that, the UAV Waypoint Follower block provides a required heading from a list of waypoints and this heading is converted, by the heading control block, into a Target Roll that is used by the autopilot. The heading control block is the following function: This function in the absence of wind evaluates to:

$$\phi = \text{atan2}(p(\psi_d - \psi)V,g)$$ meaning, where, $$\phi$$ is the target roll, $$V$$ is the current speed, $$\psi$$ is current heading, $$\psi_d$$ is the desired heading and $$p$$ is the proportional gain "PHeadingAngle".

I'm struggling to understand how that equation works mathematically, and how it transforms a heading to a roll angle.

If possible, I'd also like an explanation for how the function deals with wind. I know that it transforms the heading angle and the speed using the wind speeds but am unsure how that transformation works.