# ray tracing, indices and path length registration

15 views (last 30 days)
Albert on 2 Oct 2017
Commented: Albert on 27 Jun 2018
Dear all
Thank you for reading my following question and I greatly appreciate any of your help.
Problem: Given a grid (N*N) and a non-straight ray with known discrete coordinates, how to register the indices and path length in the pixels crossed by the ray? This is on a plane, what if it is in 3d space? Are there any existing MATLAB script to carry out this function?
Thank you very much.
Sincerely
Albert

Albert on 5 Oct 2017
Thank you Corey, although it's not what I need. I am doing muon tomography. We have already found way to register muon most likely trajectory represented by discrete points. Now I am focusing on a function which could register the indexes and segment length in these voxels/pixels intersected by the trajectory. Here is a function
https://www.mathworks.com/matlabcentral/fileexchange/56527-fast-raytracing-through-a-3d-grid
It's quite close to what I need, but it doesn't register segment length in these voxels/pixels. I am modifying this function now.
Thank you
Alexander Jones on 26 Jun 2018
Hello, I am trying to do some microwave tomography, and am in need of a very similar thing - I was wondering if you found a solution to the problem of finding path length, and if so if you could please point me in the right direction.
Albert on 27 Jun 2018
Hi Jones,
To be clear, are you trying to trace a straight or curve? If it is for straight, please see https://www.mathworks.com/matlabcentral/fileexchange/28496-tomobox?focused=5159748&tab=function
Anyhow you may want to have a look at this document for the theory behind the code, see here (much efficient than calculating the interaction) http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.42.3443&rep=rep1&type=pdf
If you are looking at curve rather than straight ray, as Anton Semechko mentioned, the curve ray may be represented by segments, for each segment you can use the above code to calculate index and path length, but you need truncate the result before you concatenate them together for one ray. Because the above code calculates the index and path length in each voxel for straight line across the whole image reconstruction volume.
The above code can handle 2D and 3D.
Good luck.

Anton Semechko on 26 Jun 2018
Edited: Anton Semechko on 26 Jun 2018
For 2D reconstruction, the problem can be approached follows:
1) Let's say you have a set of K rays {Rk}, where Rk is k-th ray parameterized by the equation Rk(t)=Xk+t*Dk, where Xk is the point of origin and Dk is the direction of travel.
2) Given a M-by-M grid (G) sampled on a plane passing through point P with unit normal N, find points of intersection between G and all of the rays {Rk}.
3) Find transformation that aligns N with the z-axis, and horizonal and vertical grid lines of G with the x- and y-axes, respectively.
4) Apply the transformation from (3) to the points of intersection in (2).
5) Bin data from (4) to get the intensity image corresponding to the number of hits in a given bin (i.e., grid cell/pixel).
This process can be easily generalized to get a volumetric image using a 3D grid. This is because 3D grid is just a stack of 2D grids.