private static VertexNode[] CreateWeightedNodes(float[] vertices, int hull) { var nodes = new VertexNode[hull]; int currentIndex = 0; for (int i = 0; i < nodes.Length; i++) { int vertexCount = (int)vertices[currentIndex]; // Количество костей Vertex[] vtx = new Vertex[vertexCount]; for (int j = 0; j < vtx.Length; j++) { int bone = (int)vertices[currentIndex + 1]; float x = vertices[currentIndex + 2]; float y = vertices[currentIndex + 3]; float weight = vertices[currentIndex + 4]; vtx[j] = new Vertex(bone, x, y, weight); currentIndex += 4; } nodes[i] = new VertexNode(vtx); currentIndex++; } return(nodes); }
// Returns all active vertices in step n public List <VertexNode> getVertices(int n) { List <VertexNode> activeVertices = new List <VertexNode>(); for (int i = 0; i < vll.Count; i++) { if (vll[i].vertices[0].step <= n) { int j = 0; int m = 0; while (j < vll[i].vertices.Count) { if (vll[i].vertices[j].step <= n) { m = j; } j++; } VertexNode vn = new VertexNode(vll[i].vertices[m]); activeVertices.Add(vn); } } return(activeVertices); }
//add vertex public void AddVertex(string newLabel) { // create temporary node with the input // newLabel value VertexNode temp = new VertexNode(newLabel); // If there are no vertices, reference start to temp if (start == null) { start = temp; } // Reference current to the last node temp. else { VertexNode current = start; while (current.nextVertex != null) { if (current.Label.Equals(newLabel)) { Console.WriteLine("Already exists!"); } // move current to next vertex while the value is not null // and doesn't already exist current = current.nextVertex; } if (current.Label.Equals(newLabel)) { Console.WriteLine("Already exists!"); return; } current.nextVertex = temp; } }
// Given a vertex it moves it to the closest point to the selected not performing any creases public void displace(VertexNode vn, Vector3 p) { step++; Vector3 pos = new Vector3(0, 0, 0); List <Edge> eL = vn.edges; List <VertexNode> contiguous = new List <VertexNode>(); for (int i = 0; i < eL.Count; i++) { if (eL[i].origin != vn) { contiguous.Add(eL[i].origin); } if (eL[i].end != vn) { contiguous.Add(eL[i].end); } } for (int i = 0; i < contiguous.Count; i++) { pos += contiguous[i].getPosition(); } pos = pos / contiguous.Count; pos = vn.getPosition() + (pos - vn.getPosition()) * 2; /// /// p1 = (x0,->c1-c2) /// q = p projectat p1 /// p2 = (q, cross(->q-c1,->q-c2)) /// /// c = c1 +r1 -(r1+r2-d(c1,c2))/2 /// rc = d(c, c2) /// r = sqrt(r2^2+rc^2) /// S = (c,r) //sage: x, y,z,a,b,c,d,e,f,g,h,i,j,k,l = var('x, y,z,a,b,c,d,e,f,g,h,i,j,k,l') //sage: solve([(x - a) ^ 2 + (y - b) ^ 2 + (z - c) ^ 2 == d, e * x + f * y + z * g == h, i * x + j * y + z * k == l], x, y,z) ////x == -((c * f * g - b * g ^ 2 - f * h) * i * j - (c * e * g - a * g ^ 2 - e * h) * j ^ 2 - (b * e * f - a * f ^ 2 - e * h) * k ^ 2 - ((c * f ^ 2 - b * f * g + g * h) * i - (c * e * f + (b * e - 2 * a * f) * g) * j) * k - (e * f * j + e * g * k - (f ^ 2 + g ^ 2) * i) * l - sqrt(-(2 * b * c * f * g + (a ^ 2 + b ^ 2 - d) * f ^ 2 + (a ^ 2 + c ^ 2 - d) * g ^ 2 - 2 * (b * f + c * g) * h + h ^ 2) * i ^ 2 - 2 * (a * b * g ^ 2 - (a ^ 2 + b ^ 2 - d) * e * f - (b * c * e + a * c * f) * g + (b * e + a * f) * h) * i * j - (2 * a * c * e * g + (a ^ 2 + b ^ 2 - d) * e ^ 2 + (b ^ 2 + c ^ 2 - d) * g ^ 2 - 2 * (a * e + c * g) * h + h ^ 2) * j ^ 2 - (2 * a * b * e * f + (a ^ 2 + c ^ 2 - d) * e ^ 2 + (b ^ 2 + c ^ 2 - d) * f ^ 2 - 2 * (a * e + b * f) * h + h ^ 2) * k ^ 2 - (e ^ 2 + f ^ 2 + g ^ 2) * l ^ 2 + 2 * ((b * c * e * f - a * c * f ^ 2 + (a * b * f + (a ^ 2 + c ^ 2 - d) * e) * g - (c * e + a * g) * h) * i - (b * c * e ^ 2 - a * c * e * f - (a * b * e + (b ^ 2 + c ^ 2 - d) * f) * g + (c * f + b * g) * h) * j) * k - 2 * ((b * e * f - a * f ^ 2 + c * e * g - a * g ^ 2 - e * h) * i - (b * e ^ 2 - a * e * f - c * f * g + b * g ^ 2 + f * h) * j - (c * e ^ 2 + c * f ^ 2 - (a * e + b * f) * g + g * h) * k) * l) * (g * j - f * k)) / (2 * e * f * i * j - (f ^ 2 + g ^ 2) * i ^ 2 - (e ^ 2 + g ^ 2) * j ^ 2 - (e ^ 2 + f ^ 2) * k ^ 2 + 2 * (e * g * i + f * g * j) * k), ///y == ((c * f * g - b * g ^ 2 - f * h) * i ^ 2 - (c * e * g - a * g ^ 2 - e * h) * i * j - (b * e ^ 2 - a * e * f + f * h) * k ^ 2 - ((c * e * f - (2 * b * e - a * f) * g) * i - (c * e ^ 2 - a * e * g + g * h) * j) * k + (e * f * i + f * g * k - (e ^ 2 + g ^ 2) * j) * l - sqrt(-(2 * b * c * f * g + (a ^ 2 + b ^ 2 - d) * f ^ 2 + (a ^ 2 + c ^ 2 - d) * g ^ 2 - 2 * (b * f + c * g) * h + h ^ 2) * i ^ 2 - 2 * (a * b * g ^ 2 - (a ^ 2 + b ^ 2 - d) * e * f - (b * c * e + a * c * f) * g + (b * e + a * f) * h) * i * j - (2 * a * c * e * g + (a ^ 2 + b ^ 2 - d) * e ^ 2 + (b ^ 2 + c ^ 2 - d) * g ^ 2 - 2 * (a * e + c * g) * h + h ^ 2) * j ^ 2 - (2 * a * b * e * f + (a ^ 2 + c ^ 2 - d) * e ^ 2 + (b ^ 2 + c ^ 2 - d) * f ^ 2 - 2 * (a * e + b * f) * h + h ^ 2) * k ^ 2 - (e ^ 2 + f ^ 2 + g ^ 2) * l ^ 2 + 2 * ((b * c * e * f - a * c * f ^ 2 + (a * b * f + (a ^ 2 + c ^ 2 - d) * e) * g - (c * e + a * g) * h) * i - (b * c * e ^ 2 - a * c * e * f - (a * b * e + (b ^ 2 + c ^ 2 - d) * f) * g + (c * f + b * g) * h) * j) * k - 2 * ((b * e * f - a * f ^ 2 + c * e * g - a * g ^ 2 - e * h) * i - (b * e ^ 2 - a * e * f - c * f * g + b * g ^ 2 + f * h) * j - (c * e ^ 2 + c * f ^ 2 - (a * e + b * f) * g + g * h) * k) * l) * (g * i - e * k)) / (2 * e * f * i * j - (f ^ 2 + g ^ 2) * i ^ 2 - (e ^ 2 + g ^ 2) * j ^ 2 - (e ^ 2 + f ^ 2) * k ^ 2 + 2 * (e * g * i + f * g * j) * k), ///z == -((c * f ^ 2 - b * f * g + g * h) * i ^ 2 - (2 * c * e * f - (b * e + a * f) * g) * i * j + (c * e ^ 2 - a * e * g + g * h) * j ^ 2 + ((b * e * f - a * f ^ 2 - e * h) * i - (b * e ^ 2 - a * e * f + f * h) * j) * k - (e * g * i + f * g * j - (e ^ 2 + f ^ 2) * k) * l - sqrt(-(2 * b * c * f * g + (a ^ 2 + b ^ 2 - d) * f ^ 2 + (a ^ 2 + c ^ 2 - d) * g ^ 2 - 2 * (b * f + c * g) * h + h ^ 2) * i ^ 2 - 2 * (a * b * g ^ 2 - (a ^ 2 + b ^ 2 - d) * e * f - (b * c * e + a * c * f) * g + (b * e + a * f) * h) * i * j - (2 * a * c * e * g + (a ^ 2 + b ^ 2 - d) * e ^ 2 + (b ^ 2 + c ^ 2 - d) * g ^ 2 - 2 * (a * e + c * g) * h + h ^ 2) * j ^ 2 - (2 * a * b * e * f + (a ^ 2 + c ^ 2 - d) * e ^ 2 + (b ^ 2 + c ^ 2 - d) * f ^ 2 - 2 * (a * e + b * f) * h + h ^ 2) * k ^ 2 - (e ^ 2 + f ^ 2 + g ^ 2) * l ^ 2 + 2 * ((b * c * e * f - a * c * f ^ 2 + (a * b * f + (a ^ 2 + c ^ 2 - d) * e) * g - (c * e + a * g) * h) * i - (b * c * e ^ 2 - a * c * e * f - (a * b * e + (b ^ 2 + c ^ 2 - d) * f) * g + (c * f + b * g) * h) * j) * k - 2 * ((b * e * f - a * f ^ 2 + c * e * g - a * g ^ 2 - e * h) * i - (b * e ^ 2 - a * e * f - c * f * g + b * g ^ 2 + f * h) * j - (c * e ^ 2 + c * f ^ 2 - (a * e + b * f) * g + g * h) * k) * l) * (f * i - e * j)) / (2 * e * f * i * j - (f ^ 2 + g ^ 2) * i ^ 2 - (e ^ 2 + g ^ 2) * j ^ 2 - (e ^ 2 + f ^ 2) * k ^ 2 + 2 * (e * g * i + f * g * j) * k)], ///[x == -((c* f* g - b* g^2 - f* h)*i* j - (c* e* g - a* g^2 - e* h)*j^2 - (b* e* f - a* f^2 - e* h)*k^2 - ((c* f^2 - b* f*g + g* h)*i - (c* e* f + (b* e - 2*a* f)*g)*j)*k - (e* f* j + e* g*k - (f^2 + g^2)*i)*l + sqrt(-(2*b* c*f* g + (a^2 + b^2 - d)*f^2 + (a^2 + c^2 - d)*g^2 - 2*(b* f + c* g)*h + h^2)*i^2 - 2*(a* b* g^2 - (a^2 + b^2 - d)*e* f - (b* c* e + a* c*f)*g + (b* e + a* f)*h)*i* j - (2*a* c*e* g + (a^2 + b^2 - d)*e^2 + (b^2 + c^2 - d)*g^2 - 2*(a* e + c* g)*h + h^2)*j^2 - (2*a* b*e* f + (a^2 + c^2 - d)*e^2 + (b^2 + c^2 - d)*f^2 - 2*(a* e + b* f)*h + h^2)*k^2 - (e^2 + f^2 + g^2)*l^2 + 2*((b* c* e* f - a* c*f^2 + (a* b* f + (a^2 + c^2 - d)*e)*g - (c* e + a* g)*h)*i - (b* c* e^2 - a* c*e* f - (a* b* e + (b^2 + c^2 - d)*f)*g + (c* f + b* g)*h)*j)*k - 2*((b* e* f - a* f^2 + c* e*g - a* g^2 - e* h)*i - (b* e^2 - a* e*f - c* f*g + b* g^2 + f* h)*j - (c* e^2 + c* f^2 - (a* e + b* f)*g + g* h)*k)*l)*(g* j - f* k))/(2*e* f*i* j - (f^2 + g^2)*i^2 - (e^2 + g^2)*j^2 - (e^2 + f^2)*k^2 + 2*(e* g* i + f* g*j)*k), ///y == ((c* f* g - b* g^2 - f* h)*i^2 - (c* e* g - a* g^2 - e* h)*i* j - (b* e^2 - a* e*f + f* h)*k^2 - ((c* e* f - (2*b* e - a* f)*g)*i - (c* e^2 - a* e*g + g* h)*j)*k + (e* f* i + f* g*k - (e^2 + g^2)*j)*l + sqrt(-(2*b* c*f* g + (a^2 + b^2 - d)*f^2 + (a^2 + c^2 - d)*g^2 - 2*(b* f + c* g)*h + h^2)*i^2 - 2*(a* b* g^2 - (a^2 + b^2 - d)*e* f - (b* c* e + a* c*f)*g + (b* e + a* f)*h)*i* j - (2*a* c*e* g + (a^2 + b^2 - d)*e^2 + (b^2 + c^2 - d)*g^2 - 2*(a* e + c* g)*h + h^2)*j^2 - (2*a* b*e* f + (a^2 + c^2 - d)*e^2 + (b^2 + c^2 - d)*f^2 - 2*(a* e + b* f)*h + h^2)*k^2 - (e^2 + f^2 + g^2)*l^2 + 2*((b* c* e* f - a* c*f^2 + (a* b* f + (a^2 + c^2 - d)*e)*g - (c* e + a* g)*h)*i - (b* c* e^2 - a* c*e* f - (a* b* e + (b^2 + c^2 - d)*f)*g + (c* f + b* g)*h)*j)*k - 2*((b* e* f - a* f^2 + c* e*g - a* g^2 - e* h)*i - (b* e^2 - a* e*f - c* f*g + b* g^2 + f* h)*j - (c* e^2 + c* f^2 - (a* e + b* f)*g + g* h)*k)*l)*(g* i - e* k))/(2*e* f*i* j - (f^2 + g^2)*i^2 - (e^2 + g^2)*j^2 - (e^2 + f^2)*k^2 + 2*(e* g* i + f* g*j)*k), ///z == -((c* f^2 - b* f*g + g* h)*i^2 - (2*c* e*f - (b* e + a* f)*g)*i* j + (c* e^2 - a* e*g + g* h)*j^2 + ((b* e* f - a* f^2 - e* h)*i - (b* e^2 - a* e*f + f* h)*j)*k - (e* g* i + f* g*j - (e^2 + f^2)*k)*l + sqrt(-(2*b* c*f* g + (a^2 + b^2 - d)*f^2 + (a^2 + c^2 - d)*g^2 - 2*(b* f + c* g)*h + h^2)*i^2 - 2*(a* b* g^2 - (a^2 + b^2 - d)*e* f - (b* c* e + a* c*f)*g + (b* e + a* f)*h)*i* j - (2*a* c*e* g + (a^2 + b^2 - d)*e^2 + (b^2 + c^2 - d)*g^2 - 2*(a* e + c* g)*h + h^2)*j^2 - (2*a* b*e* f + (a^2 + c^2 - d)*e^2 + (b^2 + c^2 - d)*f^2 - 2*(a* e + b* f)*h + h^2)*k^2 - (e^2 + f^2 + g^2)*l^2 + 2*((b* c* e* f - a* c*f^2 + (a* b* f + (a^2 + c^2 - d)*e)*g - (c* e + a* g)*h)*i - (b* c* e^2 - a* c*e* f - (a* b* e + (b^2 + c^2 - d)*f)*g + (c* f + b* g)*h)*j)*k - 2*((b* e* f - a* f^2 + c* e*g - a* g^2 - e* h)*i - (b* e^2 - a* e*f - c* f*g + b* g^2 + f* h)*j - (c* e^2 + c* f^2 - (a* e + b* f)*g + g* h)*k)*l)*(f* i - e* j))/(2*e* f*i* j - (f^2 + g^2)*i^2 - (e^2 + g^2)*j^2 - (e^2 + f^2)*k^2 + 2*(e* g* i + f* g*j)*k) Vertex newV = new Vertex(pos, step, vertexLL.count); vertexLL.count++; vn.Add(newV); unfoldCount = 0; }
public void RemoveVertexNode() { VertexGraph graph = new VertexGraph(9); // Straight removal var node = graph.AddNode(vertex1, vertex2); var success = graph.RemoveNode(node); Assert.IsTrue(success); Assert.IsNull(graph.FindVertex(vertex1)); Assert.AreEqual(0, graph.Size); // Remove end of list graph.AddNode(vertex1, vertex2); node = graph.AddNode(vertex1, vertex3); success = graph.RemoveNode(node); Assert.IsTrue(success); Assert.IsNull(graph.FindEdge(vertex1, vertex3)); Assert.AreEqual(1, graph.Size); // This removal is just cleanup node = graph.FindVertex(vertex1); Assert.IsTrue(graph.RemoveNode(node)); // Remove beginning of list node = graph.AddNode(vertex1, vertex2); graph.AddNode(vertex1, vertex3); success = graph.RemoveNode(node); Assert.IsTrue(success); Assert.IsNull(graph.FindEdge(vertex1, vertex2)); Assert.IsNotNull(graph.FindEdge(vertex1, vertex3)); Assert.AreEqual(1, graph.Size); // This removal is just cleanup node = graph.FindVertex(vertex1); Assert.IsTrue(graph.RemoveNode(node)); // Remove middle of list graph.AddNode(vertex1, vertex2); node = graph.AddNode(vertex1, vertex3); graph.AddNode(vertex1, vertex4); success = graph.RemoveNode(node); Assert.IsTrue(success); Assert.IsNull(graph.FindEdge(vertex1, vertex3)); Assert.IsNotNull(graph.FindEdge(vertex1, vertex4)); Assert.AreEqual(2, graph.Size); // Remove non-existent node node = new VertexNode(); success = graph.RemoveNode(node); Assert.IsFalse(success); Assert.AreEqual(2, graph.Size); graph.Clear(); }
/// <summary> /// Initializer for a node /// </summary> /// <param name="fromVtx">Vertex to start from</param> /// <param name="toVtx">Vertex to end at</param> /// <!-- Based off 3.1.1 --> private static VertexNode _initVertexNode(GeoCoord fromVtx, GeoCoord toVtx) { var node = new VertexNode { from = fromVtx, to = toVtx, next = null }; return(node); }
//---------------------------------AUXILIAR FUNCTIONS-------------------------------------------// // Given 2 elements it creates the symmetry plane for the fold public Plane createSymmetryPlane(VertexNode v1, VertexNode v2) { Vector3 normal = v1.getPosition() - v2.getPosition(); Vector3 midpoint = (v1.getPosition() + v2.getPosition()) / 2; Plane p = new Plane(normal, midpoint); return(p); }
// Mountain, valley, inside and reverse folds and open sinks public void symmetryFold(Plane p, VertexNode v1, Vector3 n) { step++; Vector3 delta = n * epsilon; p.addToNormal(delta); fold(p, v1); }
private void Generate() { int count = Random.Range(0, allNodes.Count); VertexNode theNode = allNodes[count]; nodesInTree.Add(theNode); findNext(); }
public void Set_VertexNode_ReturnException() { adjList.Add(new VertexNode("A")); adjList.Add(new VertexNode("B")); Assert.Throws <ArgumentException>(() => { adjList[0] = new VertexNode("B"); }, "插入了重复顶点!"); }
VertexNode[] vertexes; //顶点顺序表 #endregion Fields #region Constructors public AdjacencyList(string[] cities) { vertexes = new VertexNode[cities.Length]; for (int i = 0; i < cities.Length; i++) { vertexes[i] = new VertexNode(cities[i]); } }
public bool edgeContainsVertex(VertexNode _aNode) { if (node0 == _aNode || node1 == _aNode) { return(true); } return(false); }
public Edge(VertexNode _n0, VertexNode _n1) { node0 = _n0; node1 = _n1; theLine = new GameObject().AddComponent <LineRenderer>(); theLine.material = new Material(Shader.Find("Particles/Additive")); theLine.name = "EdgeLine"; theLine.tag = "Lines"; }
public void ItemTest() { for (int i = 0; i < graph.VertexNodeList.Length; i++) { VertexNode <string> current = graph[i]; Assert.AreEqual(nodes[i], current.Data); } }
/// <summary> /// 添加顶点 /// </summary> /// <param name="data"></param> public void AddVertex(T data) { // 扩容 if (index >= vertexs.Length) { Resize(); } vertexs[index] = new VertexNode(data); index++; }
public override bool Equals(object obj) { VertexNode objVerNode = (VertexNode)obj; if (!Vertex.Equals(objVerNode.Vertex)) { return(false); } return(base.Equals(obj)); }
/************************ * Constructor ************************/ public Delaunay() { m_isComplete = false; m_triangleList = new List <Triangle>(); m_toAddList = new List <VertexNode>(); m_nextNode = null; m_dirtyEdges = new List <Edge>(); m_infProtect = 0; m_finalTriangulation = new List <Edge>(); }
public void init() { for (int vnc = 0; vnc < VertexNodeCount; vnc++) { VertexNode cuVN = new VertexNode(); cuVN.vertex = vnc; cuVN.firstedge = null; AdjList[vnc] = cuVN; } }
// Folds along a symmetry plane v being the moved vertex public void fold(Plane p, VertexNode v) { List <VertexNode> aV = getAfecctedVertices(p, v); generateNewCreases(p); applySymetry(p, aV); unfoldCount = 0; }
public SynchronizedCollection <VertexNode <T> > GetAdjacentNodes(VertexNode <T> sourceNode) { // This method needs to get the adjacent nodes from an adjacency matrix. var matches = this.Vertices[sourceNode.Position] .Where(t => t != null) .Select(t => t.Position); var collection = new SynchronizedCollection <VertexNode <T> >(); return(collection); }
public void crease(VertexNode v1, Vector3 p1) { step++; Vector3 midpoint = (v1.getPosition() + p1) / 2; Vector3 v = v1.getPosition() - p1; Vector3 n = camToModel; Plane p = new Plane(Vector3.Cross(v, n), midpoint); generateNewCreases(p); }
//print vertices public void PrintVertices() { Console.WriteLine("Printing the vertices ..."); // Writes out every node that meets the condition statement for (VertexNode current = start; current != null; current = current.nextVertex) { Console.WriteLine(current.Label); } }
public List <Edge> PrimsMST() { List <Edge> minimumSpanningTreeEdges = new List <Edge>(); // for output VertexNode[] vertexDistanceKeyTracker = new VertexNode[this.V]; Dictionary <int, VertexNode> hashTable = new Dictionary <int, VertexNode>(); //For others, make it infinite for (int i = 0; i < this.V; i++) { vertexDistanceKeyTracker[i] = new VertexNode(i, Int32.MaxValue, 0); hashTable.Add(i, vertexDistanceKeyTracker[i]); } vertexDistanceKeyTracker[0].Key = 0; vertexDistanceKeyTracker[0].Parent = -1; //start node distance key = zero, parent -1 //create new min heap to get minimum of all adjacent Heap <VertexNode> minHeap = new Heap <VertexNode>(vertexDistanceKeyTracker, HeapType.MinHeap); //Take v-1 edges, or v vertex while (!minHeap.IsEmpty()) { VertexNode minimumDistanceNode = minHeap.GetZeroIndexElement(); minHeap.RemoveZeroIndexElement(); //For output, add retrieved node with its parent if (minimumDistanceNode.Parent != -1) { minimumSpanningTreeEdges.Add(new Edge(minimumDistanceNode.Parent, minimumDistanceNode.Id, false, minimumDistanceNode.Key)); } int currentVertex = minimumDistanceNode.Id; foreach (var adjacentVertex in adj[currentVertex]) { VertexNode adjacentVertexNode = hashTable[adjacentVertex.Id]; if (minHeap.IsInHeap(adjacentVertexNode) && adjacentVertex.EdgeWeight < adjacentVertexNode.Key) { //To update parent, we will need node itself, not just id adjacentVertexNode.Parent = currentVertex; adjacentVertexNode.Key = adjacentVertex.EdgeWeight; // only equal //CRITICAL - Need to re heapify minHeap.UpdateHeapForChangedPriority(adjacentVertexNode); } } } return(minimumSpanningTreeEdges); }
//Find if this triangle contains a vert) public bool containsVertex(VertexNode _vert) { foreach (Edge aEdge in edgeList) { if (aEdge.getNode0() == _vert || aEdge.getNode1() == _vert) { return(true); } } return(false); }
public bool hasVertex(VertexNode vertex) { foreach (Edge edge in edges) { if (edge.getNode0() == vertex || edge.getNode1() == vertex) { return(true); } } return(false); }
// Clears all the elements that have been selected public void clearData() { v1 = null; v2 = null; e1 = null; e2 = null; p1 = new Vector3(9999, 9999, 9999); p2 = new Vector3(9999, 9999, 9999); Destroy(po1); Destroy(po2); }
public BreadthFirstSearch(DiGraph g, int s) { nodes = new VertexNode[g.V]; for (int i = 0; i < nodes.Length; i++) { nodes[i] = new VertexNode(i); nodes[i].Color = VertexColor.White; } bfs(g, s); }
private void findNext() { VertexNode oldNode = null; VertexNode closesNode = null; float closesDistance = 0; foreach (VertexNode aNode1 in nodesInTree) { List <VertexNode> connectedNodes = (List <VertexNode>)vertexTable[aNode1]; foreach (VertexNode aNode in connectedNodes) { if (!nodesInTree.Contains(aNode)) { float tempDst = Vector2.Distance(aNode.getParentCell().transform.position, aNode1.getParentCell().transform.position); if (closesNode != null) { if (tempDst < closesDistance) { closesDistance = tempDst; closesNode = aNode; oldNode = aNode1; } } else { closesNode = aNode; closesDistance = tempDst; oldNode = aNode1; } } } } nodesInTree.Add(closesNode); foreach (Edge aEdge in allEdges) { if (aEdge.edgeContainsVertex(oldNode) && aEdge.edgeContainsVertex(closesNode)) { edgesInTree.Add(aEdge); } } if (nodesInTree.Count == allNodes.Count) { return; } else { findNext(); } }
// Creates the gameObjects necessary to visualize the model public void createVertexObject(VertexNode v) { GameObject vertex = GameObject.CreatePrimitive(PrimitiveType.Sphere); vertex.AddComponent <VertexObject>(); vertex.transform.Translate(v.getPosition()); vertex.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f); vertex.GetComponent <VertexObject>().v = v; vertex.GetComponent <VertexObject>().c = this; plot.Add(vertex.GetComponent <VertexObject>()); }
/// <summary> /// 获取边在顶点所有边中的序号 /// </summary> /// <param name="vn">顶点</param> /// <param name="e">边</param> public int GetEdgeNumber(VertexNode vn, Edge e) { EdgeNode p = vn.FirstEdge; int which = 0; while (p != null && p.EdgeLink != e) { p = p.Next; which++; } return(which); }
// Given a vertex if folds it toa given point public void pull(VertexNode v1, Vector3 p1) { step++; Plane p = createSymmetryPlane(v1, p1); generateNewFlapCreases(p, v1); //generateNewCreases(p); List <VertexNode> aV = new List <VertexNode>(); aV.Add(v1); applySymetry(p, aV); unfoldCount = 0; }
public double y; // Y coordinate component #endregion Fields #region Constructors public VertexNode( double x, double y ) { this.x = x ; this.y = y ; this.next = null ; }
/// <summary> /// Return a tree that contains 4 trapezoids /// </summary> /// <param name="segment"></param> /// <returns></returns> public Node To4Traps(Segment segment) { // Vertex nodes Node root = new VertexNode(segment.LeftVertex); Node rightVertexNode = new VertexNode(segment.RightVertex); // Segment node Node segmentNode = new SegmentNode(segment); // Trapezoid nodes Trapezoid leftTrap = new Trapezoid(Trapezoid.Leftp, segment.LeftVertex, Trapezoid.Top, Trapezoid.Bottom); Trapezoid higherCenterTrap = new Trapezoid(segment.LeftVertex, segment.RightVertex, Trapezoid.Top, segment); Trapezoid lowerCenterTrap = new Trapezoid(segment.LeftVertex, segment.RightVertex, segment, Trapezoid.Bottom); Trapezoid rightTrap = new Trapezoid(segment.RightVertex, Trapezoid.Rightp, Trapezoid.Top, Trapezoid.Bottom); Node leftTrapNode = new TrapezoidalNode(leftTrap); Node higherCenterTrapNode = new TrapezoidalNode(higherCenterTrap); Node lowerCenterTrapNode = new TrapezoidalNode(lowerCenterTrap); Node rightTrapNode = new TrapezoidalNode(rightTrap); leftTrap.SetNeighbor(Trapezoid.HigherLeftNeighbor, Trapezoid.LowerLeftNeighbor, higherCenterTrap, lowerCenterTrap); leftTrap.Node = leftTrapNode; higherCenterTrap.SetNeighbor(leftTrap, leftTrap, rightTrap, rightTrap); higherCenterTrap.Node = higherCenterTrapNode; lowerCenterTrap.SetNeighbor(leftTrap, leftTrap, rightTrap, rightTrap); lowerCenterTrap.Node = lowerCenterTrapNode; rightTrap.SetNeighbor(higherCenterTrap, lowerCenterTrap, Trapezoid.HigherRightNeighbor, Trapezoid.LowerRightNeighbor); rightTrap.Node = rightTrapNode; segmentNode.SetChildren(ref higherCenterTrapNode, ref lowerCenterTrapNode); rightVertexNode.SetChildren(ref segmentNode, ref rightTrapNode); root.SetChildren(ref leftTrapNode,ref rightVertexNode); return root; }
public void add_right( double x, double y ) { VertexNode nv = new VertexNode( x, y ); /* Add vertex nv to the right end of the polygon's vertex list */ proxy.v[RIGHT].next= nv; /* Update proxy->v[RIGHT] to point to nv */ proxy.v[RIGHT]= nv; }
public VertexNode[] v = new VertexNode[2] ; /* Left and right vertex list ptrs */ #endregion Fields #region Constructors public PolygonNode( PolygonNode next, double x, double y ) { /* Make v[LEFT] and v[RIGHT] point to new vertex */ VertexNode vn = new VertexNode( x, y ); this.v[LEFT ] = vn ; this.v[RIGHT] = vn ; this.next = next ; this.proxy = this ; /* Initialise proxy to point to p itself */ this.active = 1 ; //TRUE }
public void add_left( double x, double y) { VertexNode nv = new VertexNode( x, y ); /* Add vertex nv to the left end of the polygon's vertex list */ nv.next= proxy.v[LEFT]; /* Update proxy->[LEFT] to point to nv */ proxy.v[LEFT]= nv; }
public readonly VertexNode Vertex; //结点指向的顶点 #endregion Fields #region Constructors public AdjacencyNode(VertexNode vertex, AdjacencyNode next) { this.Vertex = vertex; this.Next = next; }
//深度优先遍历顶点 void DepthFirstSearchVertex(VertexNode vertex) { if (vertex == null || vertex.Visited) return; Console.Write(vertex.City + "\t"); vertex.Visited = true; AdjacencyNode node = vertex.FirstNode; //第一个邻接结点 while (node != null) { DepthFirstSearchVertex(node.Vertex); node = node.Next; } }