Plotting dots on the edges of an object uniformly
5 views (last 30 days)
Show older comments
Kerem Asaf Tecirlioglu
on 1 Jan 2017
Commented: Walter Roberson
on 2 Jan 2017
Hello, everyone. I wonder is it possible to distribute a specific number of dots on the edges of the acquired image. Think of a circle for instance, is it possible to distribute,like, 8 dots uniformly on the circle ? Note: As in the image i have uploaded. Red circles are the dots etc.(sorry for paint level image :3)
0 Comments
Accepted Answer
Walter Roberson
on 1 Jan 2017
See http://www.mathworks.com/matlabcentral/answers/317921-distances-along-a-plotted-line#answer_248275
You would probably want to set marker_dist to dist_from_start(end)/N where N is the number of dots you want around the edge.
Note that that code does not try to put the markers at corners: it is code for placing the markers at equal distances along the path, where-ever that comes out to be.
2 Comments
Walter Roberson
on 2 Jan 2017
Hmmm, I remember fixing that at the time, but I do not remember what the fix I used then was. One fix would be
x = [0 5 10];
y = [2 4 1];
Number_of_divisions = 5;
dist_from_start = cumsum( [0, sqrt((x(2:end)-x(1:end-1)).^2 + (y(2:end)-y(1:end-1)).^2)] );
a = dist_from_start(end)/Number_of_divisions;
marker_dist = a;
marker_locs = marker_dist : marker_dist : dist_from_start(end); %replace with specific distances if desired
marker_indices = interp1( dist_from_start, 1 : length(dist_from_start), marker_locs);
marker_base_pos = floor(marker_indices);
weight_second = marker_indices - marker_base_pos;
mask = marker_base_pos < length(dist_from_start);
final_x = x(end); final_y = y(end);
final_marker = any(~mask) & (x(1) ~= final_x | y(1) ~= final_y);
marker_x = [x(1), x(marker_base_pos(mask)) .* (1-weight_second(mask)) + x(marker_base_pos(mask)+1) .* weight_second(mask), final_x(final_marker)];
marker_y = [y(1), y(marker_base_pos(mask)) .* (1-weight_second(mask)) + y(marker_base_pos(mask)+1) .* weight_second(mask), final_y(final_marker)];
plot(x, y, marker_x, marker_y, 'r+');
This code also checks to see if the curve is (exactly) closed and in that case avoids plotting the marker twice (because there is already a marker there from the plot from the beginning.)
More Answers (1)
Image Analyst
on 2 Jan 2017
See interparc http://www.mathworks.com/matlabcentral/fileexchange/34874-interparc by John D'Errico. It works for arbitrarily shaped curves in 2D as well as circles.
1 Comment
Walter Roberson
on 2 Jan 2017
Note: a difference between my code and John's is that my code treats the points as a series of line segments that the markers must sit on, whereas John's code treats the points a subsampling of a curve and interpolates the curve, a more difficult task.
My code is suitable for the case where the points define the path, such as the situation of a vehicle traveling at constant velocity along a map.
See Also
Categories
Find more on Modify Image Colors in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!