//Maybe...http://answers.google.com/answers/threadview/id/782886.html //https://en.wikipedia.org/wiki/Position_of_the_Sun //https://en.wikipedia.org/wiki/Solar_azimuth_angle //http://www.itacanet.org/the-sun-as-a-source-of-energy/part-3-calculating-solar-angles/ public double[] getZenithAndAzimuth(DateTime time, double longitude, double latitude, double timezone) { int daysInYear = 365; if (DateTime.IsLeapYear(time.Year)) { daysInYear = 366; } //radians double fractionalYear = (2 * Math.PI / daysInYear) * (time.DayOfYear - 1 + ((time.Hour - 12) / 24)); //eqptime in Minutes double eqtime = 229.18 * (0.000075 + 0.001868 * Math.Cos(fractionalYear) - 0.032077 * Math.Sin(fractionalYear) - 0.014615 * Math.Cos(2 * fractionalYear) - 0.040849 * Math.Sin(2 * fractionalYear)); //decl in Radians double decl = 0.006918 - 0.399912 * Math.Cos(fractionalYear) + 0.070257 * Math.Sin(fractionalYear) - 0.006758 * Math.Cos(2 * fractionalYear) + 0.000907 * Math.Sin(2 * fractionalYear) - 0.002697 * Math.Cos(3 * fractionalYear) + 0.00148 * Math.Sin(3 * fractionalYear); double time_offset = eqtime + 4 * longitude - 60 * timezone; double tst = time.Hour * 60 + time.Minute + time.Second / 60 + time_offset; //Tst= true solar time double ha = (tst / 4) - 180; //Solar Hour Angle in degrees //Debug.Log(ha); //Solar Zenith Angle, and solar azimuth angle in radians double sza = Math.Acos(MathD.Sin(latitude) * Math.Sin(decl) + MathD.Cos(latitude) * Math.Cos(decl) * MathD.Cos(ha)); //Solar Zenith Angle in radians double saa = -(Math.Acos(-(MathD.Sin(latitude) * Math.Cos(sza) - Math.Sin(decl)) / (MathD.Cos(latitude) * Math.Sin(sza))) - Math.PI); //Solar Azimuth Angle //Wikiperdia solar azimuth angle //double saa = Math.Acos( // (Math.Sin(decl) * Math.Cos(latitude) - Math.Cos(ha) * Math.Cos(decl) * Math.Sin(latitude)) / Math.Sin(sza) // ); double[] answer = new double[2]; answer[0] = MathD.RadianToDegree(sza); answer[1] = MathD.RadianToDegree(saa); if (ha < 0 || ha > 180) { //answer[0] *= -1; answer[0] += 180; } Debug.LogFormat("Time: {0},\tZenith: {1},\tAzimuth: {2},\tHour Angle: {3}", time.ToString(), answer[0], answer[1], ha); return(answer); }
// This method calculates part values such as mass, lift, drag and connection forces, as well as all intermediates. public void CalculateAerodynamicValues(bool doInteraction = true) { // Calculate intemediate values //print(part.name + ": Calc Aero values"); b_2 = (double)tipPosition.z - (double)Root.localPosition.z + 1.0; MAC = ((double)tipScale.x + (double)rootScale.x + 2.0) * (double)modelChordLenght / 2.0; midChordSweep = (MathD.Rad2Deg * Math.Atan(((double)Root.localPosition.x - (double)tipPosition.x) / b_2)); taperRatio = ((double)tipScale.x + 1.0) / ((double)rootScale.x + 1.0); surfaceArea = MAC * b_2; aspectRatio = 2.0 * b_2 / MAC; ArSweepScale = Math.Pow(aspectRatio / MathD.Cos(MathD.Deg2Rad * midChordSweep), 2.0) + 4.0; ArSweepScale = 2.0 + Math.Sqrt(ArSweepScale); ArSweepScale = (2.0 * MathD.PI) / ArSweepScale * aspectRatio; wingMass = MathD.Clamp((double)massFudgeNumber * surfaceArea * ((ArSweepScale * 2.0) / (3.0 + ArSweepScale)) * ((1.0 + taperRatio) / 2), 0.01, double.MaxValue); Cd = (double)dragBaseValue / ArSweepScale * (double)dragMultiplier; Cl = (double)liftFudgeNumber * surfaceArea * ArSweepScale; //print("Gather Children"); GatherChildrenCl(); connectionForce = MathD.Round(MathD.Clamp(MathD.Sqrt(Cl + ChildrenCl) * (double)connectionFactor, (double)connectionMinimum, double.MaxValue)); // Values always set if (isWing) { wingCost = (float)wingMass * (1f + (float)ArSweepScale / 4f) * costDensity; wingCost = Mathf.Round(wingCost / 5f) * 5f; } else if (isCtrlSrf) { wingCost = (float)wingMass * (1f + (float)ArSweepScale / 4f) * costDensity * (1f - modelControlSurfaceFraction); wingCost += (float)wingMass * (1f + (float)ArSweepScale / 4f) * costDensityControl * modelControlSurfaceFraction; wingCost = Mathf.Round(wingCost / 5f) * 5f; } part.breakingForce = Mathf.Round((float)connectionForce); part.breakingTorque = Mathf.Round((float)connectionForce); // Stock-only values if (!FARactive) { // numbers for lift from: http://forum.kerbalspaceprogram.com/threads/118839-Updating-Parts-to-1-0?p=1896409&viewfull=1#post1896409 float stockLiftCoefficient = (float)(surfaceArea / 3.52); // CoL/P matches CoM unless otherwise specified part.CoMOffset = new Vector3(Vector3.Dot(Tip.position - Root.position, part.transform.right) / 2, Vector3.Dot(Tip.position - Root.position, part.transform.up) / 2, 0); if (isWing && !isCtrlSrf) { part.Modules.GetModules <ModuleLiftingSurface>().FirstOrDefault().deflectionLiftCoeff = stockLiftCoefficient; part.mass = stockLiftCoefficient * 0.1f; } else { ModuleControlSurface mCtrlSrf = part.Modules.OfType <ModuleControlSurface>().FirstOrDefault(); if (mCtrlSrf != null) { mCtrlSrf.deflectionLiftCoeff = stockLiftCoefficient; mCtrlSrf.ctrlSurfaceArea = modelControlSurfaceFraction; part.mass = stockLiftCoefficient * (1 + modelControlSurfaceFraction) * 0.1f; } } } // FAR values // With reflection stuff from r4m0n if (FARactive) { if (part.Modules.Contains("FARControllableSurface")) { PartModule FARmodule = part.Modules["FARControllableSurface"]; Type FARtype = FARmodule.GetType(); FARtype.GetField("b_2").SetValue(FARmodule, b_2); FARtype.GetField("b_2_actual").SetValue(FARmodule, b_2); FARtype.GetField("MAC").SetValue(FARmodule, MAC); FARtype.GetField("MAC_actual").SetValue(FARmodule, MAC); FARtype.GetField("S").SetValue(FARmodule, surfaceArea); FARtype.GetField("MidChordSweep").SetValue(FARmodule, midChordSweep); FARtype.GetField("TaperRatio").SetValue(FARmodule, taperRatio); FARtype.GetField("ctrlSurfFrac").SetValue(FARmodule, modelControlSurfaceFraction); //print("Set fields"); } else if (part.Modules.Contains("FARWingAerodynamicModel")) { PartModule FARmodule = part.Modules["FARWingAerodynamicModel"]; Type FARtype = FARmodule.GetType(); FARtype.GetField("b_2").SetValue(FARmodule, b_2); FARtype.GetField("b_2_actual").SetValue(FARmodule, b_2); FARtype.GetField("MAC").SetValue(FARmodule, MAC); FARtype.GetField("MAC_actual").SetValue(FARmodule, MAC); FARtype.GetField("S").SetValue(FARmodule, surfaceArea); FARtype.GetField("MidChordSweep").SetValue(FARmodule, midChordSweep); FARtype.GetField("TaperRatio").SetValue(FARmodule, taperRatio); } if (!triggerUpdate && doInteraction) { TriggerUpdateAllWings(); } if (doInteraction) { triggerUpdate = false; } } //print("FAR Done"); // Update GUI values if (!FARactive) { guiCd = Mathf.Round((float)Cd * 100f) / 100f; guiCl = Mathf.Round((float)Cl * 100f) / 100f; guiWingMass = part.mass; } guiMAC = (float)MAC; guiB_2 = (float)b_2; guiMidChordSweep = (float)midChordSweep; guiTaperRatio = (float)taperRatio; guiSurfaceArea = (float)surfaceArea; guiAspectRatio = (float)aspectRatio; StartCoroutine(updateAeroDelayed()); }