Exemple #1
0
        private static List <Vector3D[]> BasePointsTiling()
        {
            TilingConfig config = new TilingConfig(3, 7, maxTiles: 100);
            Tiling       tiling = new Tiling();

            tiling.Generate(config);

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

            int numPerSeg = 25;
            List <Vector3D[]> basePoints = new List <Vector3D[]>();

            foreach (Tile t in tiling.Tiles)
            {
                foreach (Segment s in t.Boundary.Segments)
                {
                    H3.Cell.Edge e = new H3.Cell.Edge(s.P1, s.P2);
                    if (finished.Contains(e))
                    {
                        continue;
                    }
                    finished.Add(e);

                    Vector3D[] points = s.Subdivide(numPerSeg).Select(p =>
                    {
                        p = new Vector3D(p.X, 0, p.Y);
                        return(H3Models.BallToUHS(p));
                    }).ToArray();
                    basePoints.Add(points);
                }
            }

            return(basePoints);
        }
Exemple #2
0
        public static void Experiment()
        {
            TilingConfig config = new TilingConfig(4, 3);
            Tiling       tiling = new Tiling();

            tiling.Generate(config);

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

            string fileName = "hopf.pov";

            using (StreamWriter sw = File.CreateText(fileName))
            {
                Tile[] tiles = tiling.Tiles.ToArray();
                //foreach( Tile t in tiling.Tiles )
                foreach (Tile t in new Tile[] { tiles[0] })
                {
                    foreach (Segment seg in t.Boundary.Segments)
                    {
                        H3.Cell.Edge e = new H3.Cell.Edge(seg.P1, seg.P2);
                        if (completed.Contains(e))
                        {
                            continue;
                        }

                        HopfLink(sw,
                                 Sterographic.PlaneToSphereSafe(e.Start),
                                 Sterographic.PlaneToSphereSafe(e.End), anti: false);
                        completed.Add(e);
                    }
                }
            }
        }
Exemple #3
0
        public static void Cell633()
        {
            TilingConfig config = new TilingConfig(6, 3, maxTiles: 20000);
            Tiling       tiling = new Tiling();

            tiling.GenerateInternal(config, Polytope.Projection.VertexCentered);

            double edgeLength = Honeycomb.EdgeLength(6, 3, 3);

            double z      = 0.25;
            double offset = H3Models.UHS.ToEHorizontal(edgeLength, z);
            double scale  = offset / tiling.Tiles.First().Boundary.Segments.First().Length;

            foreach (Tile tile in tiling.Tiles)
            {
                tile.Transform(Mobius.Scale(scale));
            }

            Vector3D dummy;
            double   radius;

            H3Models.UHS.Geodesic(new Vector3D(0, 0, z), new Vector3D(scale, 0, z), out dummy, out radius);
            Vector3D midradius = H3Models.UHSToBall(new Vector3D(0, 0, radius));
            double   temp      = midradius.Z;
            double   temp2     = (1 - temp) / 2;
            double   temp3     = temp + temp2;
            double   temp4     = temp3;

            Vector3D circumradius = H3Models.UHSToBall(new Vector3D(0, 0, z));

            temp  = circumradius.Z;
            temp2 = (1 - temp) / 2;
            temp3 = temp + temp2;
            temp4 = temp3;

            // Checking

            /*
             * Vector3D test = new Vector3D( offset, 0, z );
             * test = H3Models.UHSToBall( test );
             * double edgeLength2 = DonHatch.e2hNorm( test.Abs() );
             * edgeLength2 += 0;
             */

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

            foreach (Tile tile in tiling.Tiles)
            {
                foreach (Segment seg in tile.Boundary.Segments)
                {
                    H3.Cell.Edge edge = new H3.Cell.Edge(
                        H3Models.UHSToBall(seg.P1 + new Vector3D(0, 0, z)),
                        H3Models.UHSToBall(seg.P2 + new Vector3D(0, 0, z)));
                    edges.Add(edge);
                }
            }

            PovRay.WriteH3Edges(new PovRay.Parameters(), edges.ToArray(), "edges.pov");
        }
