# How I can continue vector if I know two points of vector and direction vector?

4 views (last 30 days)
Aknur on 2 May 2023
Edited: Aknur on 3 May 2023
Hello everyone! Kindly ask if I have two points of vector A( X0, Y0, Z0) and B(Xr, Yr, Zr). And I plotted vector in a 3d cube. How I can continue the line of vector further after Xr, Yr, Zr. I need new coordinates of the point which lies on this vector and this point will be lower than B.
X0 = 1.5;
Y0 = 1.5;
Z0 = 3.0;
Theta0 = 45;
Phi0 = 30;
XBar = sind(Theta0) * cosd(Phi0); %second point of ray outside of the room
YBar = sind(Theta0) * sind(Phi0);
ZBar = cosd(Theta0);
ThetaBar = Theta0;
PhiBar = Phi0;
Xr = 0;
Yr = 0.6340;
Zr = 1.2679;
plot3([X0 Xr], [Y0 Yr], [Z0 Zr]) Chunru on 2 May 2023
Edited: Chunru on 3 May 2023
X0 = 1.5;
Y0 = 1.5;
Z0 = 3.0;
Theta0 = 10; % azimuth
Phi0 = -45; % elev
XBar = cosd(Theta0) * cosd(Phi0); %second point of ray outside of the room
YBar = sind(Theta0) * cosd(Phi0);
ZBar = sind(Phi0);
% Reflection points along AB
% Intersection with boundary (need to check all boundaries)
% Here we use only one boudary X=3
Xr = 3;
k=(Xr-X0)/XBar;
Xr = X0 + k*XBar;
Yr = Y0 + k*YBar;
Zr = Z0 + k*ZBar;
% The incident direction
inc = [XBar YBar ZBar];
% Normal of the boundary (X=3)
s = [-1 0 0]; % pointing inside the box
% The reflection direction
% n2 = n1 -2 dot(n1, s) s
n1 = [XBar YBar ZBar]; % incident
n2 = n1 - 2*dot(n1, s)*s;
% The reflection will intersect with Z=0
Z1 = 0;
k=(Z1-Zr)/n2(3);
X1 = Xr + k*n2(1);
Y1 = Yr + k*n2(2);
Z1 = Zr + k*n2(3);
plot3([X0 Xr X1], [Y0 Yr Y1], [Z0 Zr Z1])
xlabel("x"); ylabel("y"); zlabel("z")
text([X0 Xr X1], [Y0 Yr Y1], [Z0 Zr Z1], ["X_0", "X_R", "X_1"]);
box on; grid on
set(gca, 'BoxStyle', 'full')
axis([0 3 0 3 0 3]) %view(2)
[X0 Y0 Z0; XBar YBar ZBar; Xr Yr Zr; X1 Y1 Z1]
ans = 4×3
1.5000 1.5000 3.0000 0.6964 0.1228 -0.7071 3.0000 1.7645 1.4769 1.5456 2.0209 0
Aknur on 3 May 2023
Edited: Aknur on 3 May 2023
Dear @Chunru
Here is my code, but I did not use n2 (Rr in my script) because I did not know how to use.

### Categories

Find more on Function-Based Unit Tests in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!