MATLAB: How can i divide a line into equal parts and divide them into small circles of equal radius ?

dividing lines into equal parts

Hi guys i am currently facing a problem where i have to divide a line into equal parts and then create circles of equal radius on the line, the major obstacle being that the length of the line is unknown and how can i get the radius of the circles if its at just random locations in my 2D-plot ,i am actually working on a obstacle avoidance code where in circles are defined at random locations can i get the radius of the circle if its random in nature in the 2d plot??
Can you please help me sort this thank you in advance

Best Answer

If you have definite coordinates for the endpoints of the line then its length can be calculated with the Euclidean formula. But you probably don't need it.
Divide the total change in x by the number of segments, and the total length in y by the number of segments, and record those. Now divide both of those by 2 and add those half-values to the original endpoint coordinates. The result will be the middle of the first segment. After that, add the whole deltas successively to get the middles of the additional segments.
If the circles are to go through the endpoints of each segment, then the centers are the middles I just described and the radii is the length of the half-change:
n = 10; %10 segments
deltax = (x(2) - x(1))/n;
deltay = (y(2) - y(1))/n;
halfdx = deltax/2;
halfdy = deltay/2;
radius = sqrt(halfdx.^2 + halfdy.^2);
xcents = x(1) + halfdx + (0:n-1)*deltax;
ycents = y(1) + halfdy + (0:n-1)*deltay;
plot(x, y, 'bs', xcents, ycents, 'r*');