How I can continue vector if I know two points of vector and direction vector?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
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])

Accepted Answer
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 Comments
Aknur
on 2 May 2023
Dear @Chunru thank you so much for your valuable help. It works perfect! I am so happy! Thank you for your time, I really appreciate it.
Can I ask one more question....
How I can turn out this extended vector like to opposite direction. I attached picture
From Xr, Yr, Zr to the same Xc, Yc, Zc but opposite
Thank you in advance for you time and help

Chunru
on 3 May 2023
For ray tracing, the code can be complicated since you have to consider which boundary and where the ray hit. Once you have determined the reflection point, you need to find out the equation of the reflection ray, noting that the incident and reflection rays are on the same plane and the incident angle equal to the reflection angle.
You should refer to some ray tracing books for the detailed formulation.
Aknur
on 3 May 2023
Dear,@Chunru I wrote equation of the reflection ray with this formula, find point of intersection. And have two angles azimuth and elevation
I found intersection point of incident ray with plane. Intersection point is also point of reflected ray.
And define direction of reflected ray using Rr = Ri - 2 * (dot(Ri, n)) * n;
and equation of reflected ray using this Rray= Pint + sI.*Rr;
Intersection point Pint is my Xr, Yr, Zr. And XBar, YBar, ZBar are my unit direction vector. I found it using this. (Angles Phi and Theta - 30, 45 resepectively)
Light point (1.5 1.5 3.0)
XBar = sind(Theta0) * cosd(Phi0);
YBar = sind(Theta0) * sind(Phi0);
ZBar = cosd(Theta0);
I think my problem that I dont know how I should apply/use
Rr = Ri - 2 * (dot(Ri, n)) * n;
I think this equation should give me direction, But I could not understand how to use it for the reflected ray
As result I got this direction of reflected ray Rr
plane1 where ray hit the plane and reflect according to the angles
Rr =
-98.5920 0.3536 0.7071
Rray: 241.500000
Rray: -0.232051
Rray: -0.464102
will appreciate if you can advice what I am doing worng, or any documentation. Thank you in advance
BR, Aknur
Chunru
on 3 May 2023
See the update above.
Aknur
on 3 May 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
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
See Also
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)