How can I draw a line from center of multiple circles that will intersect all the circles?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I want to multiple circles with same center but different radius. Later on I want add a line from center that will intersect all the cirles. I am attaching a figure to demonstrate how will be my expected output.
Accepted Answer
Star Strider
on 19 Jan 2019
Try this:
t = linspace(0, 2*pi);
r = [1, 2, 3];
xc = 0.5;
yc = 0.1;
xcir = (r(:)*cos(t))' + xc;
ycir = (r(:)*sin(t))' + yc;
figure
hold all
plot(xcir, ycir)
plot([xc, xc+5], [yc, yc], '-r')
hold off
axis equal
text(xc+r, yc*ones(1,numel(r)), ['$\frac{D}h$', compose('$\\frac{%dD}h$', r(2:end))], 'HorizontalAlignment','left', 'VerticalAlignment','top', 'Interpreter','latex', 'FontSize',12)
producing:

Experiment to get the result you want.
7 Comments
Zara Khan
on 20 Jan 2019
This is working well and getting the exact output but unable to point D/h, 2D/h etc as 'compose' giving me error. I am using R2014b.
Zara Khan
on 20 Jan 2019
This is the error:
Undefined function 'compose' for input arguments of type 'char'.
Error in circle_line (line 14)
text(xc+r, yc*ones(1,numel(r)), ['$\frac{D}h$', compose('$\\frac{%dD}h$', r(2:end))], 'HorizontalAlignment','left',
'VerticalAlignment','top', 'Interpreter','latex', 'FontSize',12 )
Change the compose call to sprintfc (that I believe evryone has). It is an undocumented function that creates cell strings, and is otherwise the same as sprintf.
This worked for me just now when I ran it, so it should work for you as well:
text(xc+r, yc*ones(1,numel(r)), ['$\frac{D}h$', sprintfc('$\\frac{%dD}h$', r(2:end))], 'HorizontalAlignment','left', 'VerticalAlignment','top', 'Interpreter','latex', 'FontSize',12)
My apologies for the delay. We are 7 hours behind UTC, so it was night here.
Zara Khan
on 21 Jan 2019
Thank you so much. It works well and perfectly. How can I bold the text? I am using 'fontWeight', 'bold' but its not working. One more thing how can I place D/h, 2D/h, 3D/h .... one line below so that it will not touch the straight line ?
As always, my pleasure.
For LaTeX labels, use the control sequence \bf to invoke boldface type, and \rm to restore the defaults:
text(xc+r, yc*ones(1,numel(r))-0.1, ['$\bf\frac{D}h\rm$', sprintfc('$\\bf\\frac{%dD}h\\rm$', r(2:end))], 'HorizontalAlignment','left', 'VerticalAlignment','top', 'Interpreter','latex', 'FontSize',12)
That worked when I tried it. It also lowers the labels by 0.1, so they are below the straight line.
Zara Khan
on 22 Jan 2019
Thank you. you are great !!!!!!!!!!!!!!!!!!!!
Star Strider
on 22 Jan 2019
As always, my pleasure!
Thank you!
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)