Ejemplo n.º 1
0
        public void Gen()
        {
            Vector3D[] verts = Verts(m_m, m_k);
            Sphere[]   tet   = Tetrahedron(verts);
            Quad       quad  = new Quad()
            {
                Verts = verts
            };

            // We need to avoid infinities.
            //tet = tet.Select( s => H3Models.UHSToBall( s ) ).ToArray();
            //for( int i=0; i<quad.Verts.Length; i++ )
            //	quad.Verts[i] = H3Models.UHSToBall( quad.Verts[i] );

            // Reflect it around.
            //Quad[] quads = new Quad[] { quad };
            Quad[] quads = CalcQuads(tet, quad);

            List <H3.Cell.Edge> edges = new List <H3.Cell.Edge>();

            foreach (Quad q in quads)
            {
                q.R3toS3();
                edges.AddRange(q.GenEdges());
            }

            string filename = string.Format("lawson_{0}_{1}.pov", m_m, m_k);

            PovRay.WriteEdges(new PovRay.Parameters()
            {
                AngularThickness = 0.01
            },
                              Geometry.Spherical, edges.ToArray(), filename, append: false);
        }
Ejemplo n.º 2
0
        public static void Hypercube()
        {
            List <Vector3D> vertices = new List <Vector3D>();

            vertices.Add(new Vector3D(1, 1, 1, 1));
            vertices.Add(new Vector3D(1, 1, 1, -1));
            vertices.Add(new Vector3D(1, 1, -1, 1));
            vertices.Add(new Vector3D(1, 1, -1, -1));
            vertices.Add(new Vector3D(1, -1, 1, 1));
            vertices.Add(new Vector3D(1, -1, 1, -1));
            vertices.Add(new Vector3D(1, -1, -1, 1));
            vertices.Add(new Vector3D(1, -1, -1, -1));
            vertices.Add(new Vector3D(-1, 1, 1, 1));
            vertices.Add(new Vector3D(-1, 1, 1, -1));
            vertices.Add(new Vector3D(-1, 1, -1, 1));
            vertices.Add(new Vector3D(-1, 1, -1, -1));
            vertices.Add(new Vector3D(-1, -1, 1, 1));
            vertices.Add(new Vector3D(-1, -1, 1, -1));
            vertices.Add(new Vector3D(-1, -1, -1, 1));
            vertices.Add(new Vector3D(-1, -1, -1, -1));

            HashSet <H3.Cell.Edge> edges = new HashSet <H3.Cell.Edge>(new H3.Cell.EdgeEqualityComparer());

            foreach (Vector3D v1 in vertices)
            {
                foreach (Vector3D v2 in vertices)
                {
                    if (v1.Dist(v2) == 2)
                    {
                        edges.Add(new H3.Cell.Edge(v1, v2));
                    }
                }
            }

            // Radial project to S3, then stereographic to R3.
            foreach (H3.Cell.Edge edge in edges)
            {
                edge.Start.Normalize();
                edge.Start = Sterographic.S3toR3(edge.Start);
                edge.End.Normalize();
                edge.End = Sterographic.S3toR3(edge.End);
            }

            PovRay.WriteEdges(new PovRay.Parameters()
            {
                AngularThickness = .05
            }, Geometry.Spherical, edges.ToArray(), "433.pov", append: false);
        }
Ejemplo n.º 3
0
        public static void ElevenCell()
        {
            Graph g = new Graph();

            g.SetupCompleteGraph(11);

            GraphRelaxation relaxer = new GraphRelaxation();

            relaxer.Graph          = g;
            relaxer.NodeRepulsion  = 0.01;
            relaxer.EdgeAttraction = 0.0;
            relaxer.EdgeRepulsion  = 0.0;
            relaxer.Relax(20000);

            Vector3D northPole = new Vector3D(0, 0, 0, 1);

            H3.Cell.Edge[] edges = g.Edges.Select(e =>
            {
                Vector3D v1 = g.Nodes[e.V1].Position.ToVec3D();
                Vector3D v2 = g.Nodes[e.V2].Position.ToVec3D();
                //if( v1.Compare( northPole, .5 ) || v2.Compare( northPole, 0.5 ) )	// Cull edges near north pole.
                //	return null;
                v1 = Sterographic.S3toR3(v1);
                v2 = Sterographic.S3toR3(v2);
                return(new H3.Cell.Edge(v1, v2));
            }).ToArray();

            edges = edges.Where(e => e != null).ToArray();

            bool povray = false;

            if (povray)
            {
                string filename = "test.pov";
                System.IO.File.Delete(filename);
                using (StreamWriter sw = new StreamWriter(filename))
                    sw.WriteLine("#include \"C:\\Users\\hrn\\Documents\\roice\\povray\\H3\\horosphere\\633.pov\"");

                PovRay.WriteEdges(new PovRay.Parameters {
                    AngularThickness = 0.03
                }, Geometry.Spherical, edges, filename, append: true);
            }
            else
            {
                S3.EdgesToStl(edges);
            }
        }
