how can i divide a line into equal parts and divide them into small circles of equal radius ??

7 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 24 May 2015
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*');
  5 Comments
Walter Roberson
Walter Roberson on 15 Aug 2015
MATLAB requires at least two distinct points to create a visible line segment, so if were able to draw it then you are mistaken about having only one x and one y
Image Analyst
Image Analyst on 15 Aug 2015
I can't open your fig file. SUSHMA, I think you should probably start your own question rather than continuing on here. I think arjun will probably get emails every time we post here and he probably does not care anything about what we're trying to figure out for you.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!