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 ![]()
Thank you!



