123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- using OpenCvSharp;
- namespace SimulationCommon;
- public class WeatherResponse
- {
- public Wind Wind { get; set; }
- }
- public class Wind
- {
- public double Speed { get; set; }
- public double Deg { get; set; }
- }
- public class CurrentResponse
- {
- public Current Current { get; set; }
- }
- public class Current
- {
- public double Speed { get; set; }
- public double Direction { get; set; }
- }
- public class NCread
- {
-
-
-
- public float[] longitudeArray = new float[10];
- public float[] latitudeArray = new float[7];
- public float[][][] u10Array ;
- public float[][][] v10Array;
- public float[][][] p140208Array;
- public float[][][] mwdArray;
- public float[][][] hmaxArray;
- }
- public class SeaSJ
- {
-
- public static double NormalDistributionRandom(double mu, double sigma)
- {
- Random rand = new Random();
- double u1 = 1.0 - rand.NextDouble();
- double u2 = 1.0 - rand.NextDouble();
- double normalRandom = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2);
- return mu + sigma * normalRandom;
- }
-
- public static List<double[]> GetDrift(NCread nCread,double[] initialPosition, double dt, double totalTime)
- {
-
-
- List<double[]> trajectory = CalculateDriftTrajectory(nCread,initialPosition, dt, totalTime);
- return trajectory;
- }
- public static List<double[]> CalculateDriftTrajectory(NCread nCread,double[] initialPosition, double dt, double totalTime)
- {
- int timeSteps = (int)(totalTime / dt);
- List<double[]> trajectory = new List<double[]>();
- trajectory.Add(new double[] { initialPosition[0], initialPosition[1] });
- for (int t = 1; t < timeSteps; t++)
- {
- double[] currentPos = trajectory[t - 1];
- int outputTime = 3600 * t;
-
- double[] windVelocity = GetWindVelocityFromAPI(nCread,currentPos[0], currentPos[1], outputTime);
- double[] currentVelocity = GetCurrentVelocityFromAPI(nCread,currentPos[0], currentPos[1], outputTime);
-
- double[] driftVelocity = {
- currentVelocity[0] + windVelocity[0],
- currentVelocity[1] + windVelocity[1]
- };
-
- double[] newPosition = {
- currentPos[0] + (driftVelocity[0] * dt * 3600) / ((6371000 * Math.Cos(currentPos[0] * Math.PI / 180)) * 180 / Math.PI),
- currentPos[1] + (driftVelocity[1] * dt * 3600) / ((6371000 * Math.Cos(currentPos[1] * Math.PI / 180)) * 180 / Math.PI)
- };
- trajectory.Add(newPosition);
- }
- return trajectory;
- }
- public static double[] GetWindVelocityFromAPI(NCread windNCread,double latitude, double longitude, double temptime)
- {
- float[] longitudeArray = windNCread.longitudeArray;
- float[] latitudeArray = windNCread.latitudeArray;
- float[][][] u10Array = windNCread.u10Array;
- float[][][] v10Array = windNCread.v10Array;
- int longitudeNum = 0;
- int latitudeNum = 0;
- int temptimeNum = 0;
-
-
- for (int i = 0; i < 9; i++)
- {
- if (longitude >= longitudeArray[i] && longitude < longitudeArray[i + 1])
- {
- longitude = longitudeArray[i];
- longitudeNum = i;
- }
- }
-
- for (int i = 0; i < 6; i++)
- {
- if (latitude >= latitudeArray[i] && latitude < latitudeArray[i + 1])
- {
- latitude = latitudeArray[i];
- latitudeNum = i;
- }
- }
-
-
- for (int i = 0; i < 23 ; i ++)
- {
- if (temptime >= 3600 * i && temptime < (3600 * (i + 1)))
- {
- temptimeNum = i;
- }
- }
- double windX = (double)u10Array[temptimeNum][latitudeNum][longitudeNum];
- double windY = (double)v10Array[temptimeNum][latitudeNum][ longitudeNum];
- return new double[] { windX, windY };
- }
- public static double[] GetCurrentVelocityFromAPI(NCread CurrentNCread,double latitude, double longitude, double temptime)
- {
- float[] longitudeArray = CurrentNCread.longitudeArray;
- float[] latitudeArray = CurrentNCread.latitudeArray;
- float[][][] u10Array = CurrentNCread.u10Array;
- float[][][] v10Array = CurrentNCread.v10Array;
- float[][][] p140208Array = CurrentNCread.p140208Array;
- float[][][] mwdArray = CurrentNCread.mwdArray;
- int longitudeNum = 0;
- int latitudeNum = 0;
- int temptimeNum = 0;
-
-
- for (int i = 0; i < 9; i++)
- {
- if (longitude >= longitudeArray[i] && longitude < longitudeArray[i + 1])
- {
- longitude = longitudeArray[i];
- longitudeNum = i;
- }
- }
-
- for (int i = 0; i < 6; i++)
- {
- if (latitude >= latitudeArray[i] && latitude < latitudeArray[i + 1])
- {
- latitude = latitudeArray[i];
- latitudeNum = i;
- }
- }
-
-
- for (int i = 0; i < 23; i++)
- {
- if (temptime >= 3600 * 1 && temptime < 3600 * (i + 1))
- {
- temptimeNum = i;
- }
- }
- double currentSpeed = (double)p140208Array[temptimeNum][latitudeNum][ longitudeNum];
- double currentDirection = (double)mwdArray[temptimeNum][latitudeNum][ longitudeNum];
- double currentDirectionInRadians = currentDirection * (Math.PI / 180);
- double currentX = currentSpeed * Math.Cos(currentDirectionInRadians);
- double currentY = currentSpeed * Math.Sin(currentDirectionInRadians);
- return new double[] { currentX, currentY };
- }
-
-
- public static double GetWaveHeightFromAPI(NCread WaveNCread,double latitude, double longitude, double temptime)
- {
- float[] longitudeArray = WaveNCread.longitudeArray;
- float[] latitudeArray = WaveNCread.latitudeArray;
- float[][][] hmaxArray = WaveNCread.hmaxArray;
- int longitudeNum = 0;
- int latitudeNum = 0;
- int temptimeNum = 0;
-
-
- for (int i = 0; i < 9; i++)
- {
- if (longitude >= longitudeArray[i] && longitude < longitudeArray[i + 1])
- {
- longitude = longitudeArray[i];
- longitudeNum = i;
- }
- }
-
- for (int i = 0; i < 6; i++)
- {
- if (latitude >= latitudeArray[i] && latitude < latitudeArray[i + 1])
- {
- latitude = latitudeArray[i];
- latitudeNum = i;
- }
- }
-
- for (int i = 0; i < 23 ; i ++)
- {
- if (temptime >= 3600 * i && temptime < (3600 * (i + 1)))
- {
- temptimeNum = i;
- }
- }
- double WaveHeight = (double)hmaxArray[temptimeNum][ latitudeNum][ longitudeNum];
- return WaveHeight;
- }
-
-
- public static List<double[]> getminEnclosingRect(List<double[]> latLonList)
- {
-
- List<Point2f> pointList = new List<Point2f>();
- foreach (var latLon in latLonList)
- {
- double x = Rectangular_Area_Search_Function.MokatuoLat(latLon[1]);
- double y = Rectangular_Area_Search_Function.MokatuoLon(latLon[0]);
- pointList.Add(new Point2f((float)y, (float)x));
- }
-
- Point2f[] convexHull = Rectangular_Area_Search_Function.GetConvexHull(pointList);
-
-
- List<double[]> hullPoint = new List<double[]>();
- for (int num = 0; num < convexHull.Length - 1; num++)
- {
- hullPoint.Add(new double[] { convexHull[num].Y, convexHull[num].X });
- }
- List<double[]> hullPointLatLon = new List<double[]>();
- foreach (var point in hullPoint)
- {
- double pointLat = Rectangular_Area_Search_Function.RMokatuoLat(point[1]);
- double pointLon = Rectangular_Area_Search_Function.RMokatuoLon(point[0]);
- hullPointLatLon.Add(new double[] { pointLat, pointLon });
- }
-
-
- List<double[]> minEnclosingRect = Rectangular_Area_Search_Function.MinEnclosingRectangle(convexHull);
-
- List<double[]> startPoint = new List<double[]>();
- foreach (var minEnclosingRectPoint in minEnclosingRect)
- {
- double lat = Rectangular_Area_Search_Function.RMokatuoLat(minEnclosingRectPoint[0]);
- double lon = Rectangular_Area_Search_Function.RMokatuoLon(minEnclosingRectPoint[1]);
- startPoint.Add(new double[] { lat, lon });
- }
- return startPoint;
- }
- }
|