This site uses strictly necessary cookies. More Information

X- Home /

# How do i find the normal of a line between two points?

I am trying to calculate the normal of a line between two points. The points are world-space vectors from two Raycast hits.

But I am having trouble calculating the yellow normal shown in the picture below.

Any help would be much appreciated.

**Answer** by Bunny83
·
Nov 16, 2018 at 11:14 PM

Since this is just a 2d problem the solution is actually quite trivial ^^. To get the green line, just subtract the two hit points from each other. To rotate a 2d vector by 90° you just have to swap the x and y values and invert **one** of them. Which one you invert dictates the direction you're rotating (clockwise / counter clockwise).

```
Vector2 green = hitLeft - hitRight;
// rotate 90° Clockwise
Vector2 normal = new Vector2(green.y, -green.x);
```

You may want to normalize the result in case you need a normalized vector.

Note that the rotation direction depends on the coordinate system. I assumed screen space where the origin is in the bottom left and the positive axis go right (x) and up (y).

This worked like a charm! Just what I was looking for. Didn't realize it was this trivial, might have overcomplicated things a bit ^^. Thank you very much for the quick and accurate answer!

### 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.