matlab练习程序(Householder光线反射)

已知入射光线向量X和平面方程法向量w,可以通过Householder变换求出反射向量Y。

Householder变换公式如下:

那么反射向量Y=H*X

matlab代码如下:

clear all;close all;clc;

%plane:1*x+2*y+3*z = 0
w = [1 2 3]';
w = w / norm(w);

%line:[x=5t y=3t z=4t]
l = [5 3 4]';
l= l / norm(l);

[X,Y] = meshgrid(-1:0.1:1);
Z = (w(1)*X+w(2)*Y)/(-w(3));
mesh(X,Y,Z);

hold on;
t=-1:0.1:1;
x = w(1)*t;
y = w(2)*t;
z = w(3)*t;
plot3(x,y,z,'b');

x = l(1)*t;
y = l(2)*t;
z = l(3)*t;
plot3(x,y,z,'r');

H = eye(3) - 2*(w*w');  %householder变换
l_ref = H*l;

x = l_ref(1)*t;
y = l_ref(2)*t;
z = l_ref(3)*t;
plot3(x,y,z,'g');
axis equal;

结果如下:

posted @ 2022-09-18 13:41  Dsp Tian  阅读(727)  评论(0编辑  收藏  举报