The wiki is really comprehensive: https://en.wikipedia.org/wiki/Velocity_made_good
The way you train to this for hydrofoil racing is to have a good GPS watch that allows you to "mark" an upwind mark and a downwind mark, then you sail various speeds to calculate best VMG. For example:
Upwind you're looking at your watch and notice you're going 18 knots. You foot off a little to go faster until you're running around 21 knots. Even though you're not pointing as high, you might have just increased VMG because your speed through the water allows you to reach the laylines faster and therefore reach the top mark before someone who was going 17 knots but pointing a lot higher.
Conversely, you might be going upwind at 23 knots and then after the session calculate that your VMG actually decreased because you footed off too far and weren't pointing enough to optimize VMG.
Once you do some practice runs at various speeds/angles and run the VMG calculations for that foil and kite (and believe me, it's going to work out differently for EVERY kite) you'll essentially have a "target speed" that you'll try to hit on each leg. So if your target speed based on your VMG calculations is 22 knots and you're only going 20, you know you should either foot off a bit to build speed OR tack because you're in a header and you're already footed way off but still too slow.
Without a good GPS watch that can place a mark upwind and downwind and then run lap times around the course as you collect data logs, you're not going to be able to sail to VMG.
I've personally not done these calculations but I know a few guys are working on Apps for Garmin and Fenix watches that will do this specifically with hydrofoil racing in mind.