Click to start a polyline at a point; shift + click to continue from that point. Press Z to remove the last point, and press enter to complete the polygon. Space will clear everything.

Middle click (or ctrl/command + click) to set the anchor position.

Key

Grey lines
The polyline
Red point
Anchor/starting point of ray
Blue line
Direction of ray
Cyan point
First intersection of ray and polyline
Yellow point
Mouse position
Orange point
Closest point on polyline to the mouse