Пример #1
0
        public void TwelveFaces_ShouldHaveFiveVertices
            (IPolyhedronOptions options)
        {
            // Fixture setup
            var polyhedron = GeodesicSphereFactory.Build(options);

            // Exercise system
            var numberOfFacesWithFiveVertices = polyhedron.Faces.Count(face => face.Vertices.Count == 5);

            // Verify outcome
            Debug.WriteLine("Number of faces with five vertices is " + numberOfFacesWithFiveVertices);
            Assert.True(numberOfFacesWithFiveVertices == 12);

            // Teardown
        }
        // Icosaspheres are generated by repeatedly subdividing the faces of an icosahedron, then projecting the resultant
        // vertices onto the sphere.

        /// <summary>
        /// Constructs the geodesic sphere with a number of faces exceeding the specified minimum.
        /// </summary>
        public static IPolyhedron Build(IPolyhedronOptions options)
        {
            // Build an icosasphere with a minimum number of faces.
            var minimumNumberOfVertices = 2 * options.MinimumNumberOfFaces - 4;
            var icosasphereOptions      = new PolyhedronOptions
            {
                Radius = options.Radius,
                MinimumNumberOfFaces = minimumNumberOfVertices
            };
            var icosasphere = IcosasphereFactory.Build(icosasphereOptions);

            // Take the icosasphere's dual to get the geodesic sphere we want.
            var faces = DualofIcosasphere(icosasphere);

            return(new Polyhedron(faces));
        }
        // Icosaspheres are generated by repeatedly subdividing the faces of an icosahedron, then projecting the resultant
        // vertices onto the sphere.

        /// <summary>
        /// Constructs the icosasphere with least number of vertices exceeding the specified minimum.
        /// </summary>
        public static IPolyhedron Build(IPolyhedronOptions options)
        {
            var icosahedron = IcosahedronFactory.Build();

            // Calculate the number of times the icosahedron will have to be subdivided in order to meet the minimum
            // number of faces specification.
            var numberOfSubdivisions = NumberOfSubdivisionsRequired(options.MinimumNumberOfFaces);

            // Keep subdividing the icosahedron until it meets the minimum number of faces specification.
            for (int i = 0; i < numberOfSubdivisions; i++)
            {
                icosahedron = Subdivide(icosahedron);
            }

            // Project the subdivision of the icosahedron onto the sphere.
            return(ProjectOntoSphere(icosahedron, options.Radius));
        }
Пример #4
0
        public void Vertices_ShouldHaveTheSameLengthsAsTheRadius
            (IPolyhedronOptions options)
        {
            // Fixture setup
            var polyhedron = GeodesicSphereFactory.Build(options);

            // Exercise system
            var vertices = polyhedron.Vertices;

            // Verify outcome
            var lengths = vertices.Select(vertex => vertex.Position.Norm()).ToList();

            Debug.WriteLine("Lengths were " + TestUtilities.CollectionToString(lengths));
            Assert.True(lengths.All(length => Number.AlmostEqual(length, options.Radius)));

            // Teardown
        }
Пример #5
0
        public void EveryVertex_ShouldNeighbourThreeFaces
            (IPolyhedronOptions options)
        {
            // Fixture setup
            var polyhedron = GeodesicSphereFactory.Build(options);

            // Exercise system
            var numberOfVerticesWithThreeFaces = polyhedron.Vertices.Count(vertex => polyhedron.FacesOf(vertex).Count == 3);

            // Verify outcome
            var numberOfVertices = polyhedron.Vertices.Count;

            Debug.WriteLine("Number of vertices is " + numberOfVertices);
            Debug.WriteLine("Number of vertices neighbouring three faces is " + numberOfVerticesWithThreeFaces);
            Assert.True(numberOfVerticesWithThreeFaces == numberOfVertices);

            // Teardown
        }
Пример #6
0
        public void EveryEdge_ShouldNeighbourTwoFaces
            (IPolyhedronOptions options)
        {
            // Fixture setup
            var polyhedron = GeodesicSphereFactory.Build(options);

            // Exercise system
            var numberOfEdgesWithThreeFaces = polyhedron.Edges.Count(edge => polyhedron.FacesOf(edge).Count == 2);

            // Verify outcome
            var numberOfEdges = polyhedron.Edges.Count;

            Debug.WriteLine("Number of edges is " + numberOfEdges);
            Debug.WriteLine("Number of edges neighbouring two faces is " + numberOfEdgesWithThreeFaces);
            Assert.True(numberOfEdgesWithThreeFaces == numberOfEdges);

            // Teardown
        }
Пример #7
0
        public void NumbersOfVerticesAndEdgesAndFaces_ShouldSatisfyEulersFormula
            (IPolyhedronOptions options)
        {
            // Fixture setup
            var polyhedron = GeodesicSphereFactory.Build(options);

            // Exercise system
            var v = polyhedron.Vertices.Count;
            var e = polyhedron.Edges.Count;
            var f = polyhedron.Faces.Count;

            // Verify outcome
            Debug.WriteLine("Number of vertices: " + v);
            Debug.WriteLine("Number of edges: " + e);
            Debug.WriteLine("Number of faces: " + f);
            Assert.True(v - e + f == 2);

            // Teardown
        }