123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- 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 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(double[] initialPosition, double dt, double totalTime)
- {
-
-
- List<double[]> trajectory = CalculateDriftTrajectory(initialPosition, dt, totalTime);
- return trajectory;
- }
- public static List<double[]> CalculateDriftTrajectory(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];
-
- double[] windVelocity = GetWindVelocityFromAPI(currentPos[0], currentPos[1], t);
- double[] currentVelocity = GetCurrentVelocityFromAPI(currentPos[0], currentPos[1], t);
-
- double[] driftVelocity =
- {
- currentVelocity[0] + windVelocity[0],
- currentVelocity[1] + windVelocity[1]
- };
-
- double[] newPosition =
- {
- currentPos[0] + (driftVelocity[0] * dt / 60.0),
- currentPos[1] + (driftVelocity[1] * dt / 60.0)
- };
- trajectory.Add(newPosition);
- }
- return trajectory;
- }
- public static double[] GetWindVelocityFromAPI(double latitude, double longitude, int time)
- {
-
- WeatherResponse weatherResponse = new WeatherResponse() { };
- double windSpeed = weatherResponse.Wind.Speed;
- double windDirection = weatherResponse.Wind.Deg;
-
- double windSpeedInKnots = windSpeed / 1.852;
- double windDirectionInRadians = windDirection * (Math.PI / 180);
- double windX = windSpeedInKnots * Math.Cos(windDirectionInRadians);
- double windY = windSpeedInKnots * Math.Sin(windDirectionInRadians);
- return new double[] { windX, windY };
- }
- public static double[] GetCurrentVelocityFromAPI(double latitude, double longitude, int time)
- {
-
- CurrentResponse currentResponse = new CurrentResponse() { };
- double currentSpeed = currentResponse.Current.Speed;
- double currentDirection = currentResponse.Current.Direction;
-
- double currentSpeedInKnots = currentSpeed / 1.852;
- double currentDirectionInRadians = currentDirection * (Math.PI / 180);
- double currentX = currentSpeedInKnots * Math.Cos(currentDirectionInRadians);
- double currentY = currentSpeedInKnots * Math.Sin(currentDirectionInRadians);
- return new double[] { currentX, currentY };
- }
-
-
- public static Tuple<Point2f[], double> getminEnclosingRect(List<Tuple<double, double>> latLonList)
- {
-
- List<Point2f> pointList = new List<Point2f>();
- foreach (var latLon in latLonList)
- {
- double x = Rectangular_Area_Search_Function.MokatuoLat(latLon.Item1);
- double y = Rectangular_Area_Search_Function.MokatuoLon(latLon.Item2);
- pointList.Add(new Point2f((float)x, (float)y));
- }
-
- Point2f[] convexHull = Rectangular_Area_Search_Function.GetConvexHull(pointList);
-
- Tuple<Point2f[], double> minEnclosingRect = Rectangular_Area_Search_Function.MinEnclosingRectangle(convexHull);
- return minEnclosingRect;
- }
- }
|