Construct n-gons with a ruler and compass The task is to draw a regular polygon of n sides using only a compass and an unmarked ruler.

Input (n) is one of the following 10 numbers: 3, 4, 5, 6, 8, 10, 12, 15, 16, 17.

Method: Because you only have a ruler and compass you can only draw points, lines and circles.

A line can only be drawn:


through two existing points.


A circle can only be drawn:


with one point as its centre and with its perimeter passing through a second point.


A point can only be drawn:


at the intersection of two lines,
at the intersection(s) of a line and a circle,
at the intersection(s) of two circles,
at the outset, when you may draw 2 points to get started.


Through this process (and only through this process) you must draw the n lines of the requested n-gon, along with any working required to get to that stage.

EDIT: The position of intersections must be calculated, but lines and circles may be drawn by any means provided by the language.

Output is an image of an n-sided regular polygon, showing working.

Graphically there are no restrictions on image size, format, line thickness or anything else not mentioned here. However it must be possible to visually distinguish distinct lines, circles and their intersections. Additionally:


The n lines that make up your n-gon's sides must be a different colour to your 'working' (i.e. any points, circles or other lines) and a different colour again to your background.
Working can leave the borders of the drawing area, except points, which must all be within the visible bounds of the image.
A circle can be a full circle or just an arc (as long as it shows required intersections).
A line is infinite (i.e. leaves the drawing area) or cut off at the two points it goes through. EDIT: A line may be drawn at any length. Points can only be created where the drawn line visually intersects.
A point can be drawn as you wish, including not marking it.


Scoring is twofold, a submission gets 1 point per input it supports, for a maximum of 10 points. In the event of a draw, shortest byte count wins.

Recognition will be given to submissions that can construct n-gons in the fewest steps or are able to construct n-gons outside of the given range, but it won't help your score.

Background info from Wikipedia
Mathematica, 2 3 4 polygons, 759 bytes

S=Solve;n=Norm;A=Circle;L=Line;c={#,Norm[#-#2]}&amp;{a_,b_List}~p~{c_,d_List}:=a+l*b/.#&amp;@@S[a+l*b==c+m*d,{l,m}]{a_,b_List}~p~{c_,r_}:=a+l*b/.S[n[c-a-l*b]==r,l]{c_,r_}~p~{d_,q_}:={l,m}/.S[n[c-{l,m}]==r&amp;&amp;n[d-{l,m}]==q,{l,m}]q={0,0};r={1,0};a=q~c~r;b=r~c~q;Graphics@Switch[Input[],3,{s=#&amp;@@p[a,b];A@@@{a,b},Red,L@{q,r,s,q}},4,{k={q,r};{d,e}=a~p~b;j={d,e-d};d=k~p~j~c~q;{e,f}=j~p~d;A@@@{a,b,d},L/@Accumulate/@{k,j},Red,L@{q,e,r,f,q}},6,{d={q,r};e=#&amp;@@d~p~a;f=e~c~q;{g,h}=a~p~f;{i,j}=a~p~b;A@@@{a,b,f},L@{#-2#2,#+2#2}&amp;@@d,Red,L@{r,i,g,e,h,j,r}},8,{k={q,r};{d,e}=a~p~b;j={d,e-d};d=k~p~j~c~q;{e,f}=j~p~d;g=e~c~q;h=q~c~e;i=r~c~e;{o,s}=g~p~h;{t,u}=g~p~i;o={o,2s-2o};s={t,2u-2t};{t,u}=o~p~d;{v,w}=s~p~d;A@@@{a,b,d,g,h,i},L/@Accumulate/@{k,j,o,s},Red,L@{q,t,e,v,r,u,f,w,q}}]


Random bullet points:


Input is provided via prompt.
I'm currently supporting inputs 3, 4, 6, 8.
From your options, I chose the following plotting styles:


Full circles.
Lines from endpoint to endpoint, unless a relevant intersection lies outside, in which case I'll hardcode the extent.
No points.
Workings are black, polygons are red - not for aesthetic but for golfing reasons.

There's some serious code duplication between the polygons. I think at some point I'll just do a single construction for all of them, enumerating all lines and points and circles along the way, and then just reduce the Switch to select the relevant circles and lines for each construction. That way I could reuse a lot of primitives between them.
The code contains a lot of boilerplate functions which determine all the relevant intersections, and create circles from two points.
With that in place, I will be adding more polygons in the future.


Here is the ungolfed code:

S = Solve;
n = Norm;
A = Circle;
L = Line;
c = {#, Norm[# - #2]} &amp;
{a_, b_List}~p~{c_, d_List} := 
 a + l*b /. # &amp; @@ S[a + l*b == c + m*d, {l, m}]
{a_, b_List}~p~{c_, r_} := a + l*b /. S[n[c - a - l*b] == r, l]
{c_, r_}~p~{d_, q_} := {l, m} /. 
  S[n[c - {l, m}] == r &amp;&amp; n[d - {l, m}] == q, {l, m}]
q = {0, 0};
r = {1, 0};
a = q~c~r;
b = r~c~q;
Graphics@Switch[Input[],
  3,
  {
   s = # &amp; @@ p[a, b];
   A @@@ {a, b},
   Red,
   L@{q, r, s, q}
   },
  4,
  {
   k = {q, r};
   {d, e} = a~p~b;
   j = {d, e - d};
   d = k~p~j~c~q;
   {e, f} = j~p~d;
   A @@@ {a, b, d},
   L /@ Accumulate /@ {k, j},
   Red,
   L@{q, e, r, f, q}
   },
  6,
  {
   d = {q, r};
   e = # &amp; @@ d~p~a;
   f = e~c~q;
   {g, h} = a~p~f;
   {i, j} = a~p~b;
   A @@@ {a, b, f},
   L@{# - 2 #2, # + 2 #2} &amp; @@ d,
   Red,
   L@{r, i, g, e, h, j, r}
   },
  8,
  {
   k = {q, r};
   {d, e} = a~p~b;
   j = {d, e - d};
   d = k~p~j~c~q;
   {e, f} = j~p~d;
   g = e~c~q;
   h = q~c~e;
   i = r~c~e;
   {o, s} = g~p~h;
   {t, u} = g~p~i;
   o = {o, 2 s - 2 o};
   s = {t, 2 u - 2 t};
   {t, u} = o~p~d;
   {v, w} = s~p~d;
   A @@@ {a, b, d, g, h, i},
   L /@ Accumulate /@ {k, j, o, s},
   Red,
   L@{q, t, e, v, r, u, f, w, q}
   }
  ]


And here are the outputs: