build a circle using the latitude and longitude values

14 Ansichten (letzte 30 Tage)
Angela Marino
Angela Marino am 2 Jul. 2020
Bearbeitet: Adam Danz am 6 Jul. 2020
Hi, I need to build a circle using the latitude and longitude values ​​as the center of the circle.
busStop_latit; %array (28,1)
busStop_long; %array (28,1)
%latit and long with which I want to use to build the circle
I need to define "true" if new latitude and longitude values ​​are internal to the constructed circle, "false" if these new values ​​are external to the circle. How is it possible to build the circle and write these two conditions in matlab?
latitude; %matrix (3600,4)
longitude; %matrix (3600,4)
%i want to use only the 1st column oh the two matrix
pos_busStop=ones(28,1);
distance; %matrix (3600,4) and I want to use only the 1st column for this mtrix too
idx=zeros(3600,1);
for i=1:3600
if lat(i,1)<lat_new(1,:) && lon(i,1)<long_new(1,:)
idx(:,1)=1
end
pos_busStop(:,1)==distanza(idx,1);
end
  3 Kommentare
Angela Marino
Angela Marino am 2 Jul. 2020
Yes, but i don't know how to write the code
Adam Danz
Adam Danz am 2 Jul. 2020
On second thought, pdist2() with 3600 coordinates may overwhelm that function. It would be easiest just to use the euclidean distance equation directly. I'll add a demo in the answers section that you can apply to your data.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Danz
Adam Danz am 2 Jul. 2020
Here's a demo that you can apply to your data.
% Define the center of the circle
target = [lon,lat]; % where lon and lat are single, "scalar" values
% Define the radius of the circle (distance from target to furthest accepted point)
r = 12.2;
% Compute the distance of each (lon,lat) coordinate from target
% lonVec is a vector of longitudinal coordinates
% latVec is a vector of latitudinal coordinates
% hypot(A,B) is a Matlab function that computes the Euclidean distance between (A,B)
dist = hypot(lonVec-target(1), latVec-target(2));
% Detect which coordinates are within range
withinRange = dist <= r; % withinRange is a logical vector the same size as lonVec | latVec
  6 Kommentare
Angela Marino
Angela Marino am 3 Jul. 2020
pos_fermateR2=ones(28,1);
% Define the center of the circle
target = [long_ferm(:,1),lat_ferm(:,1)]; % where lon and lat are single, "scalar" values
% Define the radius of the circle (distance from target to furthest accepted point)
r = 12.2*ones(28,1);
% Compute the distance of each (lon,lat) coordinate from target
% lonVec is a vector of longitudinal coordinates
% latVec is a vector of latitudinal coordinates
% hypot(A,B) is a Matlab function that computes the Euclidean distance between (A,B)
for i=1:3600
dist = hypot(abs(lon(i,1)-target(:,1)), abs(lat(i,1)-target(:,2)));
% Detect which coordinates are within range
% withinRange is a logical vector the same size as lonVec | latVec
withinRange = dist <= r;
if veloc(i,1)==0 && veloc(i-1,1)~=0
pos_fermateR2(:,1)==distanza(withinRange,1);
end
end
Adam Danz
Adam Danz am 6 Jul. 2020
Bearbeitet: Adam Danz am 6 Jul. 2020
Try using pdist2. Your lat and lon values contain a lot of NaNs which will propagate through to the final output.
target = [long_ferm(:,1),lat_ferm(:,1)];
dist = pdist2(target, [lon(:,1),lat(:,1)]);
inCirlce = dist <= 12.2;
inCircle is a matrix of logical values.
size(inCirlce)
ans =
28 3600
where inCircle(i,j) tells you whether [lon(j,1),lat(j,1)] is within range of the target target(i,:). 1 means in or on cirlce and 0 means outside or NaN value was present.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by