文章目录
1.问题描述
该问题同二维平面上求解过圆上一点的直线问题类似。
2.已知条件
已知球体表面上一点P, 球心C,求球面上P点的切面M。
3.求解
令向量 n = P − C n = P-C n=P−C,则 u = ( n y , − n x , 0 ) , v = u × n u=(n_y,-n_x,0),v=u\times n u=(ny,−nx,0),v=u×n
平面 M = P + t ⋅ u + m ⋅ v M = P+t\cdot u +m\cdot v M=P+t⋅u+m⋅v
4.Code
matlab
close all;
clear;
rng default;
C = rand(1,3);
r = rand();
t = rand(1,2)*pi;
P = C + [r*cos(t(1))*sin(t(2)), r*sin(t(1))*sin(t(2)), r*cos(t(2))];
t = linspace(0, 2*pi, 50);
u = linspace(0, 2*pi, 50);
[t,u] = meshgrid(t,u);
x = C(1) + r*cos(t).*sin(u);
y = C(2) + r*sin(t).*sin(u);
z = C(3) + r*cos(u);
n = normalize(P - C,'norm');
m = [0, n(3), -n(2)];
l = cross(m,n);
c1 = linspace(-1,1,20);
c2 = linspace(-1,1,20);
[c1,c2] = meshgrid(c1,c2);
xx = P(1) + c1*m(1) + c2*l(1);
yy = P(2) + c1*m(2) + c2*l(2);
zz = P(3) + c1*m(3) + c2*l(3);
figure;
mesh(x,y,z);
axis equal
hold on
mesh(xx,yy,zz)
hold on
scatter(P(1),P(2), P(3),'filled')