Ejemplo n.º 4
0
        private static void CreateSimplex(HoneycombDef imageData)
        {
            int p = imageData.P;
            int q = imageData.Q;
            int r = imageData.R;

            Vector3D cen  = InteriorPointBall;
            bool     ball = true;

            Sphere[] simplex = SimplexCalcs.Mirrors(p, q, r, ref cen, moveToBall: ball);

            // Offset as we do for the boundary images.
            //Sphere s = H3Models.UHSToBall( simplex[0] );
            //s = CoxeterImages.GeodesicOffset( s, 0.02, ball: true );

            if (m_toKlein)
            {
                simplex = simplex.Select(s => H3Models.BallToKlein(s)).ToArray();
            }

            int[] include = new int[] { 0, 1, 2, 3 };                   // All facets
            //int[] include = new int[] { 1 };
            File.Delete("simplex.pov");
            PovRay.AppendSimplex(simplex, cen, include, "simplex.pov");

            bool includeEdges = false;

            if (includeEdges)
            {
                H3.Cell.Edge[] edges = SimplexCalcs.SimplexEdgesUHS(p, q, r);
                PovRay.WriteEdges(new PovRay.Parameters {
                    Halfspace = true, AngularThickness = 0.03
                },
                                  Geometry.Hyperbolic, edges, "simplex.pov", append: true);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This generates a honeycomb by reflecting in 4 mirrors of the fundamental simplex.
        /// This "new" method is now old.
        /// </summary>
        public static void OneHoneycombNew(HoneycombDef imageData)
        {
            int p = imageData.P;
            int q = imageData.Q;
            int r = imageData.R;

            double thickness           = 0.05;
            double thicknessSpherical  = Spherical2D.s2eNorm(thickness);
            double thicknessHyperbolic = R3.Math.DonHatch.h2eNorm(thickness);
            double threshold           = 1;

            H3.Cell.Edge[] edges            = null;
            H3.Cell[]      cellsToHighlight = null;
            Sphere[]       simplex          = null;
            Vector3D       vertex           = new Vector3D();

            Geometry g = Util.GetGeometry(p, q, r);

            if (g == Geometry.Spherical)
            {
                thickness = thicknessSpherical /*.07 for 333*/  /* 0.05for 433*/  /*.025 for 533,335*/;
                threshold = 10000;

                simplex = SimplexCalcs.MirrorsSpherical(p, q, r);
                vertex  = SimplexCalcs.VertexSpherical(p, q, r);

                // Ugly special casing for 333, since it has a vertex project to infinity.
                if (p == 3 && q == 3 && r == 3)
                {
                    SpecialCase333();
                }
            }
            else if (g == Geometry.Euclidean)
            {
                thickness = thickness / 2;
                threshold = 1 /*20*/;

                //SimplexCalcs.CalcEScale();
                simplex = SimplexCalcs.MirrorsEuclidean();
                Vector3D[] verts = SimplexCalcs.VertsEuclidean();
                vertex = verts[2];
            }
            else
            {
                thickness = thicknessHyperbolic;
                threshold = 0.01;

                simplex = SimplexCalcs.Mirrors(p, q, r);
                Vector3D[] verts = SimplexCalcs.VertsBall(p, q, r);
                vertex = verts[2];

                //Vector3D[] simplexVerts = SimplexCalcs.VertsBall( p, q, r );
                //H3.Cell.Edge edge = new H3.Cell.Edge( simplexVerts[2], simplexVerts[3] );
                //H3.Cell.Edge edge = SimplexCalcs.HoneycombEdgeBall( p, q, r );
                //H3.Cell.Edge[] startingEdges = new H3.Cell.Edge[] { edge };

                //H3.Cell.Edge[] edges = Recurse.CalcEdgesSmart2( simplex, startingEdges );

                // Vertex Centered.
                bool vertexCentered = false;
                if (vertexCentered)
                {
                    Vector3D v = SimplexCalcs.VertexPointBall(p, q, r);
                    v = H3Models.BallToUHS(v);
                    double scale = 1.0 / v.Abs();
                    edges = edges.Select(e =>
                    {
                        Vector3D start = H3Models.UHSToBall(H3Models.BallToUHS(e.Start) * scale);
                        Vector3D end   = H3Models.UHSToBall(H3Models.BallToUHS(e.End) * scale);
                        return(new H3.Cell.Edge(start, end));
                    }).ToArray();
                }

                // Code to show endpoints of 535

                /*using( StreamWriter sw = File.CreateText( "535_points.pov" ) )
                 * {
                 *      HashSet<Vector3D> verts = new HashSet<Vector3D>();
                 *      foreach( H3.Cell.Edge e in edges )
                 *      {
                 *              verts.Add( Sterographic.SphereToPlane( e.Start ) );
                 *              verts.Add( Sterographic.SphereToPlane( e.End ) );
                 *      }
                 *
                 *      foreach( Vector3D vert in verts )
                 *              if( !Infinity.IsInfinite( vert ) )
                 *                      sw.WriteLine( PovRay.Sphere( new Sphere() { Center = vert, Radius = 0.01 } ) );
                 * }*/
            }

            // Recurse
            bool dual = false;
            {
                H3.Cell.Edge[] startingEdges = null;
                if (dual)
                {
                    startingEdges = new H3.Cell.Edge[] { SimplexCalcs.DualEdgeBall(simplex) }
                }
                ;
                else
                {
                    //startingEdges = new H3.Cell.Edge[] { SimplexCalcs.HoneycombEdgeBall( simplex, vertex ) };
                    Vector3D[] verts  = SimplexCalcs.VertsEuclidean();
                    Vector3D   v1     = verts[0] + 2 * verts[2];             // adjacent cube center
                    Vector3D   corner = verts[3];

                    startingEdges = new H3.Cell.Edge[] { new H3.Cell.Edge(v1, corner) };
                }

                edges = Recurse.CalcEdges(simplex, startingEdges, new Recurse.Settings()
                {
                    G = g, Threshold = threshold
                });

                edges = edges.Where(e =>
                {
                    int sum = e.Depths.Count(d => d == 0);
                    return(true);
                }).ToArray();

                //CullHalfOfEdges( ref edges );

                // No need to cull edges in spherical case.
                // This was just to generate some images for 350-cell paper.
                //edges = Cull120Cell( edges );

                Simplex tet = new Simplex();
                tet.Facets = simplex;

                if (dual)
                {
                    H3.Cell.Edge[] oneDualCell = edges.Where(e => e.Depths[2] == 0).ToArray();
                    simplex = simplex.Skip(1).ToArray();
                    edges   = Recurse.CalcEdges(simplex, oneDualCell, new Recurse.Settings()
                    {
                        G = g, Threshold = threshold
                    });

                    int[]   polyMirrors  = new int[] { 0, 1, 3 };
                    H3.Cell startingCell = HoneycombGen.PolyhedronToHighlight(g, polyMirrors, tet, new Vector3D());
                    cellsToHighlight = Recurse.CalcCells(simplex, new H3.Cell[] { startingCell });
                    //cellsToHighlight = new H3.Cell[] { startingCell };
                    //cellsToHighlight = cellsToHighlight.Skip( 7 ).ToArray();
                }
                else
                {
                    int[]   polyMirrors  = new int[] { 1, 2, 3 };
                    H3.Cell startingCell = HoneycombGen.PolyhedronToHighlight(g, polyMirrors, tet, vertex);
                    //cellsToHighlight = Recurse.CalcCells( simplex, new H3.Cell[] { startingCell } );
                    cellsToHighlight = new H3.Cell[] { startingCell };
                }

                // Include just one cell?
                bool includeOne = false;
                if (includeOne)
                {
                    edges = edges.Where(e => e.Depths[0] == 0).ToArray();
                    //cellsToHighlight = cellsToHighlight.Where( c => c.Depths[0] == 0 ).ToArray();
                }
            }

            // Rotate
            bool rotate = false;

            if (rotate)
            {
                CompoundOfFive24Cells(ref edges);
            }

            // Write the file
            bool pov = true;

            if (pov)
            {
                string filename = string.Format("{0}{1}{2}.pov", p, q, r);
                PovRay.WriteEdges(new PovRay.Parameters()
                {
                    AngularThickness = thickness
                }, g, edges,
                                  filename, append: false);
                //File.Delete( filename );
                //PovRay.AppendFacets( cellsToHighlight, filename );

                HashSet <Vector3D> verts = new HashSet <Vector3D>();
                foreach (H3.Cell.Edge e in edges)
                {
                    verts.Add(e.Start);
                    verts.Add(e.End);
                }

                /*foreach( Vector3D v in verts )
                 * {
                 *      Vector3D t = v;
                 *      t.Normalize();
                 *      t *= 0.9;
                 *      System.Diagnostics.Trace.WriteLine( string.Format( "light_source {{ <{0},{1},{2}> White*.2 }}", t.X, t.Y, t.Z ) );
                 * }*/


                /*
                 * // Include the standard pov stuff, so we can batch this.
                 * string fileName = imageData.FormatFilename( string.Empty );
                 * using( StreamWriter sw = File.CreateText( fileName + ".pov" ) )
                 * {
                 *      sw.WriteLine( "#include \"C:\\Users\\hrn\\Documents\\roice\\povray\\paper\\H3.pov\"" );
                 * }
                 *
                 * bool dummy = true;	// Doesn't matter for Pov-Ray, just Shapeways meshes.
                 * H3.SaveToFile( fileName, edges, dummy, append: true );
                 */
            }
            else
            {
                if (g == Geometry.Spherical)
                {
                    edges = edges.Where(e => e.Start.Valid() && e.End.Valid() && !Infinity.IsInfinite(e.Start) && !Infinity.IsInfinite(e.End)).ToArray();
                    S3.EdgesToStl(edges);
                }
                else
                {
                    throw new System.NotImplementedException();
                }
            }
        }