- Home /
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.
Answer by DMGregory · Jun 06, 2014 at 03:17 PM
Try:
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.
Yes that is exactly what i needed.Works like a charm.Thank you very much!I need to study more linear algebra to get my things straight.
Answer by robertbu · Jun 06, 2014 at 02:31 PM
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.
No it does not work.It does something else that it's not on the graphed results.Let me put it up again: I need the perpendicular of the normal (N) to point in the direction which the ray is.
For instance the pependicular of the hit normal is: Vector3(-hit.normal.y, hit.normal.x) * -1; or Vector3(-hit.normal.y, hit.normal.x); I want to find which one of those should it be used, depending on the casted ray's direction.
Your answer
Follow this Question
Related Questions
exact vector reflection along collision normal vector 1 Answer
Custom gravity based on normal vector and rigidbody.addForce 2 Answers
How to find perpendicular line in 2D? 3 Answers
Generate cylindrical mesh around 3D Catmull-rom spline 1 Answer
How to get the normal of a line in relation to a specific point in 3D? 1 Answer