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

33 ビュー (過去 30 日間)
Ender Rencuzogullari
Ender Rencuzogullari 2015 年 12 月 3 日
コメント済み: Dev Chhatbar 2022 年 12 月 18 日
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 件のコメント
dpb
dpb 2015 年 12 月 3 日
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 2015 年 12 月 3 日
sorry about missing information. the circle's center is positioned at
[0 , 0]

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2015 年 12 月 3 日
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 件のコメント
Star Strider
Star Strider 2019 年 6 月 14 日
@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 2022 年 12 月 18 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by