# Finding LAT LONG inside a circle of a given LAT LONG .

19 views (last 30 days)
M M Nabi on 20 Feb 2021
Answered: M M Nabi on 24 Feb 2021
I have a LAT LONG (point A). I have another set of LAT LONG. I want to find LAT LONG points within 5km radius of point A.
How can I do that?

Bruno Luong on 20 Feb 2021
Edited: Bruno Luong on 20 Feb 2021
% Random data
lonA=rand*360;
latA=rand*180-90;
n = 10000;
lonP=rand(1,n)*360;
latP=rand(1,n)*180-90;
rA = 1000; % distance from A
P = [x,y,z];
A = [xA,yA,zA];
% W. Kahan method
alpha = 2*atan(vecnorm(A-P,2,2) ./ vecnorm(A+P,2,2));
inrA = abs(alpha) <= rA/earthradius; % logical array, 1 if the distance from A is <= rA
close all
hold on
plot3(xA,yA,zA,'r+', 'Linewidth', 3);
plot3(x(inrA),y(inrA),z(inrA),'k.');
plot3(x(~inrA),y(~inrA),z(~inrA),'.','Color',0.8+[0 0 0]);
axis equal
M M Nabi on 23 Feb 2021
It helps..Thanks.

M M Nabi on 24 Feb 2021
It works better like that..
[deg,~] = distance(STATION_LAT_A,STATION_LON_A, sp_lat_all, sp_lon_all);
D = deg2km(deg);
I=find(D<9);