Exemple #1
0
        public static XYZ ToUnitVector(XYZ vector, XYZAxle defaultAxle = XYZAxle.X)
        {
            if (vector.IsUnitLength())
            {
                return(vector);
            }
            else if (vector.GetLength() == 0)
            {
                switch (defaultAxle)
                {
                case XYZAxle.X:
                    return(new XYZ(1, 0, 0));

                case XYZAxle.Y:
                    return(new XYZ(0, 1, 0));

                case XYZAxle.Z:
                    return(new XYZ(0, 0, 1));

                default:
                    throw new NotImplementedException("未实现07130319");
                }
            }
            else
            {
                return(vector * (1 / vector.GetLength()));
            }
        }
Exemple #2
0
        /// <summary>
        /// 平面XYZ 求垂直向量
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static XYZ GetVerticalVectorForPlaneXYZ(XYZ vector, XYZAxle axle)
        {
            switch (axle)
            {
            case XYZAxle.X:
                return(new XYZ(0, vector.Z, -vector.Y));

            case XYZAxle.Y:
                return(new XYZ(vector.Z, 0, -vector.X));

            case XYZAxle.Z:
                return(new XYZ(vector.Y, -vector.X, 0));

            default:
                throw new NotImplementedException("该XYZ非平面向量");
            }
        }
Exemple #3
0
        /// <summary>
        /// 将方向调整到指定象限
        /// </summary>
        /// <param name="vector"></param>
        /// <param name="quadrantType"></param>
        /// <returns></returns>
        public static XYZ GetVectorByQuadrantForPlaneXYZ(XYZ vector, QuadrantType quadrantType, XYZAxle axle)
        {
            double axle1, axle2;

            axle1 = axle2 = 0;
            switch (axle)
            {
            case XYZAxle.X:
                GetVectorByQuadrant(quadrantType, vector.Y, vector.Z, ref axle1, ref axle2);
                return(new XYZ(0, axle1, axle2));

            case XYZAxle.Y:
                GetVectorByQuadrant(quadrantType, vector.X, vector.Z, ref axle1, ref axle2);
                return(new XYZ(axle1, 0, axle2));

            case XYZAxle.Z:
                GetVectorByQuadrant(quadrantType, vector.X, vector.Y, ref axle1, ref axle2);
                return(new XYZ(axle1, axle2, 0));

            default:
                throw new NotImplementedException("该XYZ非平面向量");
            }
        }