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

3 visualizzazioni (ultimi 30 giorni)
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.
Thank you in advance for your help
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])

Risposta accettata

Chunru
Chunru il 2 Mag 2023
Modificato: Chunru il 3 Mag 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
  6 Commenti
Aknur
Aknur il 3 Mag 2023
Thank you dear @Chunru. Than you for your time and tremendious help. I have to say that for me azimuth angle is Phi, and elevation is Theta. I am sorry it was my mistake in previous comment. And I use these equations
XBar = sind(Theta0) * cosd(Phi0); %direction vector
YBar = sind(Theta0) * sind(Phi0);
ZBar = cosd(Theta0);
could you please check
I have couple of questions
1) When you find Xr, Yr, Zr you use parametric equation
And kindly ask about slope. To find k you divide it for XBar. I could not understand.
% Here we use only one boundary X=3
Xr = 3;
k=(Xr-X0)/XBar;
Xr = X0 + k*XBar;
Yr = Y0 + k*YBar;
Zr = Z0 + k*ZBar;
k is slope right
I found Xr, Yr, Zr use intersection point. Coordinates of intersection point become Xr, Yr, Zr
2) I have checked all 6 planes for the intersection, using this example and set a limit
https://www.mathworks.com/matlabcentral/fileexchange/103835-plane-and-line-intersection
If room dimension 3*3*3 and normal (for example for bottom plane 6) = 0 0 9 is it right? Or I am wrong, sorry for stupid question
planes(:,:,6) = [0 3 3; 3 3 3; 0 0 3; 3 0 3; 0 0 3];
for j=1:6
j
plane = planes(:,:,j);
p0 = plane(1,:); %coordinates of plane
p1 = plane(2,:);
p2 = plane(3,:);
p3 = plane(4,:);
V0 = plane(5,:); % any point lies on plane
3) n2 is direction of reflected ray
When I calculated direction of reflected vector I use as an initial point light position (X0, Y0, Z0) and you used (XBar, YBar, ZBar) (I used this function for intersection point https://www.mathworks.com/matlabcentral/fileexchange/103835-plane-and-line-intersection)
Now I am doubt if I did it correctly because I did not use parametric equation for Xr, Yr, Zr
But I used X0, Y0, Z0, XBar, XBar, ZBar to find intersection point
4) in reflection graph I don’t understand how you find that reflection will intersect with Z=0. Could you please clarify for me
% The reflection will intersect with Z=0
Z1 = 0;
I think I could not take an exact number, it should be maybe variable
5) Kindly write one more question about X1, Y1, Z1
Is it obligatory to multiply by slope to find X1, Y1, and Z1? As I understand direction of reflected ray will give use direction and we can catch point lies on this vector which will inside of room. Or I think your way when you sum Xr and k and direction of reflected ray already include this dimension 3*3*3, am I right?
Thank you in advance for your time and consideration
Best regards, Aknur
Aknur
Aknur il 3 Mag 2023
Modificato: Aknur il 3 Mag 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Propagation and Channel Models in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by