public BombA(IndexPair indexPair) { IsTaken = false; this.indexPair = indexPair; isoPoint = IsometricExtensionMethods.IndexesToCorrdinates(indexPair).TwoDimensionsToIso(); isoPoint.X += 15; isoPoint.Y += 15; }
public CoinGift(IndexPair indexPair) { this.indexPair = indexPair; IsTaken = false; isoPoint = IsometricExtensionMethods.IndexesToCorrdinates(indexPair).TwoDimensionsToIso(); isoPoint.X += 10; isoPoint.Y += 10; }
public void Initialize() { playerCoordinates = MapLoader.PlayerStartLocation; playerAnimation = (PlayerAnimation)AnimationFactory.CreateEmpyAnimation(AnimationType.PlayerAnimation); // Initialize the player location to the top of the screen playerAnimation.AnimationPosition = playerCoordinates.IndexesToCorrdinates(); playerAnimation.Collider.Collided += Collider_Collided; Direction = Directions.Right; }
// The singleton public void Initialize() { projectiles = new List<IWeapon>(numberOfProjectiles); // Create normal weapon spawns for (int i = 0; i < numberOfProjectiles - 3; i++) { projectiles.Add(new ProjectileClassAlpha()); projectiles[i].Used = false; } weaponIndexes = new IndexPair(0, numberOfProjectiles - 3); // Create super weapon spawns for (int i = numberOfProjectiles - 3; i < numberOfProjectiles - 1; i++) { projectiles.Add(new ProjectileClassBeta()); projectiles[i].Used = false; } superWeaponIndexes = new IndexPair(numberOfProjectiles - 3, numberOfProjectiles - 1); }
public Monster(IndexPair startPoint, IndexPair endPoint) { increasing = true; counter = 0; AnimationFactory factory = new AnimationFactory(); IndexPair temp = startPoint; myPath = new PathFinder(new RouteInformation(startPoint, endPoint)); tempPath = myPath.FindPath(); timer.Elapsed += Timer_Elapsed; timer.Enabled = true; timer.Interval = 250; //MapLoader.MonsterStartLocation; //monsterAnimation.AnimationTileIndex = new IndexPair(1, 1);//temp.TileIndecies; monsterAnimation = (MonsterAnimation)factory.CreateAnimation(AnimationType.MonsterAnimation, tempPath[0]); monsterAnimation.AnimationPosition = temp.IndexesToCorrdinates(); // TODO set Monster start position at game start. TODO set Monster Direction at game start. monsterAnimation.Collider.Collided += Monster_Collided; }
// function to convert rhino mesh to spring mesh public void ConvertToSpringMesh() { bool[] naked = iRhinoMesh.GetNakedEdgePointStatus(); for (int i = 0; i < iRhinoMesh.Vertices.Count; i++) { Point3d vertex = iRhinoMesh.Vertices[i]; oSpringMesh.Vertices.Add(new Vertex(vertex, Vector3d.Zero, new List <int>())); // boundary and fixed condition if (naked[i] == true) { oSpringMesh.Vertices[i].IsBoundaryVertex = true; oSpringMesh.Vertices[i].IsFixed = true; } // vertex neighbours int topoIndex = iRhinoMesh.TopologyVertices.TopologyVertexIndex(i); int[] connectIndex = iRhinoMesh.TopologyVertices.ConnectedTopologyVertices(topoIndex); for (int j = 0; j < connectIndex.Length; j++) { oSpringMesh.Vertices[i].NeighborVertexIndices.Add(iRhinoMesh.TopologyVertices.MeshVertexIndices(connectIndex[j])[0]); } // } foreach (MeshFace face in iRhinoMesh.Faces) { oSpringMesh.Triangles.Add(new Triangle(face.A, face.B, face.C)); } for (int i = 0; i < iRhinoMesh.TopologyEdges.Count; i++) { IndexPair indexPair = iRhinoMesh.TopologyEdges.GetTopologyVertices(i); // should convert TopologyVertices to mesh vertices first int firstIndex = iRhinoMesh.TopologyVertices.MeshVertexIndices(indexPair.I)[0]; int secondIndex = iRhinoMesh.TopologyVertices.MeshVertexIndices(indexPair.J)[0]; double len = iRhinoMesh.TopologyEdges.EdgeLine(i).Length; oSpringMesh.Edges.Add(new Edge(firstIndex, secondIndex, len, 1.0, Math.PI * 0.8, 0.0)); // edge vertex oSpringMesh.Edges[i].FirstVertexIndex = firstIndex; oSpringMesh.Edges[i].SecondVertexIndex = secondIndex; } for (int i = 0; i < iRhinoMesh.TopologyEdges.Count; i++) { // connected faces int[] connectedFacesIndex = iRhinoMesh.TopologyEdges.GetConnectedFaces(i); int firstTriIndex = -1; int secondTriIndex = -1; IndexPair indexPair = iRhinoMesh.TopologyEdges.GetTopologyVertices(i); int firstIndex = iRhinoMesh.TopologyVertices.MeshVertexIndices(indexPair.I)[0]; int secondIndex = iRhinoMesh.TopologyVertices.MeshVertexIndices(indexPair.J)[0]; if (connectedFacesIndex.Length == 2) { firstTriIndex = connectedFacesIndex[0]; oSpringMesh.Edges[i].FirstTriangleIndex = firstTriIndex; secondTriIndex = connectedFacesIndex[1]; oSpringMesh.Edges[i].SecondTriangleIndex = secondTriIndex; int triangleAdj01 = 0; int triangleAdj02 = 0; int vertex01 = oSpringMesh.Triangles[firstTriIndex].FirstVertexIndex; int vertex02 = oSpringMesh.Triangles[firstTriIndex].SecondVertexIndex; int vertex03 = oSpringMesh.Triangles[firstTriIndex].ThirdVertexIndex; int vertex11 = oSpringMesh.Triangles[secondTriIndex].FirstVertexIndex; int vertex12 = oSpringMesh.Triangles[secondTriIndex].SecondVertexIndex; int vertex13 = oSpringMesh.Triangles[secondTriIndex].ThirdVertexIndex; int[] triangleVertexList01 = { vertex01, vertex02, vertex03 }; int[] triangleVertexList02 = { vertex11, vertex12, vertex13 }; for (int j = 0; j < triangleVertexList01.Length; j++) { if (triangleVertexList01[j] != firstIndex && triangleVertexList01[j] != secondIndex) { triangleAdj01 = triangleVertexList01[j]; } } for (int j = 0; j < triangleVertexList02.Length; j++) { if (triangleVertexList02[j] != firstIndex && triangleVertexList02[j] != secondIndex) { triangleAdj02 = triangleVertexList02[j]; } } oSpringMesh.Edges[i].FirstAdjacentVertexIndex = triangleAdj01; oSpringMesh.Edges[i].SecondAdjacentVertexIndex = triangleAdj02; oSpringMesh.Edges[i].IsBoundaryEdge = false; // triangle edge and triangle if (triangleAdj01 == vertex01) { oSpringMesh.Triangles[firstTriIndex].FirstEdgeIndex = i; oSpringMesh.Triangles[firstTriIndex].FirstAdjTriIndex = secondTriIndex; } if (triangleAdj01 == vertex02) { oSpringMesh.Triangles[firstTriIndex].SecondEdgeIndex = i; oSpringMesh.Triangles[firstTriIndex].SecondAdjTriIndex = secondTriIndex; } if (triangleAdj01 == vertex03) { oSpringMesh.Triangles[firstTriIndex].ThirdEdgeIndex = i; oSpringMesh.Triangles[firstTriIndex].ThirdAdjTriIndex = secondTriIndex; } if (triangleAdj02 == vertex11) { oSpringMesh.Triangles[secondTriIndex].FirstEdgeIndex = i; oSpringMesh.Triangles[secondTriIndex].FirstAdjTriIndex = firstTriIndex; } if (triangleAdj02 == vertex12) { oSpringMesh.Triangles[secondTriIndex].SecondEdgeIndex = i; oSpringMesh.Triangles[secondTriIndex].SecondAdjTriIndex = firstTriIndex; } if (triangleAdj02 == vertex13) { oSpringMesh.Triangles[secondTriIndex].ThirdEdgeIndex = i; oSpringMesh.Triangles[secondTriIndex].ThirdAdjTriIndex = firstTriIndex; } } if (connectedFacesIndex.Length == 1) { firstTriIndex = connectedFacesIndex[0]; oSpringMesh.Edges[i].FirstTriangleIndex = firstTriIndex; int triangleAdj01 = 0; int vertex01 = oSpringMesh.Triangles[firstTriIndex].FirstVertexIndex; int vertex02 = oSpringMesh.Triangles[firstTriIndex].SecondVertexIndex; int vertex03 = oSpringMesh.Triangles[firstTriIndex].ThirdVertexIndex; int[] triangleVertexList01 = { vertex01, vertex02, vertex03 }; for (int j = 0; j < triangleVertexList01.Length; j++) { if (triangleVertexList01[j] != firstIndex && triangleVertexList01[j] != secondTriIndex) { triangleAdj01 = triangleVertexList01[j]; } } oSpringMesh.Edges[i].FirstAdjacentVertexIndex = triangleAdj01; oSpringMesh.Edges[i].IsBoundaryEdge = true; // triangle edge if (triangleAdj01 == vertex01) { oSpringMesh.Triangles[firstTriIndex].FirstEdgeIndex = i; } if (triangleAdj01 == vertex02) { oSpringMesh.Triangles[firstTriIndex].SecondEdgeIndex = i; } if (triangleAdj01 == vertex03) { oSpringMesh.Triangles[firstTriIndex].ThirdEdgeIndex = i; } } } // visualize springMesh foreach (Edge edge in oSpringMesh.Edges) { oSMeshLine.Add(new LineCurve(oSpringMesh.Vertices[edge.FirstVertexIndex].Position, oSpringMesh.Vertices[edge.SecondVertexIndex].Position)); } }
protected override void SolveInstance(IGH_DataAccess DA) { Mesh iRhinoMesh = null; DA.GetData <Mesh>(0, ref iRhinoMesh); SpringMesh oSpringMesh = new SpringMesh(); bool [] naked = iRhinoMesh.GetNakedEdgePointStatus(); for (int i = 0; i < iRhinoMesh.Vertices.Count; i++) { Point3d vertex = iRhinoMesh.Vertices[i]; oSpringMesh.Vertices.Add(new Vertex(vertex, Vector3d.Zero, new List <int>())); // boundary and fixed condition if (naked[i] == true) { oSpringMesh.Vertices[i].IsBoundaryVertex = true; oSpringMesh.Vertices[i].IsFixed = true; } // vertex neighbours int topoIndex = iRhinoMesh.TopologyVertices.TopologyVertexIndex(i); int[] connectIndex = iRhinoMesh.TopologyVertices.ConnectedTopologyVertices(topoIndex); for (int j = 0; j < connectIndex.Length; j++) { oSpringMesh.Vertices[i].NeighborVertexIndices.Add(iRhinoMesh.TopologyVertices.MeshVertexIndices(connectIndex[j])[0]); } } foreach (MeshFace face in iRhinoMesh.Faces) { oSpringMesh.Triangles.Add(new Triangle(face.A, face.B, face.C)); } for (int i = 0; i < iRhinoMesh.TopologyEdges.Count; i++) { IndexPair indexPair = iRhinoMesh.TopologyEdges.GetTopologyVertices(i); // should convert TopologyVertices to mesh vertices first int firstIndex = iRhinoMesh.TopologyVertices.MeshVertexIndices(indexPair.I)[0]; int secondIndex = iRhinoMesh.TopologyVertices.MeshVertexIndices(indexPair.J)[0]; double len = iRhinoMesh.TopologyEdges.EdgeLine(i).Length; oSpringMesh.Edges.Add(new Edge(firstIndex, secondIndex, len, 1.0, Math.PI * 0.8, 0.0)); // edge vertex oSpringMesh.Edges[i].FirstVertexIndex = firstIndex; oSpringMesh.Edges[i].SecondVertexIndex = secondIndex; } for (int i = 0; i < iRhinoMesh.TopologyEdges.Count; i++) { // connected faces int[] connectedFacesIndex = iRhinoMesh.TopologyEdges.GetConnectedFaces(i); int firstTriIndex = -1; int secondTriIndex = -1; IndexPair indexPair = iRhinoMesh.TopologyEdges.GetTopologyVertices(i); int firstIndex = iRhinoMesh.TopologyVertices.MeshVertexIndices(indexPair.I)[0]; int secondIndex = iRhinoMesh.TopologyVertices.MeshVertexIndices(indexPair.J)[0]; if (connectedFacesIndex.Length == 2) { firstTriIndex = connectedFacesIndex[0]; oSpringMesh.Edges[i].FirstTriangleIndex = firstTriIndex; secondTriIndex = connectedFacesIndex[1]; oSpringMesh.Edges[i].SecondTriangleIndex = secondTriIndex; int triangleAdj01 = 0; int triangleAdj02 = 0; int vertex01 = oSpringMesh.Triangles[firstTriIndex].FirstVertexIndex; int vertex02 = oSpringMesh.Triangles[firstTriIndex].SecondVertexIndex; int vertex03 = oSpringMesh.Triangles[firstTriIndex].ThirdVertexIndex; int vertex11 = oSpringMesh.Triangles[secondTriIndex].FirstVertexIndex; int vertex12 = oSpringMesh.Triangles[secondTriIndex].SecondVertexIndex; int vertex13 = oSpringMesh.Triangles[secondTriIndex].ThirdVertexIndex; int[] triangleVertexList01 = { vertex01, vertex02, vertex03 }; int[] triangleVertexList02 = { vertex11, vertex12, vertex13 }; for (int j = 0; j < triangleVertexList01.Length; j++) { if (triangleVertexList01[j] != firstIndex && triangleVertexList01[j] != secondIndex) { triangleAdj01 = triangleVertexList01[j]; } } for (int j = 0; j < triangleVertexList02.Length; j++) { if (triangleVertexList02[j] != firstIndex && triangleVertexList02[j] != secondIndex) { triangleAdj02 = triangleVertexList02[j]; } } oSpringMesh.Edges[i].FirstAdjacentVertexIndex = triangleAdj01; oSpringMesh.Edges[i].SecondAdjacentVertexIndex = triangleAdj02; oSpringMesh.Edges[i].IsBoundaryEdge = false; } if (connectedFacesIndex.Length == 1) { firstTriIndex = connectedFacesIndex[0]; oSpringMesh.Edges[i].FirstTriangleIndex = firstTriIndex; int triangleAdj01 = 0; int vertex01 = oSpringMesh.Triangles[firstTriIndex].FirstVertexIndex; int vertex02 = oSpringMesh.Triangles[firstTriIndex].SecondVertexIndex; int vertex03 = oSpringMesh.Triangles[firstTriIndex].ThirdVertexIndex; int[] triangleVertexList01 = { vertex01, vertex02, vertex03 }; for (int j = 0; j < triangleVertexList01.Length; j++) { if (triangleVertexList01[j] != firstIndex && triangleVertexList01[j] != secondTriIndex) { triangleAdj01 = triangleVertexList01[j]; } } oSpringMesh.Edges[i].FirstAdjacentVertexIndex = triangleAdj01; oSpringMesh.Edges[i].IsBoundaryEdge = true; } } DA.SetData(1, oSpringMesh); List <LineCurve> oDebugCurves = new List <LineCurve>(); foreach (Edge edge in oSpringMesh.Edges) { oDebugCurves.Add(new LineCurve(oSpringMesh.Vertices[edge.FirstVertexIndex].Position, oSpringMesh.Vertices[edge.SecondVertexIndex].Position)); } DA.SetDataList(0, oDebugCurves); }
public Wrapper(int[,] level, IndexPair playerLocation) { this.level = level; MonsterLocations = new Dictionary <IndexPair, IndexPair>(); this.playerLocation = playerLocation; }
public static void createIndexForType(string t, int i) { IndexPair obj = new IndexPair(t, i); Generator.registerIndexType(obj); }
/// <summary> /// Removes duplicate/invalid/tiny curves and outputs the cleaned list, a list of unique nodes and a list of node pairs. /// </summary> public static List <Curve> CleanNetwork(List <Curve> inputStruts, double tol, out Point3dList nodes, out List <IndexPair> nodePairs) { nodes = new Point3dList(); nodePairs = new List <IndexPair>(); var struts = new List <Curve>(); // Loop over list of struts for (int i = 0; i < inputStruts.Count; i++) { Curve strut = inputStruts[i]; // Unitize domain strut.Domain = new Interval(0, 1); // Minimum strut length (if user defined very small tolerance, use 100*rhinotolerance) double minLength = Math.Max(tol, 100 * RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); // If strut is invalid, ignore it if (strut == null || !strut.IsValid || strut.IsShort(minLength)) { continue; } Point3d[] pts = new Point3d[2] { strut.PointAtStart, strut.PointAtEnd }; List <int> nodeIndices = new List <int>(); // Loop over end points of strut // Check if node is already in nodes list, if so, we find its index instead of creating a new node for (int j = 0; j < 2; j++) { Point3d pt = pts[j]; // Find closest node to current pt int closestIndex = nodes.ClosestIndex(pt); // If node already exists (within tolerance), set the index if (nodes.Count != 0 && pt.EpsilonEquals(nodes[closestIndex], tol)) { nodeIndices.Add(closestIndex); } // If node doesn't exist else { // Update lookup list nodes.Add(pt); nodeIndices.Add(nodes.Count - 1); } } // We must ignore duplicate struts bool isDuplicate = false; IndexPair nodePair = new IndexPair(nodeIndices[0], nodeIndices[1]); int dupIndex = nodePairs.IndexOf(nodePair); // dupIndex equals -1 if nodePair not found, i.e. if it doesn't equal -1, a match was found if (nodePairs.Count != 0 && dupIndex != -1) { // Check the curve midpoint to make sure it's a duplicate Curve testStrut = struts[dupIndex]; Point3d ptA = strut.PointAt(0.5); Point3d ptB = testStrut.PointAt(0.5); if (ptA.EpsilonEquals(ptB, tol)) { isDuplicate = true; } } // So we only create the strut if it doesn't exist yet (check nodePairLookup list) if (!isDuplicate) { // Update the lookup list nodePairs.Add(nodePair); strut.Domain = new Interval(0, 1); struts.Add(strut); } } return(struts); }
public static BondResult IndexDocument(string docPath, string cabinet = "", string client = "", string status = "", string sender = "", string section = "", string desc = "", string docDate = null, IndexPair additionalIndex1 = null, IndexPair additionalIndex2 = null) { try { if (docDate == null) { docDate = DateTime.Now.ToString("dd/MM/yyyy"); } string commandFile = BuildCommandFile(docPath, cabinet, client, status, sender, section, desc, docDate, additionalIndex1, additionalIndex2); BondResult result = LaunchCabi(commandFile, false); result.DocPath = docPath; return(result); } catch (Exception ex) { XLtools.LogException("XLVC-IndexDocument", ex.ToString()); return(new BondResult()); } }
public static void registerIndexType(IndexPair arg) { Generator.IndStorage.Add(arg); }
public static bool IsWalkable(IndexPair pair) { return(level[pair.I, pair.J] == 0 ? true : false); }
public override CRS Jacobian(CMesh cm) { // 等長拘束をかける辺の数取得 int n = equal_fold_angle_edge_id.Count; List <double> var = new List <double>(); List <int> rind = new List <int>(); List <int> cind = new List <int>(); List <Point3d> verts = new List <Point3d>(cm.mesh.Vertices.ToPoint3dArray()); Mesh m = cm.mesh; m.FaceNormals.ComputeFaceNormals(); // メッシュの TopologyEdges 取得 MeshTopologyEdgeList topo_edges = m.TopologyEdges; for (int i = 0; i < n; i++) { // Register indices int edge_index = equal_fold_angle_edge_id[i]; IndexPair edge_ind = topo_edges.GetTopologyVertices(edge_index); int u = edge_ind.I; int v = edge_ind.J; IndexPair face_ind = cm.face_pairs[edge_index]; int P = face_ind[0]; int Q = face_ind[1]; MeshFace face_P = m.Faces[P]; MeshFace face_Q = m.Faces[Q]; int p = 0; int q = 0; for (int j = 0; j < 3; j++) { if (!edge_ind.Contains(face_P[j])) { p = face_P[j]; } if (!edge_ind.Contains(face_Q[j])) { q = face_Q[j]; } } /// Compute normals Vector3d normal_P = m.FaceNormals[P]; Vector3d normal_Q = m.FaceNormals[Q]; /// Compute h_P & cot_Pu Vector3d vec_up = verts[p] - verts[u]; Vector3d vec_uv = verts[v] - verts[u]; double sin_Pu = (Vector3d.CrossProduct(vec_up, vec_uv) / (vec_up.Length * vec_uv.Length)).Length; double cos_Pu = (vec_up * vec_uv) / (vec_up.Length * vec_uv.Length); double cot_Pu = cos_Pu / sin_Pu; double len_up = vec_up.Length; double h_P = len_up * sin_Pu; /// Compute cot_Pv Vector3d vec_vp = verts[p] - verts[v]; Vector3d vec_vu = verts[u] - verts[v]; double sin_Pv = (Vector3d.CrossProduct(vec_vp, vec_vu) / (vec_vp.Length * vec_vu.Length)).Length; double cos_Pv = (vec_vp * vec_vu) / (vec_vp.Length * vec_vu.Length); double cot_Pv = cos_Pv / sin_Pv; /// Compute h_Q & cot_Qu Vector3d vec_uq = verts[q] - verts[u]; double sin_Qu = (Vector3d.CrossProduct(vec_uq, vec_uv) / (vec_uq.Length * vec_uv.Length)).Length; double cos_Qu = (vec_uq * vec_uv) / (vec_uq.Length * vec_uv.Length); double cot_Qu = cos_Qu / sin_Qu; double len_uq = vec_uq.Length; double h_Q = len_uq * sin_Qu; /// Compute cot_Qv Vector3d vec_vq = verts[q] - verts[v]; double sin_Qv = (Vector3d.CrossProduct(vec_vq, vec_vu) / (vec_vq.Length * vec_vu.Length)).Length; double cos_Qv = vec_vq * vec_vu / (vec_vq.Length * vec_vu.Length); double cot_Qv = cos_Qv / sin_Qv; List <double> normal_P_list = new List <double>(); List <double> normal_Q_list = new List <double>(); normal_P_list.Add(normal_P.X); normal_P_list.Add(normal_P.Y); normal_P_list.Add(normal_P.Z); normal_Q_list.Add(normal_Q.X); normal_Q_list.Add(normal_Q.Y); normal_Q_list.Add(normal_Q.Z); /// Compute coefficients double co_pv = (-1 * cot_Pv) / (cot_Pu + cot_Pv); double co_qv = (-1 * cot_Qv) / (cot_Qu + cot_Qv); double co_pu = (-1 * cot_Pu) / (cot_Pu + cot_Pv); double co_qu = (-1 * cot_Qu) / (cot_Qu + cot_Qv); /// Compute Jacobian for (int v_ind = 0; v_ind < verts.Count; v_ind++) { if (v_ind == p) { for (int x = 0; x < 3; x++) { var.Add((normal_P_list[x] / (h_P))); cind.Add(3 * v_ind + x); rind.Add(i); } } if (v_ind == q) { for (int x = 0; x < 3; x++) { var.Add((normal_Q_list[x] / (h_Q))); cind.Add(3 * v_ind + x); rind.Add(i); } } if (v_ind == u) { for (int x = 0; x < 3; x++) { var.Add(((co_pv * (normal_P_list[x] / h_P) + co_qv * (normal_Q_list[x] / h_Q)))); cind.Add(3 * v_ind + x); rind.Add(i); } } if (v_ind == v) { for (int x = 0; x < 3; x++) { var.Add(((co_pu * (normal_P_list[x] / h_P) + co_qu * (normal_Q_list[x] / h_Q)))); cind.Add(3 * v_ind + x); rind.Add(i); } } } } CRS Jaco = new CRS(var, rind, cind, n, verts.Count * 3); return(Jaco); }
public Mesh Loop(Mesh x) { Mesh mesh = new Mesh(); x.Faces.ConvertQuadsToTriangles(); List <Point3d> pv = new List <Point3d>(); List <Point3d> pe = new List <Point3d>(); Rhino.Geometry.Collections.MeshTopologyVertexList vs = x.TopologyVertices; Rhino.Geometry.Collections.MeshTopologyEdgeList el = x.TopologyEdges; for (int i = 0; i < el.Count; i++) { IndexPair pair = el.GetTopologyVertices(i); Point3d pe1 = (vs[pair.I] + vs[pair.J]); int[] index = el.GetConnectedFaces(i); if (index.Length == 2) { int[] index1 = vs.IndicesFromFace(index[0]); int[] index2 = vs.IndicesFromFace(index[1]); pe1 += vs[index1[0]] + vs[index1[1]] + vs[index1[2]]; pe1 += vs[index2[0]] + vs[index2[1]] + vs[index2[2]]; pe1 /= 8.0; } else { pe1 = pe1 / 2.0; } pe.Add(pe1); } for (int i = 0; i < vs.Count; i++) { int[] index = vs.ConnectedEdges(i); int[] index2 = vs.ConnectedFaces(i); Point3d V = vs[i]; if (index.Length == index2.Length) { Point3d R = new Point3d(); double n = (double)index.Length; double u = Math.Pow(0.375 + 0.25 * Math.Cos(Math.PI * 2.0 / n), 2); u = (0.625 - u) / n; for (int j = 0; j < index.Length; j++) { IndexPair pair = el.GetTopologyVertices(index[j]); R += (vs[pair.I] + vs[pair.J] - V); } V = V * (1 - n * u) + R * u; } else { Point3d R = new Point3d(); for (int j = 0; j < index.Length; j++) { if (el.GetConnectedFaces(index[j]).Length == 1) { IndexPair pair = el.GetTopologyVertices(index[j]); R += vs[pair.I] + vs[pair.J]; } } V = R * 0.125f + V * 0.5; } pv.Add(V); } mesh.Vertices.AddVertices(pv); mesh.Vertices.AddVertices(pe); for (int i = 0; i < x.Faces.Count; i++) { int[] index = vs.IndicesFromFace(i); int p1 = index[0]; int p2 = index[1]; int p3 = index[2]; int p12 = el.GetEdgeIndex(p1, p2) + pv.Count; int p23 = el.GetEdgeIndex(p2, p3) + pv.Count; int p31 = el.GetEdgeIndex(p3, p1) + pv.Count; mesh.Faces.AddFace(p1, p12, p31); mesh.Faces.AddFace(p31, p12, p23); mesh.Faces.AddFace(p3, p31, p23); mesh.Faces.AddFace(p2, p23, p12); } mesh.UnifyNormals(); return(mesh); }
public static void ReadLevelFile(string folderPath) { int rows = -1; int cols = -1; int[,] level; IndexPair playerPosition; int monstersCount = -1; EscapeRunner.View.MapLoader.Monster[] monsters; int bombsCount = -1; EscapeRunner.View.MapLoader.StaticObject[] bombs; int coinsCount = -1; EscapeRunner.View.MapLoader.StaticObject[] coins; int bulletsCount = -1; EscapeRunner.View.MapLoader.StaticObject[] bullets; StreamReader reader = new StreamReader(folderPath); /*string json = reader.ReadToEnd(); * * var things = JsonConvert.DeserializeObject(json, new JsonSerializerSettings() * { * TypeNameHandling = TypeNameHandling.None * }); * * Wrapper wrapper = (Wrapper)things; * * Debugger.Break();*/ // read player position string line = reader.ReadLine(); if (line != null) { int[] points = Array.ConvertAll(line.Substring(24, (line.Length - 26)).Split(','), s => int.Parse(s)); playerPosition = new IndexPair(points[0], points[1]); MapLoader.PlayerStartLocation = playerPosition; } line = reader.ReadLine(); // read monsters count line = reader.ReadLine(); if (line != null) { monstersCount = Convert.ToInt32(line.Substring(20, (line.Length - 21))); } line = reader.ReadLine(); // read monsters locations if (monstersCount > 0) { line = reader.ReadLine(); monsters = new Monster[monstersCount]; int counter = 0; while ((line = reader.ReadLine()) != null) { if (counter < monstersCount) { line = line.Substring(2, (line.Length - 3)); if (counter != (monstersCount - 1)) { line = line.Substring(0, (line.Length - 2)); } int[] points = Array.ConvertAll(line.Split(','), s => int.Parse(s)); Point start = new Point(points[0], points[1]); Point end = new Point(points[2], points[3]); monsters[counter] = new Monster(start, end); counter++; } else { break; } } MapLoader.MonstersCount = monstersCount; MapLoader.Monsters = monsters; } line = reader.ReadLine(); // read bombs locations line = reader.ReadLine(); if (line != null) { bombsCount = Convert.ToInt32(line.Substring(17, (line.Length - 18))); } line = reader.ReadLine(); if (bombsCount > 0) { line = reader.ReadLine(); bombs = new StaticObject[bombsCount]; int counter = 0; while ((line = reader.ReadLine()) != null) { if (counter < bombsCount) { line = line.Substring(2, (line.Length - 3)); if (counter != (bombsCount - 1)) { line = line.Substring(0, (line.Length - 2)); } int[] points = Array.ConvertAll(line.Split(','), s => int.Parse(s)); Point start = new Point(points[0], points[1]); bombs[counter] = new StaticObject(start); counter++; } else { break; } } MapLoader.BombsCount = bombsCount; MapLoader.Bombs = bombs; } line = reader.ReadLine(); // read coins locations line = reader.ReadLine(); if (line != null) { coinsCount = Convert.ToInt32(line.Substring(17, (line.Length - 18))); } line = reader.ReadLine(); if (coinsCount > 0) { line = reader.ReadLine(); coins = new StaticObject[coinsCount]; int counter = 0; while ((line = reader.ReadLine()) != null) { if (counter < coinsCount) { line = line.Substring(2, (line.Length - 3)); if (counter != (coinsCount - 1)) { line = line.Substring(0, (line.Length - 2)); } int[] points = Array.ConvertAll(line.Split(','), s => int.Parse(s)); Point start = new Point(points[0], points[1]); coins[counter] = new StaticObject(start); counter++; } else { break; } } MapLoader.CoinsCount = coinsCount; MapLoader.Coins = coins; } line = reader.ReadLine(); // read bullets locations line = reader.ReadLine(); if (line != null) { bulletsCount = Convert.ToInt32(line.Substring(19, (line.Length - 20))); } line = reader.ReadLine(); if (coinsCount > 0) { line = reader.ReadLine(); bullets = new StaticObject[bulletsCount]; int counter = 0; while ((line = reader.ReadLine()) != null) { if (counter < bulletsCount) { line = line.Substring(2, (line.Length - 3)); if (counter != (bulletsCount - 1)) { line = line.Substring(0, (line.Length - 2)); } int[] points = Array.ConvertAll(line.Split(','), s => int.Parse(s)); Point start = new Point(points[0], points[1]); bullets[counter] = new StaticObject(start); counter++; } else { break; } } MapLoader.BulletsCount = bulletsCount; MapLoader.Bullets = bullets; } line = reader.ReadLine(); // read map dimensions line = reader.ReadLine(); if (line != null) { cols = Convert.ToInt32(line.Substring(10, (line.Length - 11))); } line = reader.ReadLine(); if (line != null) { rows = Convert.ToInt32(line.Substring(10, (line.Length - 11))); } // read level if (rows > 0 && cols > 0) { line = reader.ReadLine(); line = reader.ReadLine(); level = new int[rows, cols]; int counter = 0; while ((line = reader.ReadLine()) != null) { if (counter < rows) { line = line.Substring(2, (line.Length - 3)); if (counter != (rows - 1)) { line = line.Substring(0, (line.Length - 2)); } int counter2 = 0; string[] lines = line.Split(','); foreach (var item in lines) { if (counter2 < cols) { level[counter, counter2++] = int.Parse(item); } } counter++; //level[counter++] = Array.ConvertAll(line.Split(','), s => int.Parse(s)); } else { break; } } MapLoader.level = level; } reader.Close(); }
public Wrapper(int[,] level, IndexPair playerLocation, Dictionary <IndexPair, IndexPair> MonsterLocations) { this.level = level; this.MonsterLocations = MonsterLocations; this.playerLocation = playerLocation; }
public static FileInfo FileIndex(string fileID, bool current = true) { try { FileInfo file = new FileInfo(); if (fileID != null) { DataTable xlReader = new DataTable(); if (current) { xlReader = XLSQL.ReturnTable("Select TOP(1) * from [XLant].[dbo].[VCFileIndexView] where fileID = '" + fileID + "'"); } else { //if not current, returns the last set of audit data xlReader = XLSQL.ReturnTable("select TOP(1)* from VCAuditLog where fileid = '" + fileID + "' and index01 is null order by auditId desc"); } string statusIndex = ""; string toBeIndex = ""; XDocument settingsDoc = XLtools.settingsDoc; IEnumerable <XElement> xIndexes = settingsDoc.Descendants("Indexes"); foreach (XElement xIndex in xIndexes.Descendants("Index")) { if (xIndex.AttributeValueNull("Type") == "Status") { statusIndex = xIndex.ElementValueNull(); } else if (xIndex.AttributeValueNull("Type") == "ToBe") { toBeIndex = xIndex.ElementValueNull(); } } file.FileID = fileID; file.Cabinet = xlReader.Rows[0]["FolderName"].ToString(); file.ToBeActionedBy = xlReader.Rows[0]["INDEX" + toBeIndex].ToString(); file.Status = xlReader.Rows[0]["INDEX" + statusIndex].ToString(); file.Extension = xlReader.Rows[0]["Extension"].ToString(); string indexNumber = ""; List <IndexPair> list = new List <IndexPair>(); for (int i = 1; i < 51; i++) { //add the 0 where required. Index09 is the section name and is handled differently try { if (i < 9) { indexNumber = "INDEX0" + i.ToString(); } else if (i == 9) { IndexPair index = new IndexPair(); index.index = "INDEX09"; index.value = xlReader.Rows[0]["SectionName"].ToString(); list.Add(index); } else { indexNumber = "INDEX" + i.ToString(); } string value = xlReader.Rows[0][indexNumber].ToString(); if (!String.IsNullOrEmpty(value)) { IndexPair index = new IndexPair(); index.index = indexNumber; index.value = value; list.Add(index); } } catch { continue; } } file.Indexes = list; foreach (IndexPair i in file.Indexes) { //grab the client string and code if (i.index == "INDEX02") { file.ClientString = i.value; file.ClientCode = i.value.Substring(0, i.value.IndexOf("-") - 1); } //and the description if (i.index == "INDEX03") { file.Description = i.value; } } } return(file); } catch (Exception ex) { XLtools.LogException("XLVC-FileIndex", ex.ToString()); return(null); } }
private static string BuildCommandFile(string docPath, string cabinet = "", string client = "", string status = "", string sender = "", string section = "", string desc = "", string docDate = null, IndexPair additionalIndex1 = null, IndexPair additionalIndex2 = null) { try { if (docDate == null) { docDate = DateTime.Now.ToString("dd/MM/yyyy"); } //blanked in an attempt to handle the weird random saving string tempPath = ""; tempPath = XLtools.TempPath(); string commandFileLoc = tempPath + "VC.command"; string statusIndex = ""; string toBeIndex = ""; XDocument settingsDoc = XLtools.settingsDoc; //query the setting files and try to find a match XElement setting = (from index in settingsDoc.Descendants("Indexes") select index).FirstOrDefault(); foreach (XElement xIndex in setting.Descendants("Index")) { if (xIndex.AttributeValueNull("Type") == "Status") { statusIndex = xIndex.Value; } if (xIndex.AttributeValueNull("Type") == "ToBe") { toBeIndex = xIndex.Value; } } //Create stream and add to file. StreamWriter sw = new StreamWriter(commandFileLoc, false, System.Text.Encoding.Default); sw.WriteLine("<<MODE=FILE>>"); sw.WriteLine("<<FILE=" + docPath + ">>"); sw.WriteLine("<<LEVEL01=" + cabinet + ">>"); sw.WriteLine("<<INDEX02=" + client + ">>"); sw.WriteLine("<<INDEX03=" + desc + ">>"); sw.WriteLine("<<INDEX09=" + section + ">>"); sw.WriteLine("<<INDEX20=" + docDate + ">>"); sw.WriteLine("<<INDEX" + statusIndex + "=" + status + ">>"); sw.WriteLine("<<INDEX" + toBeIndex + "=" + sender + ">>"); if (additionalIndex1 != null) { sw.WriteLine("<<" + additionalIndex1.index + "=" + additionalIndex1.value + ">>"); } if (additionalIndex2 != null) { sw.WriteLine("<<" + additionalIndex2.index + "=" + additionalIndex2.value + ">>"); } sw.Flush(); sw.Close(); //return the location of our new command file. return(commandFileLoc); } catch (Exception ex) { XLtools.LogException("XLVC-BuildCommandFile", ex.ToString()); return(null); } }
/// <summary> /// Generates a convex hull mesh for a set of points. Also removes all faces that lie on the ExoMesh plates. /// </summary> /// <param name="nodeIndex">Index of node being hulled.</param> /// <param name="sides">Number of sides per strut.</param> /// <param name="tol">The tolerance (RhinoDoc.ActiveDoc.ModelAbsoluteTolerance is a good bet).</param> /// <param name="cleanPlates">If true, the plate faces will be removed from the hull, so that the sleeves can be directly attached.</param> /// <remarks> /// If a plate point is coplanar with another plate, the hull may be impossible to clean. /// This is because the hulling process may remove the coplanar point and create a new face. /// </remarks> public Mesh MakeConvexHull(int nodeIndex, int sides, double tol, bool cleanPlates) { Mesh hullMesh = new Mesh(); ExoHull node = this.Hulls[nodeIndex]; double radius = node.AvgRadius; double planeTolerance = tol * radius / 25; // Collect all hull points (i.e. all plate points at the node) List <Point3d> pts = new List <Point3d>(); foreach (int pIndex in node.PlateIndices) { pts.AddRange(this.Plates[pIndex].Vtc); } // 1. Create initial tetrahedron. // Form triangle from 3 first points (lie on same plate, thus, same plane) hullMesh.Vertices.Add(pts[0]); hullMesh.Vertices.Add(pts[1]); hullMesh.Vertices.Add(pts[2]); Plane planeStart = new Plane(pts[0], pts[1], pts[2]); // Form tetrahedron with a 4th point which does not lie on the same plane int nextIndex = sides + 1; while (Math.Abs(planeStart.DistanceTo(pts[nextIndex])) < planeTolerance) { nextIndex++; } hullMesh.Vertices.Add(pts[nextIndex]); // Stitch faces of tetrahedron hullMesh.Faces.AddFace(0, 2, 1); hullMesh.Faces.AddFace(0, 3, 2); hullMesh.Faces.AddFace(0, 1, 3); hullMesh.Faces.AddFace(1, 2, 3); // 2. Begin the incremental hulling process // Remove points already checked pts.RemoveAt(nextIndex); pts.RemoveRange(0, 3); // Loop through the remaining points for (int i = 0; i < pts.Count; i++) { MeshTools.NormaliseMesh(ref hullMesh); // Find visible faces List <int> seenFaces = new List <int>(); for (int faceIndex = 0; faceIndex < hullMesh.Faces.Count; faceIndex++) { Vector3d testVect = pts[i] - hullMesh.Faces.GetFaceCenter(faceIndex); double angle = Vector3d.VectorAngle(hullMesh.FaceNormals[faceIndex], testVect); Plane planeTest = new Plane(hullMesh.Faces.GetFaceCenter(faceIndex), hullMesh.FaceNormals[faceIndex]); if (angle < Math.PI * 0.5 || Math.Abs(planeTest.DistanceTo(pts[i])) < planeTolerance) { seenFaces.Add(faceIndex); } } // Remove visible faces hullMesh.Faces.DeleteFaces(seenFaces); // Add current point hullMesh.Vertices.Add(pts[i]); List <MeshFace> addFaces = new List <MeshFace>(); // Close open hull based on new vertex for (int edgeIndex = 0; edgeIndex < hullMesh.TopologyEdges.Count; edgeIndex++) { if (!hullMesh.TopologyEdges.IsSwappableEdge(edgeIndex)) { IndexPair V = hullMesh.TopologyEdges.GetTopologyVertices(edgeIndex); int I1 = hullMesh.TopologyVertices.MeshVertexIndices(V.I)[0]; int I2 = hullMesh.TopologyVertices.MeshVertexIndices(V.J)[0]; addFaces.Add(new MeshFace(I1, I2, hullMesh.Vertices.Count - 1)); } } hullMesh.Faces.AddFaces(addFaces); } MeshTools.NormaliseMesh(ref hullMesh); // 3. If requested, delete the hull faces that lie on the plates (so sleeves can connect directly to the hulls) if (cleanPlates) { List <int> deleteFaces = new List <int>(); foreach (int plateIndx in node.PlateIndices) { List <Point3f> plateVtc = MeshTools.Point3dToPoint3f(this.Plates[plateIndx].Vtc); // Recall that strut plates have 'sides+1' vertices. // If the plate has only 'sides' vertices, it is an extra plate (for acute nodes), so we should keep it if (plateVtc.Count < sides + 1) { continue; } for (int j = 0; j < hullMesh.Faces.Count; j++) { Point3f ptA, ptB, ptC, ptD; hullMesh.Faces.GetFaceVertices(j, out ptA, out ptB, out ptC, out ptD); // Check if the mesh face has vertices that belong to a single plate, if so we need to remove the face int matches = 0; foreach (Point3f testPt in plateVtc) { if (testPt.EpsilonEquals(ptA, (float)tol) || testPt.EpsilonEquals(ptB, (float)tol) || testPt.EpsilonEquals(ptC, (float)tol)) { matches++; } } // If all three face vertices are plate vertices, we should remove the face if (matches == 3) { deleteFaces.Add(j); } } } // Remove the faces. Reverse the list so that it is in decreasing order. deleteFaces.Reverse(); foreach (int faceIndx in deleteFaces) { hullMesh.Faces.RemoveAt(faceIndx); } } return(hullMesh); }
public static bool SimulateLane(TileState[,] board, IndexPair index, TileState turnTo, int directionZ, int directionX, int depth) { int z = index.z + (directionZ * depth); int x = index.x + (directionX * depth); if (z >= board.GetLength(0)) { return(false); } if (x >= board.GetLength(1)) { return(false); } if (z < 0) { return(false); } if (x < 0) { return(false); } switch (turnTo) { case TileState.Black: if (board[z, x] == TileState.Empty) { return(false); } if (board[z, x] == TileState.Black && depth > 1) { return(true); } if (board[z, x] == TileState.White) { if (SimulateLane(board, index, turnTo, directionZ, directionX, ++depth)) { board[z, x] = TileState.Black; return(true); } else { return(false); } } break; case TileState.White: if (board[z, x] == TileState.Empty) { return(false); } if (board[z, x] == TileState.White && depth > 1) { return(true); } if (board[z, x] == TileState.Black) { if (SimulateLane(board, index, turnTo, directionZ, directionX, ++depth)) { board[z, x] = TileState.White; return(true); } else { return(false); } } break; case TileState.Empty: Debug.LogError("Empty tile should not be tested as playable."); break; default: break; } return(false); }
public Mesh Catmull_Clark(Mesh x) { Mesh mesh = new Mesh(); List <Point3d> pv = new List <Point3d>(); List <Point3d> pe = new List <Point3d>(); List <Point3d> pf = new List <Point3d>(); Rhino.Geometry.Collections.MeshTopologyVertexList vs = x.TopologyVertices; Rhino.Geometry.Collections.MeshTopologyEdgeList el = x.TopologyEdges; for (int i = 0; i < x.Faces.Count; i++) { int[] index = vs.IndicesFromFace(i); Point3d pf1 = new Point3d(); for (int j = 0; j < index.Length; j++) { pf1 += vs[index[j]]; } pf1 /= index.Length; pf.Add(pf1); } for (int i = 0; i < el.Count; i++) { IndexPair pair = el.GetTopologyVertices(i); Point3d pe1 = vs[pair.I] + vs[pair.J]; int[] index = el.GetConnectedFaces(i); if (index.Length == 2) { pe1 += pf[index[0]] + pf[index[1]]; pe1 /= 4.0; } else { pe1 = pe1 / 2.0; } pe.Add(pe1); } for (int i = 0; i < vs.Count; i++) { int[] index = vs.ConnectedEdges(i); int[] index2 = vs.ConnectedFaces(i); Point3d V = vs[i]; if (index.Length == index2.Length) { Point3d R = new Point3d(), Q = new Point3d(); for (int j = 0; j < index.Length; j++) { IndexPair pair = el.GetTopologyVertices(index[j]); Point3d pe1 = (vs[pair.I] + vs[pair.J]) * 0.5f; R += pe1; } R /= index.Length; for (int j = 0; j < index2.Length; j++) { Q += pf[index2[j]]; } Q /= index2.Length; int n = vs.ConnectedTopologyVertices(i).Length; V = Q + (R * 2) + V * (n - 3); V /= n; } else { Point3d R = new Point3d(); for (int j = 0; j < index.Length; j++) { if (el.GetConnectedFaces(index[j]).Length == 1) { IndexPair pair = el.GetTopologyVertices(index[j]); R += vs[pair.I] + vs[pair.J]; } } V = R * 0.125f + V * 0.5; } pv.Add(V); } mesh.Vertices.AddVertices(pv); mesh.Vertices.AddVertices(pe); mesh.Vertices.AddVertices(pf); for (int i = 0; i < x.Faces.Count; i++) { int[] index = vs.IndicesFromFace(i); if (x.Faces[i].IsQuad) { int pc = pv.Count + pe.Count + i; int p1 = index[0]; int p2 = index[1]; int p3 = index[2]; int p4 = index[3]; int p12 = el.GetEdgeIndex(p1, p2) + pv.Count; int p23 = el.GetEdgeIndex(p2, p3) + pv.Count; int p34 = el.GetEdgeIndex(p3, p4) + pv.Count; int p41 = el.GetEdgeIndex(p4, p1) + pv.Count; mesh.Faces.AddFace(p1, p12, pc, p41); mesh.Faces.AddFace(p12, p2, p23, pc); mesh.Faces.AddFace(pc, p23, p3, p34); mesh.Faces.AddFace(p41, pc, p34, p4); } else if (x.Faces[i].IsTriangle) { int pc = pv.Count + pe.Count + i; int p1 = index[0]; int p2 = index[1]; int p3 = index[2]; int p12 = el.GetEdgeIndex(p1, p2) + pv.Count; int p23 = el.GetEdgeIndex(p2, p3) + pv.Count; int p31 = el.GetEdgeIndex(p3, p1) + pv.Count; mesh.Faces.AddFace(p1, p12, pc, p31); mesh.Faces.AddFace(p12, p2, p23, pc); mesh.Faces.AddFace(pc, p23, p3, p31); } } mesh.UnifyNormals(); return(mesh); }
protected override void formTrace() { count = elements; i = j = 0; bool wereSteppingDown; bool wereSteppingRight; int level = 0; do { wereSteppingDown = false; wereSteppingRight = false; // Stepping right at upper border if (j < columns - level - 1) { wereSteppingRight = true; } while (j < columns - level - 1) { trace[elements - (count--)] = new IndexPair(i, j); j++; } // Stepping down at rightmost border. if (i < rows - level - 1) { wereSteppingDown = true; } while (i < rows - level - 1) { trace[elements - (count--)] = new IndexPair(i, j); i++; } // Stepping left at downmost border. if (wereSteppingDown && wereSteppingRight) { while (j > level) { trace[elements - (count--)] = new IndexPair(i, j); j--; } } // Stepping up at leftmost border. if (wereSteppingDown && wereSteppingRight) { while (i > level + 1) { trace[elements - (count--)] = new IndexPair(i, j); i--; } } level++; // increase indent level } while (count > 1); if (count > 0) { trace[elements - 1] = new IndexPair(i, j); // предусмотрено для нулевых матриц } return; }
/// <summary> /// Moves on the 2D Cartesian coordinates, conversion is on checking and drawing only /// </summary> /// <param name="direction"></param> /// <param name="deltaHorizontal"></param> /// <param name="deltaVertical"></param> private void Move(Directions direction) { IndexPair temp = playerCoordinates; switch (direction) { case Directions.Up: temp.I--; break; case Directions.Down: temp.I++; break; case Directions.Left: temp.J--; break; case Directions.Right: temp.J++; break; default: break; } // Wall detection if (MapLoader.IsWalkable(temp) || MapLoader.Level[temp.I, temp.J] == 6 || MapLoader.Level[temp.I, temp.J] == 7) { playerCoordinates = temp; playerAnimation.AnimationPosition = temp.IndexesToCorrdinates(); Direction = direction; if (MapLoader.Level[temp.I, temp.J] == 7) { ProjectilePool pool = ProjectilePool.Instance; IWeapon y = pool.Acquire(Position, false); System.Windows.Forms.MessageBox.Show("Gift"); } if (MapLoader.Level[temp.I, temp.J] == 6) { playerCoordinates = temp; playerAnimation.AnimationPosition = temp.IndexesToCorrdinates(); Direction = direction; System.Threading.Tasks.Task.Run(() => { System.Threading.Thread.Sleep(100); Program.MainWindow.RefreshTimer.Enabled = false; System.Windows.Forms.MessageBox.Show("Game Over"); }); } } }
public void SetIndex(int z, int x) { index = new IndexPair(z, x); }
// Determines if this index pair is equal to another public bool isEqual(IndexPair other) { return((this.rowIndex == other.rowIndex) && (this.columnIndex == other.columnIndex)); }
public override Vec Error(CMesh cm) { Mesh m = cm.mesh; List <Point3d> verts = new List <Point3d>(m.Vertices.ToPoint3dArray()); List <double> foldang = new List <double>(); // 等長拘束をかける辺の数取得 int n = equal_fold_angle_edge_id.Count; // メッシュの TopologyEdges 取得 MeshTopologyEdgeList topo_edges = m.TopologyEdges; // 法線方向計算 m.FaceNormals.ComputeFaceNormals(); for (int i = 0; i < n; i++) { double foldang_i = 0; /// Register indices int edge_index = equal_fold_angle_edge_id[i]; IndexPair edge_ind = topo_edges.GetTopologyVertices(edge_index); int u = edge_ind.I; int v = edge_ind.J; IndexPair face_ind = cm.face_pairs[edge_index]; int P = face_ind[0]; int Q = face_ind[1]; MeshFace face_P = m.Faces[P]; MeshFace face_Q = m.Faces[Q]; int p = 0; int q = 0; for (int j = 0; j < 3; j++) { if (!edge_ind.Contains(face_P[j])) { p = face_P[j]; } if (!edge_ind.Contains(face_Q[j])) { q = face_Q[j]; } } /// Compute normals Vector3d normal_P = m.FaceNormals[P]; Vector3d normal_Q = m.FaceNormals[Q]; /// cos(foldang_e) = n_i * n_j double cos_foldang_e = normal_P * normal_Q; /// sin(foldang_e) = n_i × n_j Vector3d vec_e = verts[u] - verts[v]; vec_e.Unitize(); double sin_foldang_e = Vector3d.CrossProduct(normal_P, normal_Q) * vec_e; if (sin_foldang_e >= 0) { if (cos_foldang_e >= 1.0) { foldang_i = 0; } else if (cos_foldang_e <= -1.0) { foldang_i = Math.PI; } else { foldang_i = Math.Acos(cos_foldang_e); } } else { if (cos_foldang_e >= 1.0) { foldang_i = 0; } else if (cos_foldang_e <= -1.0) { foldang_i = -Math.PI; } else { foldang_i = -Math.Acos(cos_foldang_e); } } if (is_set_angle) { foldang_i -= fold_angle; } foldang.Add(foldang_i); } Vec ans = new Vec(foldang); return(ans); }