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

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

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

How can i divide the line into multiple equal parts? I know the mid point of the line, now how to divide equal parts from its mid point?
It's just simple 10th grade algebra. But if you want the MATLAB way, just use linspace():
xEquallySpaced = linspace(x(1), x(2), numPoints);
yEquallySpaced = linspace(y(1), y(2), numPoints);
In this figure, i want to divide the orthogonal lines, in equal spacing. I have the mid point of the line. So i have only x(1) and y(1) for each orthogonal line. Now how to divide it?
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
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

Community Treasure Hunt

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

Start Hunting!