Ray Tracing

This function is used quite a bit in rendering, so I think there should be something suitable out there.
The application is a ray passing through matter defined as a voxelized 3D volume (in 2D would like a planar mesh) with different materials in each voxel. I would like to calculate the attenuation of the ray through the volume.
To do this, I would need to get the voxels that are intersected by the line and the path length through each voxel: VoxelID, Distance.
I can implement this in Rhino by creating an array of faces to form a 3D rectangular mesh and calculating the points of intersections with each face (done). Then, I would need to identify the corresponding voxels of the intersected faces and compute the distance. This can be done, but may take some time plus might be slow.
Is there a set of simpler functions in Rhino?
If not, what about C, C++, C# or VB?

Thank you. Joseph

Are you looking for something like http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Intersect_Intersection_RayShoot.htm ?

Hi Nathan / All,
Unfortunately, it is not. Let me clarify.
In the enclosed picture, a volume broken into rectangular voxels (“boxes”) is shown. A ray (line) intersects the faces of the voxels at the points. The goal is to identify the voxelID and compute the path length (distance) through each voxel. The output would be an array of VoxelID and pathlength.
I created this geometry using a mesh of faces and found the points using Intersection.MeshLine. I reordered the points along the line, calculated the pathlengths and now need somehow to find the voxelDs associated with the intersected faces. So, there is a solution to this problem using this approach. But it is convoluted and not efficient
Again, this is a common problem.
Assume a light source and an object made of pixels with each pixel having an opacity. The source rays go through the object an the light is attenuated. To calculate the attenuated light, we need the opacity of the intersected pixels and the path length through each pixel.
Hopefully, this clarifies the problem.
Thank for your reply!

RayTracing.pdf (33.5 KB)

Hi @joseph.bendahan,

Just to clarify, Rhino does not contain a ray-tracing API. And you wish is for us to add one?

– Dale

1 Like

You probably could add a very thin cylinder and use that with http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Intersect_MeshClash_Search_1.htm. Then iterate over the MeshClash and check against the original ray line to see if it actually intersects. This might give you the meshes you’re looking for. Note that this was just thinking out loud - I haven’t tested this.

Sure, it would be great if Rhino would have Ray Tracing.
How does this go, I wish it and voila, you implement it? :slight_smile:
Thank you.