build a circle using the latitude and longitude values

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 commentaires

It sounds like you're trying to detect if a set of (lon,lat) coordinates are within a set distance to a target in which case you don't need to compute a circle. You just need to compute the distance of each (lon,lat) coordinate to the target and determine if it's less than or equal to the specified distance. That can be done using pdist2().
Yes, but i don't know how to write the code
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.

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaires

thanks a lot I'll try it!
Adam Danz
Adam Danz le 2 Juil 2020
Modifié(e) : Adam Danz le 2 Juil 2020
If you get stuck, provide more detail about your inputs, examples would be best, and show what you tried to do so I can get a sense of what needs corrected.
Angela Marino
Angela Marino le 2 Juil 2020
Modifié(e) : Angela Marino le 2 Juil 2020
this is how I modify my code. Because I would like to be evaluated the distance between each row of column 1 of the vector lat (3600*4) with each row of the vector lat_ferm (28 * 1) to find the minimum for everyone and save the position of every minimum value in the "withinRange" vector which must be 3600 rows and 1 column
I can't work with images since I cannot copy-paste code from an image.
Could you provide the variables that define the targets and the variables that define all of the coordinates you're measuring? They could be included in an attached mat file (just those variables) or you might be able to repoduce them here as a formatted comment.
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 le 6 Juil 2020
Modifié(e) : Adam Danz le 6 Juil 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by