0
votes

I want to solve a set of non linear equations in matlab. I mean lets say I have two points defined by (lat1,lon1) and (lat2,lon2). Now I want to find a point lat3,lon3 such that it is at a distance of 20km from both of the points. It is given by the intersection of the circles with radius 20km drawn with points (lat1,lon1) and (lat2,lon2) as center.

However, I am a bit confused about how to solve this equation.

I have the function to calculate the distance between two points in matlab

function [ distance ] = calculateDistance( latitude1,longitude1,latitude2,longitude2 )
radius = 6371;
dLat = degtorad(latitude2-latitude1);
dLon = degtorad(longitude2-longitude1);
a = sin(dLat/2) * sin(dLat/2) + cos(degtorad(latitude1)) * cos(degtorad(latitude2)) * sin(dLon/2) * sin(dLon/2);
c = 2 * atan2(sqrt(a), sqrt(1-a));
distance = radius * c;
end

and I am trying to use the solve function of matlab available at http://www.mathworks.com/help/toolbox/symbolic/solve.html

However when I define

syms lat3 lon3

and try to get the equations to pass to the solve function it throws the error that atan2 only accepts arguments of type sym. How can I over this?

1

1 Answers

0
votes

If you have to solve only that particular question, you do not need any equation solving functions of Matlab. You can simply use Pythagoras' formula:

If your points are (0,0) and (1,0) and the radius is x, then the two points which are x away from both (0,0) and (1,0) are

(0.5, sqrt (x^2 - 0.25) ) and (0.5, - sqrt (x^2 - 0.25)).

Now if your points are (a,b) and (c,d), then the distance of the two points is

dist = sqrt ( (c-a)^2 + (d-b)^2 ).

Ok, now we take a coordinate system where the origin is (a,b) and the unit is dist and the horizontal axis goes through (c,d). In this coordinate system, the points in question are

(0.5, +/- sqrt ( (r/dist)^2 - 0.25 ) ).

Now, to get to the original coordinate system, we have to multiply by dist, getting

(0.5 * dist, +/- sqrt ( r^2 - 0.25 * dist^2 ) ),

then rotate with the matrix rotating (dist, 0) to (c-a, d-b), which is

cos alpha   -sin alpha
sin alpha   cos alpha

where alpha = arccos ( (d-b) / dist), i.e. the matrix

(d-b) / dist   -(c-a) / dist
(c-a) / dist    (d-b) / dist

which gives

(0.5 (d-b) -/+ (c-a) sqrt (r^2 / dist^2 - 0.25), 0.5 (c-a) +/- (d-b) sqrt (r^2 / dist^2 - 0.25)

and finally add (a,b), yielding

(a + 0.5 (d-b) -/+ (c-a) sqrt (r^2 /dist^2 - 0.25), b + 0.5 (c-a) +/- (d-b) sqrt (r^2 /dist^2 - 0.25) )

These are the points you are looking for. Probably I have made a mistake somewhere, but the direction should be clear, I hope.