/// <summary> /// checks if RD-coordinate is within the defined valid region /// </summary> /// <param name="coordinaat">RD-coordinate</param> /// <returns>true if coordinate is valid</returns> public static bool RDIsValid(Vector3RD coordinaat) { bool IsValid = true; double[,] Zonegrens = new double[, ] { { 141000, 629000 }, { 100000, 600000 }, { 80000, 500000 }, { -7000, 392000 }, { -7000, 336000 }, { 101000, 336000 }, { 161000, 289000 }, { 219000, 289000 }, { 300000, 451000 }, { 300000, 614000 }, { 259000, 629000 } }; var j = 10; Debug.Log(j); var inside = false; for (int i = 0; i < 11; i++) { var pix = Zonegrens[i, 0]; var piy = Zonegrens[i, 1]; var pjx = Zonegrens[j, 0]; var pjy = Zonegrens[j, 1]; if (((piy <= coordinaat.y && coordinaat.y < pjy) || (pjy <= coordinaat.y && coordinaat.y < piy)) && (coordinaat.x < (pjx - pix) * (coordinaat.y - piy) / (pjy - piy) + pix)) { inside = !inside; } } return(inside); }
/// <summary> /// checks if RD-coordinate is within the defined valid region /// </summary> /// <param name="coordinaat">RD-coordinate</param> /// <returns>true if coordinate is valid</returns> public static bool RDIsValid(Vector3RD coordinaat) { bool IsValid = true; double[,] Zonegrens = new double[, ] { { 141000, 629000 }, { 100000, 600000 }, { 80000, 500000 }, { -7000, 392000 }, { -7000, 336000 }, { 101000, 336000 }, { 161000, 289000 }, { 219000, 289000 }, { 300000, 451000 }, { 300000, 614000 }, { 259000, 629000 } }; double[] hoeken = new double[Zonegrens.GetLength(0)]; //calculate angles from coordinate to Zonegrens-points for (int i = 0; i < Zonegrens.GetLength(0); i++) { hoeken[i] = Math.Atan((Zonegrens[i, 1] - coordinaat.z) / (Zonegrens[i, 0] - coordinaat.x)); } double TotalAngle = 0; //add angle-difference between points TotalAngle += hoeken[0] - hoeken[hoeken.Length - 1]; for (int i = 1; i < hoeken.Length; i++) { TotalAngle += hoeken[i] - hoeken[i - 1]; } //if TotalAngle is zero, coordinate is outside Zonegrens // else Totalangle is 360 degrees (2*pi) and coordinate is inside Zonegrens if (Math.Abs(TotalAngle) < 0.1) { IsValid = false; } return(IsValid); }
/// <summary> /// Converts WGS84-coordinate to UnityCoordinate /// </summary> /// <param name="coordinaat">Vector2 WGS-coordinate</param> /// <returns>Vector3 Unity-Coordinate (y=0)</returns> public static Vector3 WGS84toUnity(Vector2 coordinaat) { Vector3 output = new Vector3(); output = WGS84toUnity(coordinaat.x, coordinaat.y); return(output); }
/// <summary> /// Convert RD-coordinate to Unity-coordinate /// </summary> /// <param name="coordinaat">RD-coordinate XYH</param> /// <returns>Unity-Coordinate</returns> public static Vector3 RDtoUnity(Vector2 coordinaat) { Vector3 output = new Vector3(); //convert to unity output = RDtoUnity(coordinaat.x, coordinaat.y, 0); return(output); }
/// <summary> /// Converts WGS84-coordinate to UnityCoordinate /// </summary> /// <param name="coordinaat">Vector3RD WGS-coordinate</param> /// <returns>Vector Unity-Coordinate</returns> public static Vector3 WGS84toUnity(Vector3WGS coordinaat) { Vector3 output = new Vector3(); output = WGS84toUnity(coordinaat.lon, coordinaat.lat); output.y = (float)(coordinaat.h - ReferenceWGS84.h); return(output); }
/// <summary> /// Converts WGS84-coordinate to UnityCoordinate /// </summary> /// <param name="coordinaat">Vector2 WGS-coordinate</param> /// <returns>Vector3 Unity-Coordinate (y=0)</returns> public static Vector3 WGS84toUnity(Vector2 coordinaat) { Vector3 output = new Vector3(); output = WGS84toUnity(coordinaat.x, coordinaat.y); output.y = (float)-ReferenceWGS84.h; return(output); }
/// <summary> /// Converts Unity-Coordinate to WGS84-Coordinate /// </summary> /// <param name="coordinaat">Unity-coordinate XHZ</param> /// <returns>WGS-coordinate</returns> public static Vector3WGS UnitytoWGS84(Vector3 coordinaat) { Vector3RD vectorRD = UnitytoRD(coordinaat); Vector3WGS output = RDtoWGS84(vectorRD.x, vectorRD.y); double hoogteCorrectie = RDCorrection(output.lon, output.lat, "Z", RDCorrectionZ); output.h = vectorRD.z + hoogteCorrectie; return(output); }
/// <summary> /// Converts Unity-Coordinate to RD-coordinate /// </summary> /// <param name="coordinaat">Unity-Coordinate</param> /// <returns>RD-coordinate</returns> public static Vector3RD UnitytoRD(Vector3 coordinaat) { Vector3WGS wgs = UnitytoWGS84(coordinaat); Vector3RD RD = WGS84toRD(wgs.lon, wgs.lat); RD.z = wgs.h - RDCorrection(wgs.lon, wgs.lat, "Z", RDCorrectionZ); RD.z = RD.z - Config.activeConfiguration.zeroGroundLevelY; return(RD); }
/// <summary> /// Converts Unity-Coordinate to RD-coordinate /// </summary> /// <param name="coordinaat">Unity-Coordinate</param> /// <returns>RD-coordinate</returns> public static Vector3RD UnitytoRD(Vector3 coordinaat) { //Vector3WGS wgs = UnitytoWGS84(coordinaat); Vector3RD RD = new Vector3RD(); RD.x = coordinaat.x + Config.activeConfiguration.RelativeCenterRD.x; RD.y = coordinaat.z + Config.activeConfiguration.RelativeCenterRD.y; RD.z = coordinaat.y - Config.activeConfiguration.zeroGroundLevelY; return(RD); }
/// <summary> /// Convert RD-coordinate to Unity-Coordinate /// </summary> /// <param name="coordinaat">Vector3RD RD-Coordinate XYH</param> /// <returns>Vector3 Unity-Coordinate</returns> public static Vector3 RDtoUnity(Vector3RD coordinaat) { Vector3 output = new Vector3(); //convert to unity output = RDtoUnity(coordinaat.x, coordinaat.y, coordinaat.z); //insert elevation output.y = (float)(coordinaat.z + Config.activeConfiguration.zeroGroundLevelY); return(output); }
/// <summary> /// Convert RD-coordinate to Unity-Coordinate /// </summary> /// <param name="coordinaat">RD-coordinate</param> /// <returns>UnityCoordinate</returns> public static Vector3 RDtoUnity(Vector3 coordinaat) { Vector3 output = new Vector3(); //convert to unity output = RDtoUnity(coordinaat.x, coordinaat.y, coordinaat.z); //insert elevation //output.y = coordinaat.y; return(output); }
/// <summary> /// calculate the necessary rotation for objects in rd-coordinates to sit nicely in the Unity-CoordinateSystem /// </summary> /// <param name="locatie">RD-coordinate</param> /// <returns>rotationAngle for RD-object (clockwise) in degrees around unity Y-axis</returns> public static double RDRotation(Vector3RD locatie) { double hoek = 0; Vector3WGS origin = RDtoWGS84(locatie.x, locatie.y); Vector3WGS punt2 = RDtoWGS84(locatie.x + 100, locatie.y); double deltaX = (punt2.lon - origin.lon) * unitsPerDegreeX; double deltaY = (punt2.lat - origin.lat) * unitsPerDegreeY; double hoekRad = Math.Tan(deltaY / deltaX); hoek = -1 * (hoekRad * 180 / Math.PI); return(hoek); }
/// <summary> /// Converts WGS84-coordinate to UnityCoordinate /// </summary> /// <param name="lon">double lon (east-west)</param> /// <param name="lat">double lat (south-north)</param> /// <returns>Vector3 Unity-Coordinate at 0-NAP</returns> public static Vector3 WGS84toUnity(double lon, double lat) { Vector3 output = new Vector3(); if (WGS84IsValid(new Vector3WGS(lon, lat, 0)) == false) { Debug.Log("<color=red>coordinate " + lon + "," + lat + " is not a valid WGS84-coordinate!</color>"); return(output); } Vector3RD vectorRD = new Vector3RD(); vectorRD = WGS84toRD(lon, lat); vectorRD.z = Config.activeConfiguration.zeroGroundLevelY; output = RDtoUnity(vectorRD); return(output); }
/// <summary> /// Convert RD-coordinate to Unity-coordinate /// </summary> /// <param name="x">RD X-coordinate</param> /// <param name="y">RD Y-coordinate</param> /// <param name="y">RD eleveation</param> /// <returns>Unity-Coordinate</returns> private static Vector3 RDtoUnity(double X, double Y, double Z) { Vector3 output = new Vector3(); //if (RDIsValid(new Vector3((float)X, (float)Y)) == false) //check if RD-coordinate is valid //{ // Debug.Log("<color=red>coordinaat " + X + "," + X + " is geen geldig RD-coordinaat!</color>"); // return output; //} //convert to WGS84 Vector3WGS wgs = RDtoWGS84(X, Y); //convert to Unity output = WGS84toUnity(wgs.lon, wgs.lat); double hoogte = RDCorrection(wgs.lon, wgs.lat, "Z", RDCorrectionZ); output.y = (float)(Z + Config.activeConfiguration.zeroGroundLevelY); return(output); }
/// <summary> /// Convert RD-coordinate to Unity-Coordinate /// </summary> /// <param name="coordinaat">Vector3RD RD-Coordinate XYH</param> /// <returns>Vector3 Unity-Coordinate</returns> public static Vector3 RDtoUnity(Vector3RD coordinaat) { return(RDtoUnity(coordinaat.x, coordinaat.y, coordinaat.z)); }