Connect two points with invisible vector and evenly spaced markers along the vector between them and Access Marking coordinates to draw circles around them.

5 vues (au cours des 30 derniers jours)
Hi, I am trying to use elements of this solution https://www.mathworks.com/matlabcentral/answers/233078-how-do-i-get-evenly-spaced-marks-in-my-plots to draw an invisible vector between two points, and then place markers along that vector that are equally spaced in increments of 8 units apart. I think this solution has just about everything I need, except I do not know how to access the markers coordinate data in order to draw circles around them using viscircles. Any help would be greatly appreciated.
% The 2 points I am trying to connect
P_1 = [52.7102,41.0737];
P_2 = [30.5984,56.2307];

Réponse acceptée

Adam Danz
Adam Danz le 29 Juin 2020
Assuming P_1 and P_2 and (x,y) coordinates, the steps are
  1. compute slope between the two points
  2. choose the number of points beteween and including the end points (see nPoints variable).
  3. Given the slope, and point P_1, compute the coordaintes at equally spaced intervals in the direction of P_2.
% P_1 = (x,y)
% P_2 = (x,y)
P_1 = [52.7102,41.0737];
P_2 = [30.5984,56.2307];
plot(P_1(1),P_1(2),'bo')
hold on
plot(P_2(1),P_2(2),'bo')
% Get eq of line
coefs = polyfit([P_1(1),P_2(1)], [P_1(2), P_2(2)],1);
% Get distance
d = sqrt((P_2(1)-P_1(1))^2 + (P_2(2)-P_1(2))^2);
% number of points between and including end points
nPoints = 5;
% Compute distance of each point from P_1
pointDist = linspace(0,d,nPoints);
% Compute (x,y) coordinates of nPoints **in both directions** from P_1
x = P_1(1) + [-1;1].*(pointDist .* sqrt(1/(1+coefs(1)^2)));
y = P_1(2) + [-1;1].*(coefs(1).*pointDist .* sqrt(1/(1+coefs(1)^2)));
% Chose which set of coordinates to use
% Distance should decrease as each coordinate approaches P_2
isDecreasing = all(diff(sqrt((P_2(1)-x).^2 + (P_2(2)-y).^2),1,2) < 0, 2);
x = x(isDecreasing,:);
y = y(isDecreasing,:);
% Add intervals
hold on
plot(x, y, 'r+')

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by