Exemple #4
0
        // https://plus.google.com/u/0/117663015413546257905/posts/BnCEkdNiTZ2
        public static void TwinDodecs()
        {
            Tiling       tiling = new Tiling();
            TilingConfig config = new TilingConfig(5, 3);

            tiling.GenerateInternal(config, Polytope.Projection.VertexCentered);                // Vertex-centered makes infinities tricky

            Dodec dodec = new Dodec();

            foreach (Tile tile in tiling.Tiles)
            {
                foreach (Segment seg in tile.Boundary.Segments)
                {
                    Vector3D p1 = seg.P1, p2 = seg.P2;
                    if (Infinity.IsInfinite(p1))
                    {
                        p1 = Infinity.InfinityVector;
                    }
                    if (Infinity.IsInfinite(p2))
                    {
                        p2 = Infinity.InfinityVector;
                    }

                    dodec.Verts.Add(p1);
                    dodec.Verts.Add(p2);
                    dodec.Midpoints.Add(Halfway(p1, p2));
                }
            }

            // Now recursively add more vertices.
            HashSet <Vector3D> allVerts = new HashSet <Vector3D>();

            foreach (Vector3D v in dodec.Verts)
            {
                allVerts.Add(v);
            }
            RecurseTwins(allVerts, dodec, 0);

            using (StreamWriter sw = File.CreateText("dual_dodecs_points_sphere.pov"))
            {
                foreach (Vector3D vert in allVerts)
                {
                    Vector3D onSphere = Sterographic.PlaneToSphereSafe(vert);
                    sw.WriteLine(PovRay.Sphere(new Sphere()
                    {
                        Center = onSphere, Radius = 0.01
                    }));

                    //if( !Infinity.IsInfinite( vert ) )
                    //	sw.WriteLine( PovRay.Sphere( new Sphere() { Center = vert, Radius = 0.01 } ) );
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Get a distribution of points on a sphere.
        /// The points are the vertices of a geodesic dome.
        /// </summary>
        private static Vector3D[] SpherePoints()
        {
            List <Vector3D> spherePoints = new List <Vector3D>();
            TilingConfig    config       = new TilingConfig(3, 5);
            Tiling          tiling       = new Tiling();

            tiling.GenerateInternal(config);

            Tile baseTile = tiling.Tiles.First();

            Vector3D[] templateTextureCoords = TextureHelper.TextureCoords(baseTile.Boundary, Geometry.Spherical, doGeodesicDome: true);
            foreach (Tile tile in tiling.Tiles)
            {
                Isometry isom = new Isometry();
                isom.CalculateFromTwoPolygons(baseTile, tile, Geometry.Spherical);
                Vector3D[] textureCoords = Isometry.TransformVertices(templateTextureCoords, isom.Inverse());
                spherePoints.AddRange(textureCoords);
            }

            return(spherePoints.Select(p => H3Models.UHSToBall(p)).Distinct().ToArray());
        }
Exemple #6
0
        public static void Polarity()
        {
            TilingConfig config = new TilingConfig(3, 7, 50);
            Tiling       tiling = new Tiling();

            tiling.GenerateInternal(config);

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

            foreach (Polygon p in tiling.Tiles.Select(t => t.Boundary))
            {
                foreach (Segment s in p.Segments)
                {
                    foreach (Vector3D v in s.Subdivide(25))
                    {
                        Vector3D     klein = HyperbolicModels.PoincareToKlein(v);
                        H3.Cell.Edge e     = Dual(klein);
                        points.Add(klein);
                        edges.Add(e);
                    }
                }
            }

            using (StreamWriter sw = File.CreateText("polarity.pov"))
            {
                double rad = 0.01;
                foreach (Vector3D vert in points)
                {
                    sw.WriteLine(PovRay.Sphere(new Sphere()
                    {
                        Center = vert, Radius = rad
                    }));
                }
                foreach (H3.Cell.Edge edge in edges)
                {
                    sw.WriteLine(PovRay.Cylinder(edge.Start, edge.End, rad / 2));
                }
            }
        }
Exemple #7
0
        private static void HyperidealSquares()
        {
            Mobius rot = new Mobius();

            rot.Isometry(Geometry.Spherical, Math.PI / 4, new Vector3D());

            List <Segment> segs = new List <Segment>();

            int[] qs = new int[] { 5, -1 };
            foreach (int q in qs)
            {
                TilingConfig   config   = new TilingConfig(4, q, 1);
                Tile           t        = Tiling.CreateBaseTile(config);
                List <Segment> polySegs = t.Boundary.Segments;
                polySegs = polySegs.Select(s => { s.Transform(rot); return(s); }).ToList();
                segs.AddRange(polySegs);
            }

            Vector3D v1 = new Vector3D(1, 0);

            v1.RotateXY(Math.PI / 6);
            Vector3D v2 = v1;

            v2.Y *= -1;
            Vector3D cen;
            double   rad;

            H3Models.Ball.OrthogonalCircle(v1, v2, out cen, out rad);
            Segment seg = Segment.Arc(v1, v2, cen, false);

            rot.Isometry(Geometry.Spherical, Math.PI / 2, new Vector3D());
            for (int i = 0; i < 4; i++)
            {
                seg.Transform(rot);
                segs.Add(seg.Clone());
            }

            SVG.WriteSegments("output1.svg", segs);

            System.Func <Segment, Segment> PoincareToKlein = s =>
            {
                return(Segment.Line(
                           HyperbolicModels.PoincareToKlein(s.P1),
                           HyperbolicModels.PoincareToKlein(s.P2)));
            };
            segs = segs.Select(s => PoincareToKlein(s)).ToList();

            Vector3D v0 = new Vector3D(v1.X, v1.X);
            Vector3D v3 = v0;

            v3.Y *= -1;
            Segment seg1 = Segment.Line(v0, v1), seg2 = Segment.Line(v2, v3);
            Segment seg3 = Segment.Line(new Vector3D(1, 1), new Vector3D(1, -1));

            for (int i = 0; i < 4; i++)
            {
                seg1.Transform(rot);
                seg2.Transform(rot);
                seg3.Transform(rot);
                segs.Add(seg1.Clone());
                segs.Add(seg2.Clone());
                segs.Add(seg3.Clone());
            }

            SVG.WriteSegments("output2.svg", segs);
        }