/// <summary>
        /// 投影
        /// </summary>
        /// <param name="m"></param>
        /// <param name="h"></param>
        /// <param name="p"></param>
        /// <param name="cameraVector"></param>
        /// <param name="mathP"></param>
        /// <returns></returns>
        public static MathVector Project(this ITriadManipulator m, swTriadManipulatorControlPoints_e h, IMathPoint p, IMathVector cameraVector, IMathUtility mathP)
        {
            IMathUtility math = mathP;

            //var zero = (IMathPoint)math.CreatePoint(new[] { 0, 0, 0 });
            //double pT, qT;
            switch (h)
            {
            case swTriadManipulatorControlPoints_e.swTriadManipulatorOrigin:
                return((MathVector)p.Subtract(m.Origin));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorXAxis:

                return(ClosestPointOnAxis(m, p, cameraVector, m.XAxis));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorYAxis:
                return(ClosestPointOnAxis(m, p, cameraVector, m.YAxis));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorZAxis:
                return(ClosestPointOnAxis(m, p, cameraVector, m.ZAxis));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorXYPlane:
                return((MathVector)p.Subtract(m.Origin));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorYZPlane:
                return((MathVector)p.Subtract(m.Origin));

            case swTriadManipulatorControlPoints_e.swTriadManipulatorZXPlane:
                return((MathVector)p.Subtract(m.Origin));

            default:
                throw new ArgumentOutOfRangeException(nameof(h), h, null);
            }
        }
        public static MathVector Project(this ITriadManipulator m, swTriadManipulatorControlPoints_e h, IMathPoint p, IMathVector cameraVector, IMathUtility mathP)
        {
            IMathUtility math = mathP;
            var zero = (IMathPoint) math.CreatePoint(new[] {0, 0, 0});
            double pT, qT;
            switch (h)
            {
                case swTriadManipulatorControlPoints_e.swTriadManipulatorOrigin:
                    return (MathVector) p.Subtract(m.Origin);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorXAxis:

                    return ClosestPointOnAxis(m, p, cameraVector, m.XAxis);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorYAxis:
                    return ClosestPointOnAxis(m, p, cameraVector, m.YAxis);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorZAxis:
                    return ClosestPointOnAxis(m, p, cameraVector, m.ZAxis);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorXYPlane:
                    return (MathVector) p.Subtract(m.Origin);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorYZPlane:
                    return (MathVector) p.Subtract(m.Origin);
                case swTriadManipulatorControlPoints_e.swTriadManipulatorZXPlane:
                    return (MathVector) p.Subtract(m.Origin);
                default:
                    throw new ArgumentOutOfRangeException(nameof(h), h, null);
            }
        }
        /// <summary>
        /// 计算在某轴上的投影
        /// </summary>
        /// <param name="point"></param>
        /// <param name="origin"></param>
        /// <param name="axis"></param>
        /// <returns></returns>
        public static MathPoint Project(this IMathPoint point, IMathPoint origin, IMathVector axis)
        {
            var a = (IMathVector)point.Subtract(origin);
            var t = a.Project(axis);
            var v = (MathVector)axis.Scale(t);

            return((MathPoint)origin.AddVector(v));
        }
 /// <summary>
 /// Find the vector in model space from the point to the viewers eye.
 /// </summary>
 /// <param name="modelView"></param>
 /// <param name="mathUtility"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 private static MathVector ViewVector(IModelView modelView, IMathUtility mathUtility, IMathPoint p)
 {
     var world2screen = modelView.Transform;
     var pScreen = (MathPoint) p.MultiplyTransform(world2screen);
     var vv = (IMathVector) mathUtility.CreateVector(new[] {0.0, 0, 1});
     var pScreenUp = (MathPoint) pScreen.AddVector(vv);
     var pWorldDelta = (MathPoint) pScreenUp.MultiplyTransform((MathTransform) world2screen.Inverse());
     var viewVector = (MathVector) p.Subtract(pWorldDelta);
     return viewVector;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Find the vector in model space from the point to the viewers eye.
        /// </summary>
        /// <param name="modelView"></param>
        /// <param name="mathUtility"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        private static MathVector ViewVector(IModelView modelView, IMathUtility mathUtility, IMathPoint p)
        {
            var world2screen = modelView.Transform;
            var pScreen      = (MathPoint)p.MultiplyTransform(world2screen);
            var vv           = (IMathVector)mathUtility.CreateVector(new[] { 0.0, 0, 1 });
            var pScreenUp    = (MathPoint)pScreen.AddVector(vv);
            var pWorldDelta  = (MathPoint)pScreenUp.MultiplyTransform((MathTransform)world2screen.Inverse());
            var viewVector   = (MathVector)p.Subtract(pWorldDelta);

            return(viewVector);
        }
        /// <summary>
        /// http://geomalgorithms.com/a07-_distance.html
        /// </summary>
        /// <param name="pa"></param>
        /// <param name="va"></param>
        /// <param name="pb"></param>
        /// <param name="vb"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        private static bool ClosestPointBetweenLines(IMathPoint pOrigin, IMathVector pVector, IMathPoint qOrigin, IMathVector qVector, out double pT, out double qT)
        {
            var w0 = (IMathVector)(pOrigin.Subtract(qOrigin));
            var u  = pVector.Normalise();
            var v  = qVector.Normalise();
            var a  = u.Dot(u);
            var b  = u.Dot(v);
            var c  = v.Dot(v);
            var d  = u.Dot(w0);
            var e  = v.Dot(w0);

            var den = (a * c - b * b);

            if (System.Math.Abs(den) < 1e-12)
            {
                pT = 0;
                qT = 0;
                return(false);
            }
            pT = (b * e - c * d) / den;
            qT = (a * a - b * d) / den;
            return(true);
        }
 public static MathVector SubtractTs(this IMathPoint a, IMathPoint b)
 {
     return((MathVector)a.Subtract(b));
 }
        /// <summary>
        /// http://geomalgorithms.com/a07-_distance.html
        /// </summary>
        /// <param name="pa"></param>
        /// <param name="va"></param>
        /// <param name="pb"></param>
        /// <param name="vb"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        private static bool ClosestPointBetweenLines(IMathPoint pOrigin, IMathVector pVector, IMathPoint qOrigin, IMathVector qVector, out double pT, out double qT)
        {
            var w0 = (IMathVector) (pOrigin.Subtract(qOrigin));
            var u = pVector.Normalise();
            var v = qVector.Normalise();
            var a = u.Dot(u);
            var b = u.Dot(v);
            var c = v.Dot(v);
            var d = u.Dot(w0);
            var e = v.Dot(w0);

            var den = (a*c - b*b);
            if (Math.Abs(den) < 1e-12)
            {
                pT = 0;
                qT = 0;
                return false;
            }
            pT = (b*e - c*d)/den;
            qT = (a*a - b*d)/den;
            return true;
        }