.NET Fiddle

CSharp · Console

/Program.cs

using GeometRi;
using System;


public class Program
{
    public static void Main()
    {

        Console.WriteLine("Mascheroni Construction of a Regular Pentagon");
        Console.WriteLine();

        // We will follow the notation from 
        // https://www.cut-the-knot.org/pythagoras/MascheroniPentagon.shtml
        // Read this article for detailed description of the algorithm

        // Start with arbitrary points A and B (in plane XY)
        Point3d A = new Point3d(0, 0, 0);
        Point3d B = new Point3d(5, 0, 0);

        // Draw a circle C1 with center in point A through point B
        Circle3d C1 = new Circle3d(A, A.DistanceTo(B), new Vector3d(0, 0, 1));

        // Draw a circle C2 with center in point B through point A
        Circle3d C2 = new Circle3d(B, A.DistanceTo(B), new Vector3d(0, 0, 1));

        // Intersection of C1 and C2 gives points C and D
        Segment3d segment = (Segment3d)C1.IntersectionWith(C2);
        Point3d C = segment.P1;
        Point3d D = segment.P2;

        // Draw a circle C3 with center in point C through point D
        Circle3d C3 = new Circle3d(C, C.DistanceTo(D), new Vector3d(0, 0, 1));

        // Intersection of C3 and C1 gives point E
        segment = (Segment3d)C3.IntersectionWith(C1);
        Point3d E = segment.P1;
        // if E == D, choose another point of intersection
        if (E == D)
        {
            E = segment.P2;
        }

        // Intersection of C3 and C2 gives point F
        segment = (Segment3d)C3.IntersectionWith(C2);
        Point3d F = segment.P1;
        // if F == D, choose another point of intersection
        if (F == D)
        {
            F = segment.P2;
        }

        // Draw a circle C4 with center in point A through point F
        Circle3d C4 = new Circle3d(A, A.DistanceTo(F), new Vector3d(0, 0, 1));

        // Draw a circle C5 with center in point B through point E
        Circle3d C5 = new Circle3d(B, B.DistanceTo(E), new Vector3d(0, 0, 1));

        // Intersection of C4 and C5 gives points G and H
        segment = (Segment3d)C4.IntersectionWith(C5);
        // point G is closer to point D
        Point3d G = new Point3d();
        Point3d H = new Point3d();
        if (segment.P1.DistanceTo(D) < segment.P2.DistanceTo(D))
        {
            G = segment.P1;
            H = segment.P2;
        }
        else
        {
            H = segment.P1;
            G = segment.P2;
        }

        // Draw a circle C6 with center in point G through point C
        Circle3d C6 = new Circle3d(G, G.DistanceTo(C), new Vector3d(0, 0, 1));

        // Intersection of C6 and C3 gives points I and J
        // we need to choose correct side for I and J
        segment = (Segment3d)C6.IntersectionWith(C3);
        Point3d I = new Point3d();
        Point3d J = new Point3d();
        if (segment.P1.DistanceTo(A) < segment.P1.DistanceTo(B))
        {
            I = segment.P1;
            J = segment.P2;
        }
        else
        {
            J = segment.P1;
            I = segment.P2;
        }


        // Draw a circle C7 with center in point H through point C
        Circle3d C7 = new Circle3d(H, H.DistanceTo(C), new Vector3d(0, 0, 1));

        // Intersection of C7 and C3 gives points K and L
        segment = (Segment3d)C7.IntersectionWith(C3);
        Point3d K = new Point3d();
        Point3d L = new Point3d();
        if (segment.P1.DistanceTo(I) < segment.P1.DistanceTo(J))
        {
            K = segment.P1;
            L = segment.P2;
        }
        else
        {
            L = segment.P1;
            K = segment.P2;
        }


        // Points DIKLJ define our pentagon
        // Let's check if interion angles are equal 108 degrees (with accuracy 1e-8)
        double angle1 = new Vector3d(D, I).AngleToDeg(new Vector3d(D, J));
        double angle2 = new Vector3d(I, D).AngleToDeg(new Vector3d(I, K));
        double angle3 = new Vector3d(K, I).AngleToDeg(new Vector3d(K, L));
        double angle4 = new Vector3d(L, K).AngleToDeg(new Vector3d(L, J));
        double angle5 = new Vector3d(J, L).AngleToDeg(new Vector3d(J, D));

        double tolerance = 1e-8;
        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)
        {
            Console.WriteLine("Your construction is correct!");
            Console.WriteLine(D.ToString());
            Console.WriteLine(I.ToString());
            Console.WriteLine(K.ToString());
            Console.WriteLine(L.ToString());
            Console.WriteLine(J.ToString());
        }



        Console.ReadLine();


    }
}
;