Random Walk Responding to Boundary

I’ve got a basic random walk script. I’d like to modify it so that it turns inward, away from the boundary whenever it approaches it. Any ideas about how to approach this or suggestions for places to look are welcome! Thanks.

Random Walk Boundary.gh (33.1 KB)

You need to add a vector to its movement inside the loop. The vector should point away from the boundary. You might find the closest point on the boundary to your walker, then evaluate the curve at that parameter to find the tangent. Then you can use a cross product with the tangent and z axis to find your ‘stay inside boundary’ vector. You’ll want to scale the magnitude of this s carefully. You could use an inverse square

1 Like

Check this out. It’s under “6.5 Your Own Desires: Desired Velocity”.


Thank you @dharman! I integrated vectors into the script and then went in a slightly different direction. It works most of the time but it still sometimes jumps outside of the boundary - I’m trying to sort out why but it’s progress, I think.

Random Walk Boundary_0827.gh (35.0 KB)

Many thanks, @diff-arch. Very interesting context - this is exactly what I’m trying to do. If only I could script without Ghop components… future goals.

Well … never is toooooo late (or is it?). That said if you are in the AEC market sector go for C#.

Anyway for the general case (Lists of inner/outer GeometryBase containers either in 2 or 3 D) try to mastermind first some way to do this (Note: available RC RayShoot Method works on Breps (ignores Trims)/Meshes [not Curves] and requires some rethinking ASAP):

So if we “Loop Recursively” the above (with random generations , random amplitudes, random directions … etc etc PLUS using some sort of escape probability [a user controlled var]) we get that:

@dharman I hewed more closely to your suggestion and it works beautifully now. The cross product vector is the answer. Thank you!!

Random Walk Boundary_0828_WORKS.gh (23.9 KB)

You can keep the point inside the boundary by using Surface closest point

Random Walk Boundary.gh (11.5 KB)

1 Like