过圆外一点与圆相切的直线
文章目录
- 1.问题描述
- 2.已知条件
- 3.求解
- 4.code
1.问题描述
过定点与圆相切的直线,一般分为三种情况,a 定点在圆上(一个解)。b 定点在圆内(无解)。c 定点在圆外(两个解)。前面一节讨论了过圆上一点与圆相切的直线问题,该文接着讨论过圆外的一点,与圆相切的情况。
2.已知条件
圆心C,半径r,圆外点P。求过点P与圆相切的直线。Q为切点。
3.求解
4.code
clc;
close all;
clear;
%% Point P on the line is outside circle
rng default;
C = rand(1,2);
r = rand()*3;
theta = rand()*2*pi;
r_out = r + rand();
P = C+[r_out*cos(theta), r_out*sin(theta)];
u = P - C;
r_2 = r*r;
u_2 = u.^2;
delta = sqrt(-r_2^2*u_2(1) + r_2*u_2(1)^2 + r_2*u_2(1)*u_2(2));
x1 = (r_2 - r_2*u_2(2)/sum(u_2) - u(2)*delta/sum(u_2))/u(1);
y1 = (r_2*u(2) + delta)/sum(u_2);
x2 = (r_2 - r_2*u_2(2)/sum(u_2) + u(2)*delta/sum(u_2))/u(1);
y2 = (r_2*u(2) - delta)/sum(u_2);
u = linspace(0,2*pi,50);
circle = C + [r*cos(u'), r*sin(u')];
t = linspace(-5,5,50);
n = [-y1, x1];
L = P + t'*n;
n2 = [-y2, x2];
L2 = P + t'*n2;
figure;
plot(circle(:,1),circle(:,2));
hold on
plot(L(:,1), L(:,2));
hold on
plot(L2(:,1), L2(:,2));
hold on
scatter(P(1), P(2),'filled','o')
axis equal
grid on