# How to plot a circle centered on a line and passing through a point?

46 views (last 30 days)

Show older comments

##### 0 Comments

### Answers (1)

Roger Stafford
on 12 Mar 2018

Edited: Roger Stafford
on 12 Mar 2018

There are infinitely many ways a circle can be centered on a line and pass through a given point, except for the case when a line segment from the center to the given point is required to be orthogonal to that line. In that case the circle would be unique. Therefore I will suppose that is what you actually require. Let the line run through points Pa = [a1;a2] and Pb = [b1;b2] and let the circle have its center on that line and pass through the point Q = [x;y], along with the above orthogonality requirement.

t = dot(Pb-Pa,Pb-Q)/dot(Pb-Pa,Pb-Pa);

C = t*Pa+(1-t)*Pb; % Center at orthogonal projection of Q onto line

R = norm(Q-C); % Circle's radius

p = linspace(0,2*pi,1000); % Parameter for generating circular plot

plot(C(1)+R*cos(p),C(2)+R*sin(p),'b-') % Plot the circle

(Of course you will also want the line to appear on the plot. I leave that to you.)

(Also I leave to you the need to do all the above for several points in an array and a like number of circles instead of a single Q, for which you will presumably need an appropriate for-loop.)

##### 0 Comments

### See Also

### Categories

### Products

### Community Treasure Hunt

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

Start Hunting!