Ejemplo n.º 1
0
        private static void Relax(Surface surface)
        {
            System.Random rand = new System.Random();

            Graph g = new Graph();

            foreach (SurfaceVertex v in surface.Vertices)
            {
                Vector3D v3d = new Vector3D(v.Vertex.X, v.Vertex.Y, v.Vertex.Z);
                //Vector3D v3d = new Vector3D( rand.NextDouble(), rand.NextDouble(), rand.NextDouble() );
                //v3d.Normalize();
                g.Nodes.Add(new GraphNode(new VectorND(new double[] { v3d.X, v3d.Y, v3d.Z }), new VectorND(dimension: 3)));
            }
            foreach (SurfaceEdge e in surface.Edges)
            {
                g.AddEdge(new Edge(e.V1 - 1, e.V2 - 1));                        // more 0-indexed vs. 1-indexed stuff
            }
            GraphRelaxation relaxer = new GraphRelaxation();

            relaxer.Graph          = g;
            relaxer.EdgeAttraction = 0.1;
            relaxer.NodeRepulsion  = 0;
            relaxer.Relax(50);

            int index = 0;

            foreach (GraphNode node in relaxer.Graph.Nodes)
            {
                SurfaceVertex sv = surface.Vertices[index];
                sv.Vertex = new Vector3D(node.Position.X[0], node.Position.X[1], node.Position.X[2]);
                surface.Vertices[index] = sv;
                index++;
            }
        }
Ejemplo n.º 2
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.º 3
0
        private static void Relax(Vector3D[] coordsR3, int[] elementIndices, Vector3D[] locks)
        {
            int   dim = 4;
            Graph g   = new Graph();

            for (int i = 0; i < coordsR3.Length; i++)
            {
                Vector3D  v    = coordsR3[i];
                GraphNode node = new GraphNode(new VectorND(Sterographic.R3toS3(v)), new VectorND(dim));
                node.Lock = new VectorND(locks[i]);
                g.Nodes.Add(node);
            }

            for (int i = 0; i < elementIndices.Length; i += 3)
            {
                int a = elementIndices[i];
                int b = elementIndices[i + 1];
                int c = elementIndices[i + 2];
                g.AddEdge(new GraphEdge(a, b));
                g.AddEdge(new GraphEdge(b, c));
                g.AddEdge(new GraphEdge(c, a));
            }

            GraphRelaxation relaxer = new GraphRelaxation();

            relaxer.Graph          = g;
            relaxer.NodeRepulsion  = 0;
            relaxer.EdgeAttraction = 0.5;
            relaxer.EdgeRepulsion  = 0;
            relaxer.Relax(1000);

            for (int i = 0; i < coordsR3.Length; i++)
            {
                GraphNode node = g.Nodes[i];
                coordsR3[i] = Sterographic.S3toR3(node.Position.ToVec3D());
            }
        }