Ejemplo n.º 1
0
        public bool IntersectionWith(Line line2, out Vector Intersection)
        {
            Intersection = new Vector(Dimensions);

            // Lösen der Gleichung n*Direction + P1 = m*Direction2 + P2
            // => P2 - P1 = n*Direction - m*Direction2
            // => P2 - P1 = [Direction | Direction2] * (n, m)t
            // => (n,m)t =  [Direction | Direction2]^-1 * P2 - P1

            Vector Pdiff = line2.P1 - P1;

            Transformations.Matrix M = new Transformations.Matrix(Dimensions, 2);
            M.SetColumn(0, Direction);
            M.SetColumn(1, line2.Direction);

            Transformations.Matrix Minv;
            if (!M.Invert(out Minv))
            {
                return(false);
            }

            Vector nm = Minv.RightMul(Pdiff);

            Intersection.Set((nm[0] * Direction + P1).coordinates);
            return(true);
        }