Reputation: 906
Suppose we have the following coordinates; an origin point and an end point based on an angle: [(37.040893, -7.83197), (37.042393, -7.83197)]
. In a map, I plotted them as follows:
I was able to get the end point successfully as shown below and it works perfectly:
import math
end_lat = origin_point[0] + length * math.sin(math.radians(angle))
end_lon = origin_point[1] + length * math.cos(math.radians(angle))
But I want to create a rectangle with a length of x meters
and a width of 6 meters
based on the origin point and the end point. Whereas, the origin point and the end point are at the center of their vertices. The following illustration explains what I am trying to do:
Now, I found that a 1 degree of latitude is equal to 110.574km, and 1 degree of longitudeis equal to 111.320*cos(latitude)km. And, I'm not so familliar with the math and I should't tackle the problem linearly (blindly). How can I solve this and be sure that everything works perfectly?
Upvotes: 1
Views: 683
Reputation: 80187
If you don't want to use appropriate libraries, look at the formulas at Movable Type Scripts page.
a) If you have bearing from start point to destination, use it further, otherwise calculate it with formula from Bearing section (JS script there)
θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )
where φ1,λ1 is the start point, φ2,λ2 the end point
(Δλ is the difference in longitude)
b) Get perpendicular bearings as
θ1 = θ + Pi/2
θ2 = θ - Pi/2
c) Find Destination point given distance and bearing from start point
φ2 = asin( sin φ1 ⋅ cos δ + cos φ1 ⋅ sin δ ⋅ cos θ )
λ2 = λ1 + atan2( sin θ ⋅ sin δ ⋅ cos φ1, cos δ − sin φ1 ⋅ sin φ2 )
where φ is latitude, λ is longitude, θ is the bearing (clockwise from north),
δ is the angular distance d/R; d being the distance travelled, R the earth’s radius
with d=3 m, R=6371000 m, starting coordinate and θ1, θ2 bearings to get rectangle corners, then repeat with desination coordinates.
d) For rather small distances approximation in destination point is good, otherwise you can use true bearing in destination point (because Dest-Src bearing differs a bit from S-D bearing)
Upvotes: 1