/// <summary> /// Compute the Facet Normal between three vertices in space. The direction is given by rhs-rule /// v1v2 x v1v3 /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <param name="v3"></param> /// <returns></returns> public static Vector3 CalcFacetNormal(Vertex v1, Vertex v2, Vertex v3) { var M = new Vector3(v2.X - v1.X, v2.Y - v1.Y, v2.Z - v1.Z); var N = new Vector3(v3.X - v1.X, v3.Y - v1.Y, v3.Z - v1.Z); var normalVector = M.CrossProduct(N); normalVector.Normalize(); return normalVector; }
/// <summary> /// Generates a cartesian mesh by inserting relative X and Y coordinates based on the given distance /// and Z (elevation) based on a locations map. /// </summary> /// <param name="locations">Location data containing elevation information</param> /// <param name="ni">Number of horizontal (X) grid cells</param> /// <param name="nj">Number of vertical (Y) grid cells</param> /// <param name="distEW">Total horizontal distance</param> /// <param name="distSN">Total vertical distance</param> /// <returns></returns> private static Vertex[,] GenerateVerticesMatrix(ref LatLonAlt[,] locations, int ni, int nj, double distEW, double distSN) { var x0 = -distEW / 2F; var y0 = -distSN / 2F; var y = y0; double dx = distEW / (double)ni; double dy = distSN / (double)nj; var vertices = new Vertex[ni, nj]; for (var j = 0; j < nj; j++) { var x = x0; for (var i = 0; i < ni; i++) { vertices[i, j] = new Vertex(x, y, locations[i, j].Altitude); x += dx; } y += dy; } return vertices; }
public static Vertex[,] ToVertex(ref LatLonAlt[,] pos) { var vertex = new Vertex[pos.GetLength(0), pos.GetLength(1)]; for (var j = 0; j < pos.GetLength(1); j++) { for (var i = 0; i < pos.GetLength(1); i++) { vertex[i, j] = ToVertex(pos[i, j]); } } return vertex; }
public static Vertex ToVertex(LatLonAlt pos) { var vertex = new Vertex(pos.Latitude, pos.Longitude, pos.Altitude); return vertex; }
/// <summary> /// Constructor /// </summary> /// <param name="vertices">A map of structured N*M vertices </param> public Stereolithography(Vertex[,] vertices) { Vertices = vertices; }
/// <summary> /// Write the STL facet field. /// </summary> /// <param name="writer"></param> /// <param name="v1">Vertex 1</param> /// <param name="v2">Vertex 2</param> /// <param name="v3">Vertex 3</param> private void WriteFacet(Vertex v1, Vertex v2, Vertex v3) { var normal = Geometry.CalcFacetNormal(v1, v2, v3); writer.WriteLine(String.Format("facet normal {0} {1} {2}", normal.X, normal.Y, normal.Z)); writer.WriteLine("outer loop"); writer.WriteLine(String.Format("vertex {0} {1} {2}", v1.X, v1.Y, v1.Z)); writer.WriteLine(String.Format("vertex {0} {1} {2}", v2.X, v2.Y, v2.Z)); writer.WriteLine(String.Format("vertex {0} {1} {2}", v3.X, v3.Y, v3.Z)); writer.WriteLine("endloop"); writer.WriteLine("endfacet"); }