1.问题描述
直线过给定点与圆相切有多种情况,包括定点在圆上,定点不在圆上。该文讨论定点在圆上的情况。下图显示了一条通过一个圆上的给定点并且与圆相切的直线。 该问题同样可以推广到3维空间,即求球体上定点到切面,待续。。。
2.已知条件
圆心C,圆上定点P,求直线L。
3.求解
令向量
n
=
P
−
C
n = P-C
n=P−C,则
d
=
n
⊥
=
(
n
y
,
−
n
x
)
d=n^{\perp}=(n_y,-n_x)
d=n⊥=(ny,−nx)
所以 直线为:
L
=
P
+
t
⋅
d
L=P+t \cdot d
L=P+t⋅d
4.Code
clc;
close all;
clear;
rng default;
C = rand(1,2);
r = rand()*3;
theta = rand()*2*pi;
P = C+[r*cos(theta), r*sin(theta)];
n = normalize(P - C,'norm');
u = linspace(0,2*pi,50);
circle = C + [r*cos(u'), r*sin(u')];
t = linspace(-1,1,50);
L = P + t'*[n(2), -n(1)];
figure;
plot(circle(:,1),circle(:,2));
hold on
plot(L(:,1), L(:,2));
axis equal
grid on