How I can define/ calculate reflection of the ray correctly? As my reflection makes mistake in direction
Afficher commentaires plus anciens
Hello, everyone. Kinsly ask about advice or suggestion about how to find reflection of incidence ray and plot it
How I can make reflected ray in 3d indoor. I wrote function step by step but when it reflects it does not work properly. Maybe you can advice me function or documentation/source. I did everything with geometry. And tried then to solve using Rr = Ri - 2 N (Ri . N)
and my R become like 0.7 1.5 -157 which is not coreect.
The main problem that my ray does not reflect from the surface. I found intersection. Maybe something wrong with my directional vector and angles theta
Thank you in advance
19 commentaires
William Rose
le 9 Mar 2023
Modifié(e) : William Rose
le 19 Mar 2023
[edit: Add text to clarify what
represents, and corrct spelling mistakes.]
The equation you provided looks correct, for the direction of the ray. The equation you gave does not accont for the location of the ray. To account for the location of the reflected ray, you must specify a point
that the incident ray passes through, and some point
in the reflecting plane.
can be anywhere in the reflecting plane; it does not need to be the intersection point.
is needed to establish the location of the plane. The plane's orientation is given by its normal vector,
. From these we can calculate where the incident ray intersects the plane; this point is also on the reflected ray.
Direction of reflected ray: 

where
is the normal to the plane.

