Getting perpendicular direction vector from surface normal

Hello guys. My problem which i can’t solve is this:
I want to find out the perpendicular direction of a normal (the red arrow) from the surface normal (green line) which must always point at the direction of the ray (light purple color).Just to clarify: i know how to find the perpendicular of the normal, but i don’t know how to get the correct perpendicular in order to achieve the result from the image.


Vector3 surfaceParallel = direction - normal * Vector3.Dot(direction, normal);

This subtracts any part of direction that’s parallel to normal, leaving only the perpendicular component. Note that if direction and normal are completely parallel, this will give you a zero vector. In other cases, you can normalize it to get a unit vector in the desired direction.

I think this gives it to you:

var v = Vector3.cross(n,ray.direction);
var direction = Vector3.cross(v,n);

You may have to reverse the order of the parameters of the second Cross.