public IrregularDtm(AttributedPointCollection collection) { this.collection = collection; //PointCollection c = new PointCollection(); //for (int i = 0; i < collection.Count; i++) //{ // c.Add(new Point(collection[i].X, collection[i].Y)); //} this.triangulation = new DelaunayTriangulation(this.collection); currenTriangle = triangulation.triangles[0]; }
public IrregularDtm(double[] east, double[] north, double[] value) { try { this.collection = new AttributedPointCollection(new List <double>(east), new List <double>(north), new List <double>(value)); triangulation = new DelaunayTriangulation(collection); currenTriangle = triangulation.triangles[0]; } catch (Exception ex) { throw ex; } }
public double Interpolate(Point point) { if (this.collection.Contains(point)) { return(this.collection[this.collection.IndexOf(point)].Value); } Triangle triangle = triangulation.GetTriangle(point, ref currenTriangle); if (triangle == null) { currenTriangle = triangulation.triangles[0]; return(double.NaN); } double firstValue = collection.GetValue(triangle.FirstPoint); double secondValue = collection.GetValue(triangle.SecondPoint); double thirdValue = collection.GetValue(triangle.ThirdPoint); double dx1 = triangle.SecondPoint.X - triangle.FirstPoint.X; double dy1 = triangle.SecondPoint.Y - triangle.FirstPoint.Y; double dz1 = secondValue - firstValue; double dx2 = triangle.ThirdPoint.X - triangle.FirstPoint.X; double dy2 = triangle.ThirdPoint.Y - triangle.FirstPoint.Y; double dz2 = thirdValue - firstValue; double a = dy1 * dz2 - dy2 * dz1; double b = -(dx1 * dz2 - dx2 * dz1); double c = dx1 * dy2 - dx2 * dy1; double d = a * triangle.FirstPoint.X + b * triangle.FirstPoint.Y + c * firstValue; return(1 / c * (d - a * point.X - b * point.Y)); }
public AdjacencyList <Point, double> GetSlopeGraph() { AdjacencyList <Point, double> result = new AdjacencyList <Point, double>();//this.triangulation.triangles.Count); for (int i = 0; i < this.triangulation.triangles.Count; i++) { QuasiTriangle tempQuasiTriangle = this.triangulation.triangles[i]; int tempCode = tempQuasiTriangle.GetHashCode(); Triangle tempTriangle = this.triangulation.GeTriangle(tempCode); Point firstPoint = tempTriangle.CalculateCentroid(); double currentSlope = CalculateSlope(tempTriangle); foreach (int neighbour in tempQuasiTriangle.OrderedNeighbours) { if (neighbour != -1) { Triangle neighbourTriangle = this.triangulation.GeTriangle(neighbour); Point secondPoint = neighbourTriangle.CalculateCentroid(); double neighbourSlope = CalculateSlope(tempTriangle); double weight = currentSlope + neighbourSlope; Connection <Point, double> tempConnection = new Connection <Point, double>(secondPoint, weight); result.AddUndirectedEdge(firstPoint, secondPoint, weight); } } } return(result); }