how to plot tangent line from specified point to a circle ?

49 views (last 30 days)
Dear Friends,
There is a specified point which is;
[X , Y]
And there is a circle which radius is
r
Before I asked, I searched for the answer and I found something. However, the codes that I found did not work for my program and I don't know why. so how can I plot a tangent line from this point to this circle with 'r' radius. Thanks
  2 Comments
dpb
dpb on 3 Dec 2015
Well, there has to be more than just the circle radius...you've got to be able to locate it somehow...the radius only says how big around it is, nothing at all about "where"
Ender Rencuzogullari
Ender Rencuzogullari on 3 Dec 2015
sorry about missing information. the circle's center is positioned at
[0 , 0]

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 3 Dec 2015
See if this does what you want:
a = linspace(0, 2*pi); % Assign Angle Vector
r = 2; % Radius
ctr = [2 3]; % Centre
x = ctr(1) + r.*cos(a); % Circle ‘x’ Vector
y = ctr(2) + r.*sin(a); % Circle ‘y’ Vector
dxda = -r.*sin(a); % Derivative
dyda = r.*cos(a); % Derivative
dydx = dyda./dxda; % Slope Of Tangent
N = 21; % Choose Point On Circle (As Index)
point = [x(N) y(N)]; % Define Point
intcpt = point(2) - dydx(N).*point(1); % Calculate Intercept
xvct = point(1)-1:point(1)+1; % ‘x’ Vecor For Tangent
tngt = dydx(N).*xvct + intcpt; % Calculate Tantent
figure(1)
plot(x, y) % Plot Circle
hold on
plot(point(1), point(2), 'gp') % Plot Point
plot(xvct, tngt) % Plot Tangent At Point
hold off
axis equal
grid
  13 Comments
Star Strider
Star Strider on 14 Jun 2019
@Scott McCleary —
The ‘xvct’ vector is simply the independent variable of the line calculated in the ‘tngt’ assignment (dependent variable for the tangent line), and the plotted in:
plot(xvct, tngt) % Plot Tangent At Point
Dev Chhatbar
Dev Chhatbar on 18 Dec 2022
Your above code works wonders. I was just curious as to know how would one adapt it such that it allows the user to pick a point and allow the user to input the x, y and radius components for the Circle? Would appreciate your help.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!