how can i divide a line into equal parts and divide them into small circles of equal radius ??
20 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Walter Roberson
2015-5-24
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 个评论
Walter Roberson
2015-8-15
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
2015-8-15
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!