PlaneToSphere() public static method

Sphere geometry is implicit. A radius 1 sphere with the center at the origin.
public static PlaneToSphere ( Vector3D planePoint ) : Vector3D
planePoint Vector3D
return Vector3D
Example #1
0
        private static void HopfFibration(Tiling tiling)
        {
            int       segDivisions = 10;
            Shapeways mesh         = new Shapeways();

            HashSet <Vector3D> done = new HashSet <Vector3D>();

            foreach (Tile tile in tiling.Tiles)
            {
                foreach (Segment seg in tile.Boundary.Segments)
                {
                    if (done.Contains(seg.Midpoint))
                    {
                        continue;
                    }

                    // Subdivide the segment, and project points to S2.
                    Vector3D[] points = seg.Subdivide(segDivisions).Select(v => Spherical2D.PlaneToSphere(v)).ToArray();
                    foreach (Vector3D point in points)
                    {
                        Vector3D[] circlePoints = OneHopfCircle(point);
                        ProjectAndAddS3Points(mesh, circlePoints, shrink: false);
                    }

                    done.Add(seg.Midpoint);
                }
            }

            STL.SaveMeshToSTL(mesh.Mesh, @"D:\p4\R3\sample\out1.stl");
        }
Example #2
0
        private static void HopfFibration(Tiling tiling)
        {
            int       segDivisions    = 10;
            int       circleDivisions = 125;
            Shapeways mesh            = new Shapeways();

            HashSet <Vector3D> done = new HashSet <Vector3D>();

            foreach (Tile tile in tiling.Tiles)
            {
                foreach (Segment seg in tile.Boundary.Segments)
                {
                    if (done.Contains(seg.Midpoint))
                    {
                        continue;
                    }

                    // Subdivide the segment, and project points to S2.
                    Vector3D[] points = seg.Subdivide(segDivisions).Select(v => Spherical2D.PlaneToSphere(v)).ToArray();
                    foreach (Vector3D point in points)
                    {
                        // Get the hopf circle and add to mesh.
                        // http://en.wikipedia.org/wiki/Hopf_fibration#Explicit_formulae
                        double a      = point.X;
                        double b      = point.Y;
                        double c      = point.Z;
                        double factor = 1 / (Math.Sqrt(1 + c));
                        if (Tolerance.Equal(c, -1))
                        {
                            continue;
                        }

                        List <Vector3D> circlePoints = new List <Vector3D>();
                        double          angleInc     = 2 * Math.PI / circleDivisions;
                        double          angle        = 0;
                        for (int i = 0; i <= circleDivisions; i++)
                        {
                            double sinTheta = Math.Sin(angle);
                            double cosTheta = Math.Cos(angle);
                            circlePoints.Add(new Vector3D(
                                                 (1 + c) * cosTheta,
                                                 a * sinTheta - b * cosTheta,
                                                 a * cosTheta + b * sinTheta,
                                                 (1 + c) * sinTheta));

                            angle += angleInc;
                        }

                        bool shrink = false;
                        ProjectAndAddS3Points(mesh, circlePoints.ToArray(), shrink);
                    }

                    done.Add(seg.Midpoint);
                }
            }

            STL.SaveMeshToSTL(mesh.Mesh, @"D:\p4\R3\sample\out1.stl");
        }
Example #3
0
        /// <summary>
        /// Outputs edges to an stl file.
        /// </summary>
        public void Output()
        {
            System.Func <Vector3D, Vector3D> p2s       = v => Spherical2D.PlaneToSphere(v);
            System.Func <Vector3D, Vector3D> transform = v => H3Models.Ball.ApplyMobius(Mobius.Scale(3), v);

            double min  = double.MaxValue;
            Cell   cell = m_cells.First();

            foreach (Vector3D v1 in cell.Tiles[0].Boundary.Vertices)
            {
                foreach (Vector3D v2 in cell.Tiles[1].Boundary.Vertices)
                {
                    min = Math.Min(min, p2s(v1).Dist(p2s(v2)));
                }
            }

            // XXX - code below so ugly to read!

            Dictionary <TileVertex, TileVertex> vMap = new Dictionary <TileVertex, TileVertex>();

            for (int tile_i = 0; tile_i < cell.Tiles.Length; tile_i++)
            {
                for (int tile_j = tile_i + 1; tile_j < cell.Tiles.Length; tile_j++)
                {
                    for (int vertex_i = 0; vertex_i < cell.Tiles[tile_i].Boundary.Vertices.Length; vertex_i++)
                    {
                        for (int vertex_j = 0; vertex_j < cell.Tiles[tile_j].Boundary.Vertices.Length; vertex_j++)
                        {
                            Vector3D v1 = cell.Tiles[tile_i].Boundary.Vertices[vertex_i];
                            Vector3D v2 = cell.Tiles[tile_j].Boundary.Vertices[vertex_j];

                            if (Tolerance.Equal(p2s(v1).Dist(p2s(v2)), min))
                            {
                                vMap[new TileVertex(tile_i, vertex_i)] = new TileVertex(tile_j, vertex_j);
                            }
                        }
                    }
                }
            }

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

            foreach (Cell c in m_cells)
            {
                foreach (KeyValuePair <TileVertex, TileVertex> kvp in vMap)
                {
                    Vector3D v1 = transform(p2s(c.Tiles[kvp.Key.Item1].Boundary.Vertices[kvp.Key.Item2]));
                    Vector3D v2 = transform(p2s(c.Tiles[kvp.Value.Item1].Boundary.Vertices[kvp.Value.Item2]));
                    edges.Add(new H3.Cell.Edge(v1, v2));
                }
            }

            //H3.m_settings.ThinEdges = true;
            H3.SaveToFile("ultrainf", edges.ToArray(), finite: false);
        }