- Home /

# Find Line intersections

It seems like there is a simple solution, but it's very frustrating. I can't seem to find it.

How can I find the point where the lines A-a and B-b intersect?

I basically want something like

```
Vector3 x = GetIntersection(A, a, B, b)
```

with (lower case) **a** and **b** being the directions of the lines, their actual points are not important. They could be directional coefficients or normalized vectors.

It seems like a job for Vector3.Cross? Unfortunately I don't understand how it works.I just get zeroes and small numbers with GetNormals(A, Vector3.Zero, B)

```
Vector3 GetNormal(Vector3 a, Vector3 b, Vector3 c)
{
// Find vectors corresponding to two of the sides of the triangle.
Vector3 side1 = b - a;
Vector3 side2 = c - a;
// Cross the vectors to get a perpendicular vector, then normalize it.
return Vector3.Cross(side1, side2).normalized;
}
```

Seems like basic math, but I could really use some help with this!

**Answer** by MT369MT
·
Aug 12, 2018 at 01:33 PM

Hi, this is a function that get the intersection point of two lines. Thanks the help of this sites: https://www.habrador.com/tutorials/math/5-line-line-intersection/ http://thirdpartyninjas.com/blog/2008/10/07/line-segment-intersection/

I don't know if there are easier ways to do it, but I tested this (in 2D) and it should work.

```
Vector3 GetIntersection(Vector3 A, Vector3 a, Vector3 B, Vector3 b)
{
Vector2 p1 = new Vector2(A.x, A.y);
Vector2 p2 = new Vector2(a.x, a.y);
Vector2 p3 = new Vector2(B.x, B.y);
Vector2 p4 = new Vector2(b.x, b.y);
float denominator = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);
float u_a = ((p4.x - p3.x) * (p1.y - p3.y) - (p4.y - p3.y) * (p1.x - p3.x)) / denominator;
float u_b = ((p2.x - p1.x) * (p1.y - p3.y) - (p2.y - p1.y) * (p1.x - p3.x)) / denominator;
float IntersectionX = p1.x + u_a * (p2.x - p1.x);
float IntersectionY = p1.y + u_a * (p2.y - p1.y);
Vector3 Intersection = new Vector2(IntersectionX, IntersectionY);
return Intersection;
}
```

Oh man this is perfect! Thank you so much! Works flawlessly

I'm trying to understand how it works, but I guess it will have to sink in.

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

### Follow this Question

### Related Questions

Move Vectors as curve towards Target 1 Answer

Math/Vector Math finding weighted coordinates 2 Answers

How to get a vector3 (postion) 1 unit away from another in the direction of a 3rd vector3? 2 Answers

Given a point, a "radius" and an arc, how do I find the resulting point? 1 Answer

How can I calculate the Vector3 b using Vector 3 a pos with an angle? 1 Answer