/// <summary> /// This function computes the z-coord by a given x and y position. /// </summary> /// <param name="x">x position</param> /// <param name="y">y position</param> /// <param name="z">z position to return</param> /// <returns>True/False if the z position was found</returns> public bool GetZ(float x, float y, out float z) { try { point2D delta; point3D point1, point2, point3, point4; ushort mx = (ushort)Math.Ceiling((float)((x - this.info.location[0]) / this.info.scale[0]) + (this.info.size / 2)); ushort my = (ushort)Math.Ceiling((float)((y - this.info.location[1]) / this.info.scale[1]) + (this.info.size / 2)); if (mx >= this.info.size || my >= this.info.size) { z = 0; return(false); } point1.x = (float)((mx - (this.info.size / 2)) * this.info.scale[0]) + this.info.location[0]; point1.y = (float)((my - (this.info.size / 2)) * this.info.scale[1]) + this.info.location[1]; point1.z = (float)(this.HeightData[mx, my] * this.info.scale[2]) + this.info.location[2]; mx -= 1; point2.x = (float)((mx - (this.info.size / 2)) * this.info.scale[0]) + this.info.location[0]; point2.y = (float)((my - (this.info.size / 2)) * this.info.scale[1]) + this.info.location[1]; point2.z = (float)(this.HeightData[mx, my] * this.info.scale[2]) + this.info.location[2]; my -= 1; point3.x = (float)((mx - (this.info.size / 2)) * this.info.scale[0]) + this.info.location[0]; point3.y = (float)((my - (this.info.size / 2)) * this.info.scale[1]) + this.info.location[1]; point3.z = (float)(this.HeightData[mx, my] * this.info.scale[2]) + this.info.location[2]; mx += 1; point4.x = (float)((mx - (this.info.size / 2)) * this.info.scale[0]) + this.info.location[0]; point4.y = (float)((my - (this.info.size / 2)) * this.info.scale[1]) + this.info.location[1]; point4.z = (float)(this.HeightData[mx, my] * this.info.scale[2]) + this.info.location[2]; delta.x = point1.x - x; delta.y = point1.y - y; if (delta.x >= delta.y) //use 1,2,3 { z = (float)HeightMap.z(point1.x, point1.y, point1.z, point2.x, point2.y, point2.z, point3.x, point3.y, point3.z, x, y) + z_correction; } else //use 1,3,4 { z = (float)HeightMap.z(point1.x, point1.y, point1.z, point3.x, point3.y, point3.z, point4.x, point4.y, point4.z, x, y) + z_correction; } return(true); } catch (IndexOutOfRangeException) { z = 0; return(false); } }