printfn "Ptolemy's construction of a pentagon"
printfn "Draw a regular pentagon inside the circle"
let O = Point3d(0.0, 0.0, 0.0)
let circle = Circle3d(O, 1.0, Vector3d(0.0, 0.0, 1.0))
let C = circle.ParametricForm(0.0)
let CD = l.IntersectionWith circle |> unbox<Segment3d>
let D = if CD.P1 = C then CD.P2 else CD.P1
let circle1 = Circle3d(C, CD.Length, circle.Normal)
let circle2 = Circle3d(D, CD.Length, circle.Normal)
let line = (circle1.IntersectionWith circle2 |> unbox<Segment3d>).ToLine
let AB = line.IntersectionWith circle |> unbox<Segment3d>
let radius = M.DistanceTo C
let tmp_circle0 = Circle3d(M, radius, circle.Normal)
let ON = tmp_circle0.IntersectionWith AB |> unbox<Segment3d>
let N = if ON.P1 = O then ON.P2 else ON.P1
let side_len = C.DistanceTo N
let tmp_circle1 = Circle3d(C, side_len, circle.Normal)
let tmp_segment = tmp_circle1.IntersectionWith circle |> unbox<Segment3d>
let tmp_circle2 = Circle3d(P2, side_len, circle.Normal)
let tmp_segment2 = tmp_circle2.IntersectionWith circle |> unbox<Segment3d>
let P3 = if tmp_segment2.P1 = P1 then tmp_segment2.P2 else tmp_segment2.P1
let tmp_circle3 = Circle3d(P3, side_len, circle.Normal);
let tmp_segment3 = tmp_circle3.IntersectionWith circle |> unbox<Segment3d>
let P4 = if tmp_segment3.P1 = P2 then tmp_segment3.P2 else tmp_segment3.P1
let angle1 = Vector3d(P1, P2).AngleToDeg(Vector3d(P1, P5))
let angle2 = Vector3d(P2, P1).AngleToDeg(Vector3d(P2, P3))
let angle3 = Vector3d(P3, P2).AngleToDeg(Vector3d(P3, P4))
let angle4 = Vector3d(P4, P3).AngleToDeg(Vector3d(P4, P5))
let angle5 = Vector3d(P5, P4).AngleToDeg(Vector3d(P5, P1))
if Math.Abs(angle1 - 108.0) < tolerance &&
Math.Abs(angle2 - 108.0) < tolerance &&
Math.Abs(angle3 - 108.0) < tolerance &&
Math.Abs(angle4 - 108.0) < tolerance &&
Math.Abs(angle5 - 108.0) < tolerance then
printfn "Your construction is correct!"