Reputation: 14381
I'm using Java NASA WorldWind, and I have two objects with different elevations and positions.
How can I find the elevation angle between the objects taking into account the curvature of the earth?
This image illustrates (obviously not to scale) what I'm trying to do:
Object A is 50 feet above the ground, and Object B is 500 feet above the ground. How can I find Angle X, taking into account the curvature of the earth?
Upvotes: 5
Views: 1628
Reputation: 14381
I took Vivin's answer and coded it into the WorldWind API. I think its working as I expect:
import gov.nasa.worldwind.BasicModel;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.geom.Angle;
import gov.nasa.worldwind.geom.Position;
public class ElevationAngle {
static WorldWindow ww = new WorldWindowGLCanvas();
static {
ww.setModel(new BasicModel());
}
public static void main(String[] args) {
Position pos1 = new Position(Angle.fromDegrees(34.22389),
Angle.fromDegrees(117.2458), 50 * 0.3048); //elevation in meters
Position pos2 = new Position(Angle.fromDegrees(34.22389),
Angle.fromDegrees(117.2440), 500 * 0.3048); //elevation in meters
System.out.println(getElevationAngleDegrees(pos1, pos2));
}
public static double getElevationAngleDegrees(Position pos1, Position pos2) {
double R = ww.getModel().getGlobe().getRadiusAt(pos1);
double L = Position.greatCircleDistance(pos1, pos2).getRadians() * R;
double theta = L / R;
double ha = pos1.getElevation();
double hb = pos2.getAltitude();
double d1 = (R + ha) * Math.cos(theta);
double d3 = (R + ha) * Math.sin(theta);
double d2 = R + hb - d1;
double alpha = Math.atan(d2 / d3) - theta;
return Math.toDegrees(alpha);
}
}
Upvotes: 1
Reputation: 95518
Trigonometry saves the day! Please refer to this untidy diagram as I work through the answer:
The angle we want to find is α. We can easily find θ if we know the distance (along the curvature of the Earth) between the two points (or more accurately, the curved-line distance between the two points we get on the surface on the Earth, if we extend a line from each object down to the surface). If the distance is L
, then θ is just L/R
(see Arc Length) where R
is the radius of the Earth.
Notice the values d1, d2, and d3. We can easily find α if we know d2 and d3, because (θ + α) is the inverse tangent of d2/d3. So how do we find these?
First we'll find d1. We know that the hypotenuse of the triangle with d1 and d3 is R + ha, which is just the radius of the Earth plus the elevation of object A. Hence we can find d1:
Similarly, for d3:
Now how do we find d2? We know that the total length of the base of the entire triangle is R + hb; essentially just the radius of the Earth plus the height of object B. We already know d1. So d2 is:
Now we are ready to find α:
So using this expression which is in terms of the heights of both objects and the radius of the Earth, you should be able to find α. There may be an even easier way to find α, but this is what I was able to come up with; it's been a while since I did any trigonometry! I think my math is correct, but let me know if you spot anything wrong.
Upvotes: 6