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?

!(https://answers.unity.com/storage/attachments/122567-paper.png image)

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!

Hi, this is a function that get the intersection point of two lines. Thanks the help of this sites:


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;
    }