123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- using KYFramework;
- using Model;
- using Newtonsoft.Json;
- using Org.BouncyCastle.Utilities;
- using SimulationCommon;
- using SimulationServer.Utils;
- using Define = SimulationServer.Utils.Define;
- namespace SimulationServer;
- public class AircraftKTKS : AircraftEntity
- {
- public string NextMissionId;
- public MissionEndPoint missionEndPoint = new MissionEndPoint();
- public int LandingPersonnel;
- public MHRescueMission mhRescueMission;
- public int landingPoint = 0;
- public MissionPoint missionpoint = new MissionPoint();
- public KTKSTask taskContent;
- int Days;
- int Hour;
- public TaskParameter taskParameter;
- public bool IsOver;
- public bool Success;
- public RescueDemandInfo rescueDemandInfo;
- public bool isReadNC;
- Text_readNC text_ReadNC;
- public override void End()
- {
- TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
- }
- public override void Reset()
- {
- base.Reset();
- IsOver = false;
- Success = false;
- TotalTime = 0;
- }
- public override void Start()
- {
-
- FlightPlanEditor.missionpoint.MissionPointLatitude = rescueDemandInfo.TargetPointLatitude;
- FlightPlanEditor.missionpoint.MissionPointLongitude = rescueDemandInfo.TargetPointLongitude;
- FlightPlanEditor.missionpoint.MissionPointHeight = rescueDemandInfo.TargetPointHeight;
-
- FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);
- int TransportNumber = (int)Math.Ceiling(LandingPersonnel / FlightPlanEditor.aircraftparameter.MaxPassengerNumber);
- int j = 0;
-
-
-
- FXJHGenerate.KouTouKouSong(FlightPlanEditor, ref TurningPoints);
- double alpha = CalculateEastBaseAngle(TurningPoints[0].TurningPointLatitude, TurningPoints[0].TurningPointLongitude, TurningPoints[2].TurningPointLatitude, TurningPoints[2].TurningPointLongitude);
-
-
-
-
-
- int Year = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[0]);
- int Month = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[0]);
- int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]);
- Hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
- Days = GetDaysInYear(Year, Month, Day);
- if (!isReadNC)
- {
- text_ReadNC = new Text_readNC();
- text_ReadNC.initlatitudes = rescueDemandInfo.TargetPointLatitude;
- text_ReadNC.initlongitudes = rescueDemandInfo.TargetPointLongitude;
- bool isSuccess = false;
- while (!isSuccess)
- {
- isSuccess = text_ReadNC.GetNCData();
- }
- isReadNC = true;
- }
- var nCread = text_ReadNC.windNCread;
- double[] windVelocity = GetWindVelocityFromAPI(nCread, rescueDemandInfo.TargetPointLatitude, rescueDemandInfo.TargetPointLongitude, text_ReadNC.latitudes, text_ReadNC.longitudes, Days, Hour);
- var windSpeed = Math.Sqrt(windVelocity[0] * windVelocity[0] + windVelocity[1] * windVelocity[1]);
- var theta = Math.Asin(windVelocity[0] / windSpeed);
- List<double> KTiniposition = new List<double>();
- List<double> KTresultPostion = new List<double>();
- double KTheight;
- if (taskParameter.isParachute)
- {
- KTheight = 200;
-
- KTiniposition = getPositionWithUmbrella(FlightPlanEditor.missionpoint.MissionPointLongitude, FlightPlanEditor.missionpoint.MissionPointLatitude, KTheight, windSpeed, theta, taskParameter.airdropWindArea, taskParameter.airdropWeight);
- double inix = Mokatuo_lon(KTiniposition[1]);
- double iniy = Mokatuo_lat(KTiniposition[0]);
- double resultX = inix + 33 * Math.Cos(alpha) * KTiniposition[2] / 1000;
- double resultY = iniy + 33 * Math.Sin(alpha) * KTiniposition[2] / 1000;
- KTresultPostion.Add(ReMokatuo_lat(resultY));
- KTresultPostion.Add(ReMokatuo_lon(resultX));
- }
- else
- {
- KTheight = 20;
- KTiniposition = getPositionWithoutUmbrella(FlightPlanEditor.missionpoint.MissionPointLongitude, FlightPlanEditor.missionpoint.MissionPointLatitude, KTheight, windSpeed, 22, alpha, theta);
- double inix = Mokatuo_lon(KTiniposition[1]);
- double iniy = Mokatuo_lat(KTiniposition[0]);
- double resultX = inix + 22 * Math.Cos(alpha) * KTiniposition[2] / 1000;
- double resultY = iniy + 22 * Math.Sin(alpha) * KTiniposition[2] / 1000;
- KTresultPostion.Add(ReMokatuo_lat(resultY));
- KTresultPostion.Add(ReMokatuo_lon(resultX));
- }
- TurningPoints.RemoveAt(2);
- if(taskParameter.airdropWay == "带速空投")
- {
- FlightPlanEditor.missionpoint.MissionPointLatitude = KTiniposition[0];
- FlightPlanEditor.missionpoint.MissionPointLongitude = KTiniposition[1];
- FlightPlanEditor.missionpoint.MissionPointHeight = KTheight;
- missionpoint.MissionPointLatitude = KTresultPostion[0];
- missionpoint.MissionPointLongitude = KTresultPostion[1];
- missionpoint.MissionPointHeight = KTheight;
- missionEndPoint.MissionEndPointLatitude = KTresultPostion[0];
- missionEndPoint.MissionEndPointLongitude = KTresultPostion[1];
- missionEndPoint.MissionEndPointHeight = KTheight;
- }
- else if(taskParameter.airdropWay == "悬停空投")
- {
- FlightPlanEditor.missionpoint.MissionPointLatitude = KTiniposition[0];
- FlightPlanEditor.missionpoint.MissionPointLongitude = KTiniposition[1];
- FlightPlanEditor.missionpoint.MissionPointHeight = KTheight;
- missionpoint.MissionPointLatitude = KTiniposition[0];
- missionpoint.MissionPointLongitude = KTiniposition[1];
- missionpoint.MissionPointHeight = KTheight;
- missionEndPoint.MissionEndPointLatitude = KTiniposition[0];
- missionEndPoint.MissionEndPointLongitude = KTiniposition[1];
- missionEndPoint.MissionEndPointHeight = KTheight;
- }
- FXJHGenerate.KouTouKouSong(FlightPlanEditor, ref TurningPoints);
- FXJHGenerate.KouTouKouSong1(missionpoint, ref TurningPoints);
- TurningPoints[2].SegmentFlightTime = KTiniposition[2];
- FXJHGenerate.FromMissionToEnd(FlightPlanEditor, missionEndPoint, ref TurningPoints);
- FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
- for (int i = 0; i < TurningPoints.Count; i++)
- {
- TotalTime += TurningPoints[i].SegmentFlightTime;
- }
- Console.WriteLine("TotalTime:" + TotalTime);
- IsOver = true;
-
- End();
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public override void Update(double time)
- {
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static double[] GetWindVelocityFromAPI(NCread windNCread, double latitude, double longitude, int latitudes, int longitudes, int days, int hour)
- {
- 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 < longitudes - 1; i++)
- {
- if (longitude >= longitudeArray[i] && longitude < longitudeArray[i + 1])
- {
- longitude = longitudeArray[i];
- longitudeNum = i;
- }
- }
-
- for (int i = 0; i < latitudes - 1; i++)
- {
- if (latitude >= latitudeArray[i] && latitude < latitudeArray[i + 1])
- {
- latitude = latitudeArray[i];
- latitudeNum = i;
- }
- }
- temptimeNum += (days - 1) * 24 + hour - 1;
- double windX = (double)u10Array[temptimeNum][latitudeNum][longitudeNum];
- double windY = (double)v10Array[temptimeNum][latitudeNum][longitudeNum];
- return new double[] { windX, windY };
- }
-
-
- public double Mokatuo_lat(double lat)
- {
- double R = 6378.137;
- double y = R * Math.Log(Math.Tan((lat + 90) * Math.PI / 360));
- return y;
- }
- public double Mokatuo_lon(double lon)
- {
- double R = 6378.137;
- double x = (lon * Math.PI * R) / 180;
- return x;
- }
-
- public double ReMokatuo_lat(double y)
- {
- double R = 6378.137;
- double lat = (2 * Math.Atan(Math.Exp(y / R)) - Math.PI / 2) * 180 / Math.PI;
- return lat;
- }
- public double ReMokatuo_lon(double x)
- {
- double R = 6378.137;
- double lon = x * 180 / (Math.PI * R);
- return lon;
- }
-
-
- public List<double> getPositionWithoutUmbrella(double longitude, double latitude, double altitude, double windspeed, double velocity, double alpha, double theta)
- {
- double g = 9.8;
- double time = Math.Sqrt(2 * altitude / g);
- double x = Mokatuo_lon(longitude);
- double y = Mokatuo_lat(latitude);
- double vx = velocity * Math.Cos(alpha) + windspeed * Math.Cos(theta);
- double vy = velocity * Math.Sin(alpha) + windspeed * Math.Sin(theta);
- double y_new = y + vy * time / 1000;
- double x_new = x + vx * time / 1000;
- double lat = ReMokatuo_lat(y_new);
- double lon = ReMokatuo_lon(x_new);
- List<double> result = new List<double>()
- {lat, lon,time};
- return result;
- }
-
-
- public List<double> getPositionWithUmbrella(double longitude, double latitude, double altitude, double windspeed, double theta, double s, double m)
- {
- double g = 9.8;
- double k = 3.824 * s;
- double vz = Math.Sqrt(m * g / k);
- double time = altitude / vz;
- double x = Mokatuo_lon(longitude);
- double y = Mokatuo_lat(latitude);
- double y_new = y + windspeed * Math.Sin(theta) * time / 1000;
- double x_new = x + windspeed * Math.Cos(theta) * time / 1000;
- double lat = ReMokatuo_lat(y_new);
- double lon = ReMokatuo_lon(x_new);
- List<double> result = new List<double>()
- {lat, lon,time};
- Console.WriteLine(y_new);
- Console.WriteLine(y);
- return result;
- }
- public static int GetDaysInYear(int year, int month, int day)
- {
- int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- if (IsLeapYear(year))
- {
- daysInMonths[1] = 29;
- }
- int days = day;
- for (int i = 0; i < month - 1; i++)
- {
- days += daysInMonths[i];
- }
- return days;
- }
- public static bool IsLeapYear(int year)
- {
- return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
- }
- public static double CalculateEastBaseAngle(double lat1, double lon1, double lat2, double lon2)
- {
-
- double lat1Rad = lat1 * Math.PI / 180;
- double lon1Rad = lon1 * Math.PI / 180;
- double lat2Rad = lat2 * Math.PI / 180;
- double lon2Rad = lon2 * Math.PI / 180;
- double deltaLon = lon2Rad - lon1Rad;
-
- double x = Math.Sin(deltaLon) * Math.Cos(lat2Rad);
- double y = Math.Cos(lat1Rad) * Math.Sin(lat2Rad) - Math.Sin(lat1Rad) * Math.Cos(lat2Rad) * Math.Cos(deltaLon);
- double headingRad = Math.Atan2(x, y);
- double headingDeg = headingRad * 180 / Math.PI;
-
- headingDeg = (headingDeg + 360) % 360;
-
- double eastBaseAngle = (90 - headingDeg) % 360;
- if (eastBaseAngle < 0)
- {
- eastBaseAngle += 360;
- }
- return eastBaseAngle;
- }
- }
- [ObjectSystem]
- public class AircraftKTKSAwakeSystem : AwakeSystem<AircraftKTKS, FlightPlanEditor>
- {
- public override void Awake(AircraftKTKS self, FlightPlanEditor flightPlanEditor)
- {
- self.FlightPlanEditor = flightPlanEditor;
- self.Awake();
-
- }
- }
|