//Retrieve wind data at vessel location public wx_wind getWind(double vlat, double vlng, double vheight) { double epoch_time = Util.getLocalTime(); //Get local time (i.e. UT time) Dictionary <string, int> idx = get_dim_idx(vlat, vlng, vheight); //Get index of coordinates closest to vessel location int t = idx["t"]; int z = idx["z"]; int x = idx["x"]; int y = idx["y"]; double uu; double vv; double ww; ww = interp_var3d(0, t, z, y, x, epoch_time, vheight, vlat, vlng); //Get vertical wind component (w) at vessel location uu = interp_var3d(1, t, z, y, x, epoch_time, vheight, vlat, vlng); //Get zonal wind component (u) at vessel location vv = interp_var3d(2, t, z, y, x, epoch_time, vheight, vlat, vlng); //Get meridional wind component (v) at vessel location //Return data as struct wx_wind wind_data = new wx_wind(); wind_data.uwind = uu; wind_data.vwind = vv; wind_data.zwind = ww; return(wind_data); }
public wx_vel getVehicleVel(Vessel vessel, double vlat, double vlng, double vheight, bool wxenabled) { Vector3 windVector = Vector3.zero; //Wind in map space if (wxenabled) { //Get wind vector (in meteorological coordinates) wx_wind windvec = getWind(vlat, vlng, vheight); windVector.x = (float)windvec.vwind; //North windVector.y = (float)windvec.zwind; //Up windVector.z = (float)windvec.uwind; //East } //Retrieve mach double vel_mach; if (Util.far_GetMachNumber != null) { vel_mach = Util.far_GetMachNumber(vessel.mainBody, vessel.altitude, vessel.srf_velocity); } else { vel_mach = vessel.mach; } //Compute indicated airspeed double vel_ias = Math.Sqrt(((vessel.staticPressurekPa * 1000 * 2) * (Util.RayleighPitotTubeStagPressure(vel_mach) - 1)) / 1.225); //Get density ratio double d_ratio; if (Util.far_GetCurrentDensity != null) { d_ratio = Util.far_GetCurrentDensity(vessel.mainBody, vessel.altitude) * invKerbinSLDensity; } else { d_ratio = vessel.atmDensity / 1.225; } //Compute equivalent air speed double easCoeff = Math.Sqrt(d_ratio); double vel_eas = vessel.srfSpeed * easCoeff; if (vessel.staticPressurekPa <= 0) { vel_eas = 0; } //Get vessel orientation Vector3d CoM = vessel.CoMD; Vector3d orbitalVelocity = vessel.obt_velocity; Vector3d orbitalPosition = CoM - vessel.mainBody.position; Vector3d up = orbitalPosition.normalized; Vector3d north = vessel.north; Vector3d east = vessel.east; //Compute vessel surface velocity Vector3d surfaceVelocity = orbitalVelocity - vessel.mainBody.getRFrmVel(CoM); //Get components of vessel velocity double speedVertical = Vector3d.Dot(surfaceVelocity, up); double speedNorth = Vector3d.Dot(vessel.srf_velocity, north); double speedEast = Vector3d.Dot(vessel.srf_velocity, east); //Compute vessel ground speed double vel_grnd = Math.Sqrt(Math.Pow(speedEast, 2) + Math.Pow(speedNorth, 2)); //Get true air speed w.r.t surface double vel_tas_sfc = Math.Sqrt(Math.Pow((windVector.z - speedEast), 2) + Math.Pow((windVector.x - speedNorth), 2)); //Get true air speed (including vertical component) double vel_tas = Math.Sqrt(Math.Pow((windVector.z - speedEast), 2) + Math.Pow((windVector.x - speedNorth), 2) + Math.Pow((windVector.y - speedVertical), 2)); //Get component of wind perpendicular and parallel to the vessel's flight path. double projvu_sc = ((windVector.z * speedEast + windVector.x * speedNorth + windVector.y * speedVertical) / (Math.Pow(speedEast, 2) + Math.Pow(speedNorth, 2) + Math.Pow(speedVertical, 2))); double vel_par = Math.Sqrt(Math.Pow(projvu_sc * speedEast, 2) + Math.Pow(projvu_sc * speedNorth, 2) + Math.Pow(projvu_sc * speedVertical, 2)); double vel_prp = Math.Sqrt(Math.Pow(windVector.z - projvu_sc * speedEast, 2) + Math.Pow(windVector.x - projvu_sc * speedNorth, 2) + Math.Pow(windVector.y - projvu_sc * speedVertical, 2)); //If ground speed is slower than horizontal component of true air speed then there is a headwind. if (vel_grnd < vel_tas_sfc) { vel_par = vel_par * -1; } //Return all fields as struct wx_vel wx_data = new wx_vel(); wx_data.vel_ias = vel_ias; //Indiciated airspeed wx_data.vel_tas = vel_tas; //True airspeed wx_data.vel_eas = vel_eas; //Equivalent airspeed wx_data.vel_grnd = vel_grnd; //Surface velocity (i.e. ground speed) wx_data.vel_par = vel_par; //Component of wind perpendicular to aircraft wx_data.vel_prp = vel_prp; //Component of wind parallel to aircraft return(wx_data); }