Ray bounce out of the surface - looking for the GH component

In Rhino there is a Bounce command, I’m looking for the exact same thing but in Grasshopper (Rhino 8). I saw some very old GH attempts somewhere on the Internet but they do not work for me. Is there a component that I might have just missed?

I just want to get a line bounced out of a surface.

Hello
You can use this one

It uses multiple surface for multiple réflexion

Is it this simple? Substitute any surface for the sphere.


bounce_line_2024Aug2a.gh (8.8 KB)

P.S. Or simpler?


bounce_line_2024Aug2b.gh (7.9 KB)

Hi, sorry I know it should be easy in Grasshopper and it turns out it really is. Sometimes I try to solve problems in GH but end up complicating them. I just asked if there is a bounce component, you gave me a good, short solution made out of multiple components. Thank you.

@laurent_delrieu
Thanks for the component. It mostly solves the problem. However, Bounce command operates on an unsorted list of surfaces and rays can bounce multiple times from the same surface.
Using C# component surfaces must be ordered, which is only easy in simple scenarios. I can obtain multiple bounces by repeating surface inputs, but again it’s only feasible in simple cases.

Or a loop (white group) to repeat the process.


bounce_line_2024Aug5a.gh (27.7 KB)

My use case was simple, so I didn’t add complexity, it could be quite simple to bounce until a ray escape, also it could be better to use all sort of geometry as input (plane, surface, BRep, mesh,…).

I took shortcuts with the Anemone loop, assuming two planar surfaces with a single ray bouncing off the bottom surface first, even if it passes through the top surface. The loop could be modified to work with an unsorted list of curved surfaces. Multiple rays might be handled with nested loops, the outer loop going through a list of rays, one at a time.

However, creating a flexible test bench is almost more complicated than the Anemone loop, unless a static set of surfaces (and rays) is created in Rhino.

Perhaps something like this.

240805a_RayShoot.gh (10.9 KB)

-Kevin

2 Likes

Hah, nice test geometry! Very nice. Why does it stop?

P.S. I think I know - because the ray “escapes” through the gaps?

Correct.

With the gap closed:

Also, the order of the input surfaces does not change the results.

240805b_RayShoot.gh (13.7 KB)

Edit: removed plug-in dependency.

-Kevin

2 Likes

“Shuffle”? From Pancake plugin? Why not Jitter?

Missed seeing the plug-in dependency, trying to multi-task :roll_eyes:

Edit post to correct.

-Kevin

It’s very cool. Would be nice, and more intuitive, to see the escaping ray that I showed as blue in my loop. That part was not easy…

P.S. Jitter ‘J’ input defaults to 1 so no need for text panel.

Thank you, very nice solution.

Not to be too picky, but that would make it an ultimate solution. Also, right now this component is not very suited to situations where there is only one bounce. Of course, I can fix that with some script after the last bounce point is determined by the C# script.

I’d like to “dress up” this code a bit before posting it, giving proper credit to @kev.r of course.

On second thought, here it is:


RayShoot_2024Aug6a.gh (34.1 KB)

More can be done to enhance the start point and direction. Later. Thanks again Kevin.

NOTE: If the closing surface is added to the “obstacles”, the last ray is still shown “escaping”. :thinking:

I think a more general answer would be the following:

If you don‘t find a Rhino function inside Grasshopper, then you might be lucky and find a corresponding feature in the Rhinocommon Api. But the Api does is not align to the commands, nor does it allow you to do exactly the same, unfortunately. But its close. Grasshopper in comparison is even less than Rhinocommon.

Calling an api function is not difficult if you have a basic understanding of programming. Its rather knowing the api. Therefore, if you plan to do more in Grasshopper, it definitely helps to read and play with Rhinocommon.
You would be surprised how many plugins heavily rely on simple api calls. So under the hood the majority of work is still McNeels credit, although I admit that it requires a bit of expertise to know where things are…

That ignores a variety of solutions that are possible without scripting. :roll_eyes:

In the meantime, I prepared something like this. Used C# component by @kev.r and some method posted earlier by @Joseph_Oster.

Ray Bounce 2.gh (37.3 KB)

In this script rays are separated into 3 groups: rays that do not hit any geometry, bounce only once, and bounce multiple times.


However, doing this I realized there is quite a big issue. Both Kevin’s C# component and Rhino’s Bounce command do not account for holes in the surfaces. You can see that the round hole is ignored.

Rhino Bounce command

1 Like

This is not my point. The majority of components are calling Rhinocommon. You are doing almost exactly the same if you connect components on the canvas. You only lack the full „access“.
Creating a „Ray“ instance and feed it into function which performs this „bounce“ is close to zero effort. Knowing Rhinocommon is a big plus in Grasshopper. That is all I‘m saying.

Yes, the RhinoCommon documentation on the Rhino.Geometry.Intersect.Intersection.RayShoot() function states “Trims are ignored on Breps”

https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.intersect.intersection/rayshoot

-Kevin