Vector Bounces are glitching

Hello everyone,

ProjectionVectorProblem.gh (17.7 KB)

i try to simulate a simple version of light rays / raytraces / vector bounces with vectors in gh.

Most of the time the result looks correct but when I change the angle of the first vectors, sometimes they change direction very radically. The number slider which is responsible for this glitch is in the top left of my gh-script and labeled (problem starts if input is <10.00)

Correct looking:

Bugged:

Are there better alternatives for calculating light / vector bounces from surfaces? I want to try to build a bicycle reflector.

My script includes a custom py script with numpy (“pip install numpy”). Numpy is used to handle vectors more easily with code.

Code:

import numpy as np

def parse_vector(vector_str):
    """Convert '{x, y, z}' string to numpy array"""
    numbers = vector_str.strip('{}').split(',')
    return np.array([float(num) for num in numbers])

# Parse the vectors - n is normal vector of surface, v is incoming vector
n = parse_vector(y)
v = parse_vector(x)

# Normalize the normal vector
n = n / np.linalg.norm(n)

# Compute reflection
r = v - 2 * np.dot(v, n) * n

# Convert result back to {x, y, z} format
reflected = f"{{{r[0]}, {r[1]}, {r[2]}}}"

print(reflected)

Maybe someone can help me :smiley:
Thank you!

the issue comes not at slider <10 but at slider <10.60 (in that particular configuration):

the reason for that is you lose one intersectino point because the Surface|Line intersection does not happen, but the Python component does not know that, and so it re-links that point to the last one in the Longest List behavior:

the fastest way to solve this is to graft the top vectors and not flatten the output ones from Surface|Line intersection:

this way the tree structure will be coherent, some branches (for which intersections aren’t happening) will stay empty and cause the next component to turn red, but everything else will work fine:

ProjectionVectorProblem_inno.gh (21.3 KB)

Thank you so much!! :clinking_beer_mugs: