How to calculate the Antenna train angle between two planes in JSBsim? #628
Replies: 5 comments 6 replies
-
In general there are 3 cartesian coordinate systems available in JSBSim, i.e. ECEF, ECI and NED (local). So you could use any of them. The first two are earth centered. PropertyManager->Tie("position/eci-x-ft", this, eX, (PMF)&FGPropagate::GetInertialPosition);
PropertyManager->Tie("position/eci-y-ft", this, eY, (PMF)&FGPropagate::GetInertialPosition);
PropertyManager->Tie("position/eci-z-ft", this, eZ, (PMF)&FGPropagate::GetInertialPosition);
PropertyManager->Tie("position/ecef-x-ft", this, eX, (PMF)&FGPropagate::GetLocation);
PropertyManager->Tie("position/ecef-y-ft", this, eY, (PMF)&FGPropagate::GetLocation);
PropertyManager->Tie("position/ecef-z-ft", this, eZ, (PMF)&FGPropagate::GetLocation);
PropertyManager->Tie("velocities/eci-x-fps", this, eX, (PMF)&FGPropagate::GetInertialVelocity);
PropertyManager->Tie("velocities/eci-y-fps", this, eY, (PMF)&FGPropagate::GetInertialVelocity);
PropertyManager->Tie("velocities/eci-z-fps", this, eZ, (PMF)&FGPropagate::GetInertialVelocity);
PropertyManager->Tie("velocities/v-north-fps", this, eNorth, (PMF)&FGPropagate::GetVel);
PropertyManager->Tie("velocities/v-east-fps", this, eEast, (PMF)&FGPropagate::GetVel);
PropertyManager->Tie("velocities/v-down-fps", this, eDown, (PMF)&FGPropagate::GetVel); |
Beta Was this translation helpful? Give feedback.
-
You can't mix-up the coordinate systems. Sounds like you're trying to compute a look vector from the red aircraft to the blue aircraft? I had to do something similar on a recent project, in order to compute how to move a PTZ (Pan Tilt Zoom) to aim it at a target. So if you use the code below, you'll get the using System;
namespace GeoUtils
{
// https://microem.ru/files/2012/08/GPS.G1-X-00006.pdf (Data Transformations of GPS Positions) - LLAToECEF
// https://gis.stackexchange.com/questions/58923/calculating-view-angle (Calculating View Angle) - LookVector
/* Test of LookVector to compare with sample in the answer
var (x, y, z) = GeoUtils.LLAToECEF(-75, 39, 4000);
var (xp, yp, zp) = GeoUtils.LLAToECEF(-76, 39, 12000);
var (elevation, azimuth) = GeoUtils.LookVector((x, y, z), (xp, yp, zp));
Note there is a very small difference since we're using WGS84 ellipsoid model and
answer is using GRS80 ellipsoid model.
*/
public class GeoUtils
{
// WGS84 Parameters
static readonly double a = 6378137;
static readonly double f = 1.0 / 298.257223563;
static readonly double b = a * (1.0 - f);
static readonly double e = Math.Sqrt((a * a - b * b) / (a * a));
static public (double x, double y, double z) LLAToECEF(double lonDeg, double latDeg, double h)
{
// Convert to radians
double lon = lonDeg * Math.PI / 180.0;
double lat = latDeg * Math.PI / 180.0;
double N = a / Math.Sqrt(1.0 - e * e * Math.Sin(lat) * Math.Sin(lat));
double x = (N + h) * Math.Cos(lat) * Math.Cos(lon);
double y = (N + h) * Math.Cos(lat) * Math.Sin(lon);
double z = (((b * b) / (a * a)) * N + h) * Math.Sin(lat);
return (x, y, z);
}
static public (double elevation, double azimuth) LookVector((double x, double y, double z) from, (double xp, double yp, double zp) to)
{
var (x, y, z) = from;
var (xp, yp, zp) = to;
var (dx, dy, dz) = (xp - x, yp - y, zp - z);
double cosElevation = (x * dx + y * dy + z * dz) / Math.Sqrt((x * x + y * y + z * z) * (dx * dx + dy * dy + dz * dz));
double elevation = 90.0 - (Math.Acos(cosElevation) * 180.0 / Math.PI);
double cosAzimuth = (-z * x * dx - z * y * dy + (x * x + y * y) * dz) / Math.Sqrt((x * x + y * y) * (x * x + y * y + z * z) * (dx * dx + dy * dy + dz * dz));
double sinAzimuth = (-y * dx + x * dy) / Math.Sqrt((x * x + y * y) * (dx * dx + dy * dy + dz * dz));
double azimuth = Math.Atan2(cosAzimuth, sinAzimuth) * 180.0 / Math.PI;
if (azimuth > 90)
azimuth = 450 - azimuth;
else
azimuth = 90 - azimuth;
return (elevation, azimuth);
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I don't really understand what you're asking in terms of "closer to 0". |
Beta Was this translation helpful? Give feedback.
-
If azimuth and elevation are 0 then it means that the blue aircraft, assuming you haven't made any mistakes passing their coordinates into the function, is due north of the red aircraft and at the same level, assuming that they're not far enough apart for the curvature of the earth to be a factor for the elevation. There is nothing "better" about them being 0, it just means those are the relative angles. So check your input values, does 0 for azimuth and elevation make sense? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, everybody. I want to calculate the Antenna train angle between two planes as the below figure shows



the formula calculating that may be like this:
Where rRB is below:
In my opinion, the velocity and position in the above formula are the vectors under the ground coordinate system. Can they be represented by the property:
Beta Was this translation helpful? Give feedback.
All reactions