- 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

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.