path_reduction_factor=V_sphere/V_capsule# a capsule has a lower attenuation because the same mass is smeared through a larger volume, so we need to lower the effective path length through the material
# define a local coordinate reference system with z along the direction of displacement, and x and y normal to that
z_unit_vector=displacementsMM[sphere]/axis_length
y_vector=numpy.cross(z_unit_vector,z_unit_vector*numpy.random.rand(1,3))# dont really care which direction y is in as long as it is normal to z
x_vector=numpy.cross(y_vector,z_unit_vector)# and a third normal direction
A=numpy.vstack([x_vector/numpy.linalg.norm(x_vector),y_vector/numpy.linalg.norm(y_vector),z_unit_vector])# rotation matrix to go from global to local coordinates
ray_source_rotated=numpy.dot(A,-positionsMM[sphere])# apply the rotation matrix
# check for intersection with cylinder at ANY LOCAL z, i.e. does it cross the circle defined by the capsule. not a guarantee of collision with the capsule, just a collision with the infinite cylinder.