Every rainbow is a circle, and you are standing on the line through its middle. The middle is the shadow of your head: the point straight opposite the sun, which is behind you. The red light comes to you from raindrops 42° away from that point, all the way round.
The source code is at github.com/KirillOsenkov/LiveGeometry. It is written in .NET and Avalonia.