private void btnCenter_Click(object sender, EventArgs e) { LLBoundingBox bb = new LLBoundingBox(170, -43, 180, -44, false); var t1 = bb.GetCenter(); listBox1.Items.Add($"BB Center Test1 Not Radians {t1.Longitude} , {t1.Latitude}"); LLBoundingBox bb2 = new LLBoundingBox(MapUtil.Deg2Rad(170), MapUtil.Deg2Rad(-43), MapUtil.Deg2Rad(180), MapUtil.Deg2Rad(-44)); var t2 = bb2.GetCenter(); listBox1.Items.Add($"BB Center Test2 Not Radians {MapUtil.Rad2Deg( t2.Longitude)} , {MapUtil.Rad2Deg(t2.Latitude)}"); var t3 = MapUtil.MidPointRad(new MapPoint(MapUtil.Deg2Rad(170.0), MapUtil.Deg2Rad(-43)), new MapPoint(MapUtil.Deg2Rad(180.0), MapUtil.Deg2Rad(-44.0))); listBox1.Items.Add($"BB Center Test3 Not Radians {MapUtil.Rad2Deg(t3.Longitude)} , {MapUtil.Rad2Deg(t3.Latitude)}"); }
/* * https://cesium.com/blog/2013/05/09/computing-the-horizon-occlusion-point/ * private computeMagnitude(ellipsoid, position, scaledSpaceDirectionToPoint) * { * var scaledSpacePosition = ellipsoid.transformPositionToScaledSpace(position); * var magnitudeSquared = scaledSpacePosition.magnitudeSquared(); * var magnitude = Math.sqrt(magnitudeSquared); * var direction = scaledSpacePosition.divideByScalar(magnitude); * * // For the purpose of this computation, points below the ellipsoid * // are considered to be on it instead. * magnitudeSquared = Math.max(1.0, magnitudeSquared); * magnitude = Math.max(1.0, magnitude); * * var cosAlpha = direction.dot(scaledSpaceDirectionToPoint); * var sinAlpha = direction.cross(scaledSpaceDirectionToPoint).magnitude(); * var cosBeta = 1.0 / magnitude; * var sinBeta = Math.sqrt(magnitudeSquared - 1.0) * cosBeta; * * return 1.0 / (cosAlpha * cosBeta - sinAlpha * sinBeta); * } */ /// <summary> /// By LatLon /// </summary> /// <param name="bb"></param> /// <returns></returns> private ElevationData MakeTileDEM(LLBoundingBox bb) { // todo we also need to comput header info for the quantized mesh Vector2 v; v.X = 0; v.Y = 0; int x2 = 0; int y2 = 0; int PixelCount = GridSize - 1; var DoRandom = false; int HgtMode = 2; float minElev = float.PositiveInfinity; float maxElev = float.NegativeInfinity; Random rnd = new Random(); ElevationData ed = new ElevationData(GridSize); var midPt = bb.GetCenter(); // var pt2 = Coord.geo_to_ecef(new Vector3( MapUtil.Deg2Rad(midPt.Longitude), MapUtil.Deg2Rad(midPt.Latitude),0)); // zero elevation for now var pt = MapUtil.LatLonToEcef(midPt.Latitude, midPt.Longitude, 0); // zero elevation for now Vector3[] ecefPoints = new Vector3[GridSize * GridSize]; try { // we are going to walk up from sw to ne for returning dem in latlon coordinates var yRange = bb.North - bb.South; var xRange = bb.East - bb.West; var xStep = xRange / PixelCount; var yStep = yRange / PixelCount; int i = 0; float hgt = 0; for (int y = 0; y < GridSize; y++) { for (int x = 0; x < GridSize; x++) { var lat = bb.South + (y * yStep); var lon = bb.West + (x * xStep); v = MapProject(lat, lon); // MapProject is lat long if (v.X >= Width) { v.X = Width - 1; } if (v.Y >= Depth) { v.Y = Depth - 1; } if (v.X < 0) { v.X = 0; } if (v.Y < 0) { v.Y = 0; } x2 = (int)v.X; y2 = (int)v.Y; //hgt = 0; // if (i == 4) // hgt = 100; if (HgtMode == 1) { ed.Elev[i] = rnd.Next(1, 8000); } else if (HgtMode == 2) { ed.Elev[i] = 0; if (lat >= -43.548006 & lat <= -43.547679) { if (lon >= 172.632951 & lon <= 172.633542) { ed.Elev[i] = (float)10.0; } } } else { hgt = Map.GetPixel(x2, y2).GetBrightness(); // 0=black, 1= white ed.Elev[i] = MapUtil.Lerp(0, 1, ElevMin, ElevMax, hgt); } if (ed.Elev[i] < minElev) { minElev = ed.Elev[i]; } if (ed.Elev[i] > maxElev) { maxElev = ed.Elev[i]; } // Make ecef point list for later calculations ecefPoints[i] = Coord.geo_to_ecef(new Vector3() { X = MapUtil.Deg2Rad(lon), Y = MapUtil.Deg2Rad(lat), Z = ed.Elev[i] }); i++; } } } catch (Exception ex) { #if DEBUG System.Diagnostics.Debug.WriteLine($"**** MakeTileDEM Exception ****:{ex} v:{v} x2{x2} y2{y2} "); // file writer System.Diagnostics.Trace.WriteLine($"**** MakeTileDEM Exception *********:{ex} v:{v} x2{x2} y2{y2} "); #endif } // todo now make a ecfc array to calculate header info TileInfo tileInfo = new TileInfo(); var hdr = tileInfo.CalculateHeaderInfo(ref ecefPoints, false); ed.CenterX = hdr.CenterX; ed.CenterY = hdr.CenterY; ed.CenterZ = hdr.CenterZ; ed.BoundingSphereCenterX = hdr.CenterX; ed.BoundingSphereCenterY = hdr.CenterY; ed.BoundingSphereCenterZ = hdr.CenterZ; ed.BoundingSphereRadius = hdr.BoundingSphereRadius; ed.MaximumHeight = maxElev; ed.MinimumHeight = minElev; var hop = HorizonOcclusionPoint.FromPoints(ecefPoints, tileInfo.BoundingSphere); ed.HorizonOcclusionPointX = hop.X; ed.HorizonOcclusionPointY = hop.Y; ed.HorizonOcclusionPointZ = hop.Z; /* * // FIXME: is there a better choice for a horizon occlusion point? * // Currently it's the center of tile elevated to bbox's max Z * header.horizon_occlusion = c; * header.horizon_occlusion.z = bbox.max.z; * * * ed.HorizonOcclusionPointX = hdr.CenterX; * ed.HorizonOcclusionPointY = hdr.CenterY; * ed.HorizonOcclusionPointZ = maxElev; */ return(ed); }