Ray Tracing
- ray_trace(ray_start, v1_to_v2, init_plane, v_dims, num_planes)
Ray trace through a uniform grid of planes, using Siddon’s algorithm. The grid is defined by the initial plane (
init_plane), which is the coordinate of the top left corner of the voxel cube, the dimensions of each voxel in the voxel grid (v_dims), and the number of planes in the grid (num_planes). The ray is defined by the starting point (ray_start) and the direction vector from the starting point to the end point (v1_to_v2).- Parameters:
ray_start (
3x1 double) – The coordinates of the starting point of the ray.v1_to_v2 (
3x1 double) – The direction vector from the starting point to the end point of the ray.init_plane (
3x1 double) – The coordinates of the top left corner of the voxel cube.v_dims (
3x1 double) – The dimensions of each voxel in the voxel grid.num_planes (
3x1 double) – The number of planes in the grid.
- Returns:
lengths (
1xN double) - The lengths of the ray in each voxel.indices (
3xN double) - The 3D indices of the voxels that the ray passes through.
- ray_trace_many(ray_start, v1_to_v2, init_plane, v_dims, num_planes)
Perform many ray traces through a uniform grid of planes, using Siddon’s algorithm. The parameters are defined as follows:
- Parameters:
ray_start (
3xM double) – The coordinates of the starting points of the rays.v1_to_v2 (
3xM double) – The direction vectors from the starting points to the end points of the rays.init_plane (
3x1 double) – The coordinates of the top left corner of the voxel cube.v_dims (
3x1 double) – The dimensions of each voxel in the voxel grid.num_planes (
3x1 double) – The number of planes in the grid.
- Returns:
lengths (
1xM cell) - A cell array where each cell is a 1xN array representing the lengths of the ray in each voxel.indices (
1xM cell) - A cell array where each cell is a 3xN array representing the 3D indices of the voxels that the ray passes through.
Both of these functions use the same algorithm, but the second function is optimised for many rays. They are also able to be converted to MEX files for faster computation, using the MATLAB Coder app.