Attached is a scan of some old notes, not code. It's pretty straightforward to code once you do the trigonometry (that's what's in these notes).
All Billy's caveats apply to my method, too.
The trickiest part of a calculation like this is deciding what you mean by "coast": Is it the wind at the beach? Or 25, 50, 100km offshore?
That has implications for how complicated your "coastline" is, but more importantly the wind is almost always stronger further offshore, so the result depends very much on this choice. This is further complicated by how the wind product was calculated and how that processing treated the nearshore region.
The scale of coast you choose will therefore have large implications for the result.
I guess the first question you want to ask is: Is a straight line good enough as an approximation to your coastline? If your answer is yes, then determine a straight line that best approximates your coastline and then you know the angle θ, which is a single number for the entire calculation.
Ryo