필터 지우기
필터 지우기

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

조회 수: 31 (최근 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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by