The the equation for the reflected ray is
where
and
are given above.
Aknur
le 10 Mar 2023
William Rose
le 10 Mar 2023
@Aknur, you can specify the incident ray using the initial point
and the direction vector
, where you have computed
using the two angles which you know. The equaiton for the incident ray is
, where t is a scalar that varies from
to
. Then you can compute the intersection point
where the incident ray intersects the plane, using the equation I gave before. That intersection point is a point on the reflected ray. Therefore you can specify the reflected ray by
, where
is given in the equaiton in my answer above.
Aknur
le 12 Mar 2023
William Rose
le 13 Mar 2023
@Aknur, you are welcome.
William Rose
le 19 Mar 2023
Modifié(e) : William Rose
le 19 Mar 2023
@Aknur,
is a point in the plane. Point
can be anywhere in the plane. Point
is needed to define the locaiton of the plane. I added text to my comment above, to explain the meaning of point
.
The equation the direction vector, which you gave in your comment above, does not appear to be correct. I think that you have added two vectors to each other: the vector [X0;Y0;Z0] which specifies a location, and a direction vector with unit length, [
]. These vectors should not be added together.
[Edit: change comment about direciton vector]
The direction vector [
] is correct, if the polar angle θ is measured from the z axis, and if the azimuth angle ϕ is measured in the X-Y plane, starting at the +X axis.
Aknur
le 25 Mar 2023
William Rose
le 26 Mar 2023
Aknur, When a ray is reflected, both the azimuth, phi, and polar angle, theta, of the reflected ray are different from phi and theta for the incident ray. There is no simple formula for reflected phi and theta in terms of incident phi and theta. The formula for the reflected ray, given above, can be used to find phi and theta of the reflected ray. Thank you very much for your kind comments. I am traveling and I am not good at using my cell phone for Matlab Answers.
Aknur
le 27 Mar 2023
William Rose
le 2 Avr 2023
I will look at your code if you add a lot of comment to it - to the main script and to the funciton. For the script, explain in the comments what you are trying to do and what the different variable are. Are you reflecting a ray off or a series of mirrors? Each mirror should be described by a normal vector and by a point that lies in the plane. Please make it clear in the code which variables are the normals to each plane and the points in each plane. Each ray should be described by a direction vector and by a point on the ray. Please make it clear in the code which variables are the directions of each ray and the points on each ray.
For the function, please explain the role of each input variable and each output variable in the comments. That is a good general practice.
You said "I have failed with my attemp to solve Phi angle of reflected ray." Did you mean to say "theta angle of reflected ray"? I ask this because you refer to theta and 90-theta when discussing angle of incidence.
You said " I still have issue with my azimuth angle Phi." Please explain what issue you have with the azimuth angle. Azimuth angle is measured with respect to some coordinate system. What coordinate system do you want to use when measuring azimuth?
The formula which I provided as my original answer gives the reflected ray direction and a point on the ray (the reflection point, where it insrersects the plane) in "absolute" coordinates, i.e. in terms of an absolute sets of x,y,z axes. The angle of incidence and angle of reflection, which are the subjects of the law of reflection, are measured with respect to the normal to the plane. Therefore it is not true that the angle incidence is the angle down from the z axis, unless the reflecting plane is parallel to the x-y plane.
William Rose
le 5 Avr 2023
Thank you for your updated code with comments added.
I am not able to follow the logic of this code, and I cannot determine why you are computing thisnhgs the way you are. YOur orignal quesiton was how to compute the formula for a ray reflected by a plane. My earlier answer did not inclide azimuth or angle. You are interested in azimuth and angle and I am not sure why. I don;t understand why they are relevant for your problem.
Therefore I wrote a script that computes N rays (i.e. N- reflections) from M planes, to demonstrate that you do not need azimuth or angle to answer your quesiton. My code also illustrates that there are additional issues you must address when reflecting from multiple planes: 1. You must determine which plane a ray will strike first, because a given ray may intersect more than one plane. 2. You must propagate the ray forward, and not backward, so that intersections with planes behind the ray are not mistakenly identified as the first reflecting plane. (A plane behind could be closer, but if it is behind then we do not want to reflect off of it.) 3. If the planes do not form a bounding box, then it is possible that the ray esscapes from the planes before N-1 reflections have occurred. The code must deal with this possibility correctly.
You do not need azimuth or angle to do the calculations above. The inclusion of azimuth or angle leads to confusion, in my opinion.
My code, attached, deals with the above issues successfully. By adding and removing comments, you can demonstrate that is gives the expected answers. In al three examples, the ray begins at point (1,1,1). In all three examples, there are three planes passing through the origin: plane 1=Y-Z plane though x=0, plane 2=X-Z plane through y=0, plane 3=X-Y plane through z=0. In exaple 1 and example 2, there is also plane 4=X-Y plane thorugh z=+3. The normal vector of plane 1 is (0,0,1); the normal vector of plane 4 is (0,0,-1).
Example 1: 4 planes, initial ray direction=(-.8, 0, -.6).
Example 2: 4 planes, initial ray direction = (-.8, -.6, 0).
Example 3: 3 planes, initial ray direction = (-2/7,-3/7, -6/7).
William Rose
le 6 Avr 2023
@Aknur, I added a section of code to compute and display the altitude and azimuth of each ray, since you are interested in that information. See attached. With the attached, code, the console output, for example 1, is shown below. I this example, there are 4 reflecting planes, and 6 rays are computed. The initial ray direciton is (-.8,0,-.6). Therefore the intial ray has no y-component to its direction. Therefore the initial ray is paralell to the X-Z plane. Therefore the intial plane and all of the reflected rays never intersects plane 2, which is the X-Z plane through y=0.
>> rayReflection
Ray 1 reflects off plane 1 to make ray 2.
Ray 2 reflects off plane 3 to make ray 3.
Ray 3 reflects off plane 4 to make ray 4.
Ray 4 reflects off plane 3 to make ray 5.
Ray 5 reflects off plane 4 to make ray 6.
Ray Altitude Azimuth
___ ________ _______
1 -36.87 180
2 -36.87 0
3 36.87 0
4 -36.87 0
5 36.87 0
6 -36.87 0
William Rose
le 11 Avr 2023
I do not understand why phi becomes important if the box is rotating. If I were simulating reflections inside a rotating box, I would not use phi to compute reflections. I would continue to compute reflections with code similar to the code I provided. The difference would be that the reflection computation would be inside a loop that corresponds to time steps, and the orientation vectors of the reflecting planes would be functions of time.
Aknur
le 11 Avr 2023
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Airfoil tools dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!