Пример #1
0
        public static XMVector IntersectLine(XMVector p, XMVector linePoint1, XMVector linePoint2)
        {
            XMVector v1 = XMVector3.Dot(p, linePoint1);
            XMVector v2 = XMVector3.Dot(p, linePoint2);
            XMVector d  = XMVector.Subtract(v1, v2);

            XMVector vt = XMPlane.DotCoord(p, linePoint1);

            vt = XMVector.Divide(vt, d);

            XMVector point = XMVector.Subtract(linePoint2, linePoint1);

            point = XMVector.MultiplyAdd(point, vt, linePoint1);

            XMVector control = XMVector.NearEqual(d, XMGlobalConstants.Zero, XMGlobalConstants.Epsilon);

            return(XMVector.Select(point, XMGlobalConstants.QNaN, control));
        }
Пример #2
0
        public static XMVector LinePointDistance(XMVector linePoint1, XMVector linePoint2, XMVector point)
        {
            //// Given a vector PointVector from LinePoint1 to Point and a vector
            //// LineVector from LinePoint1 to LinePoint2, the scaled distance
            //// PointProjectionScale from LinePoint1 to the perpendicular projection
            //// of PointVector onto the line is defined as:
            ////
            ////     PointProjectionScale = dot(PointVector, LineVector) / LengthSq(LineVector)

            XMVector pointVector = XMVector.Subtract(point, linePoint1);
            XMVector lineVector  = XMVector.Subtract(linePoint2, linePoint1);

            XMVector lengthSq = XMVector3.LengthSquare(lineVector);

            XMVector pointProjectionScale = XMVector3.Dot(pointVector, lineVector);

            pointProjectionScale = XMVector.Divide(pointProjectionScale, lengthSq);

            XMVector distanceVector = XMVector.Multiply(lineVector, pointProjectionScale);

            distanceVector = XMVector.Subtract(pointVector, distanceVector);

            return(XMVector3.Length(distanceVector));
        }
Пример #3
0
 public static XMVector DotNormal(XMVector p, XMVector v)
 {
     return(XMVector3.Dot(p, v));
 }
Пример #4
0
 public static XMVector LengthSquare(XMVector v)
 {
     return(XMVector3.Dot(v, v));
 }