Connecting the origin with two adjacent vertices of the octagon you obtain an isosceles triangle, and halving that a right triangle. The remaining angles of the latter are $45^\circ$ and $22.5^\circ$. Using the formulas from here you should be able to compute the hypotenuse. Verify the normalization used by your $g$.
The problem can also be solved using "euclidean analytic geometry" in the following way: Consider two rays through the origin with slopes $\pm22.5^\circ$. These represent two subsequent spikes of your octagon. Now determine the circle with center $(a,0)$ and radius $r>0$ which intersects the two lines at an angle of $45^\circ$ and the unit circle orthogonally. The points of intersection with the two lines are vertices of your octagon.