OpenRA.Graphics.RgbaColorRenderer.IntersectionOf C# (CSharp) Method

IntersectionOf() private method

Calculate the 2D intersection of two lines. Will behave badly if the lines are parallel. Z position is the average of a and b (ignores actual intersection point if it exists)
private IntersectionOf ( float3 a, float3 da, float3 b, float3 db ) : float3
a float3
da float3
b float3
db float3
return float3
        float3 IntersectionOf(float3 a, float3 da, float3 b, float3 db)
        {
            var crossA = a.X * (a.Y + da.Y) - a.Y * (a.X + da.X);
            var crossB = b.X * (b.Y + db.Y) - b.Y * (b.X + db.X);
            var x = da.X * crossB - db.X * crossA;
            var y = da.Y * crossB - db.Y * crossA;
            var d = da.X * db.Y - da.Y * db.X;
            return new float3(x / d, y / d, 0.5f * (a.Z + b.Z));
        }