示例#1
0
        /// <summary>
        /// Compute the angle between two edges
        /// </summary>
        /// <param name="edgeA">The 1st edge</param>
        /// <param name="edgeB">The 2nd edge</param>
        /// <returns>The angle of the 2 edges</returns>
        private double AngleBetweenEdges(Edge edgeA, Edge edgeB)
        {
            Autodesk.Revit.DB.XYZ vectorA = null;
            Autodesk.Revit.DB.XYZ vectorB = null;

            // find coincident vertices
            Autodesk.Revit.DB.XYZ A_0 = edgeA.Evaluate(0);
            Autodesk.Revit.DB.XYZ A_1 = edgeA.Evaluate(1);
            Autodesk.Revit.DB.XYZ B_0 = edgeB.Evaluate(0);
            Autodesk.Revit.DB.XYZ B_1 = edgeB.Evaluate(1);
            if (A_0.IsAlmostEqualTo(B_0))
            {
                vectorA = edgeA.ComputeDerivatives(0).BasisX.Normalize();
                vectorB = edgeA.ComputeDerivatives(0).BasisX.Normalize();
            }
            else if (A_0.IsAlmostEqualTo(B_1))
            {
                vectorA = edgeA.ComputeDerivatives(0).BasisX.Normalize();
                vectorB = edgeB.ComputeDerivatives(1).BasisX.Normalize();
            }
            else if (A_1.IsAlmostEqualTo(B_0))
            {
                vectorA = edgeA.ComputeDerivatives(1).BasisX.Normalize();
                vectorB = edgeB.ComputeDerivatives(0).BasisX.Normalize();
            }
            else if (A_1.IsAlmostEqualTo(B_1))
            {
                vectorA = edgeA.ComputeDerivatives(1).BasisX.Normalize();
                vectorB = edgeB.ComputeDerivatives(1).BasisX.Normalize();
            }

            if (A_1.IsAlmostEqualTo(B_0) || A_0.IsAlmostEqualTo(B_1))
            {
                vectorA = vectorA.Negate();
            }

            if (null == vectorA || null == vectorB)
            {
                return(0d);
            }
            double angle = Math.Acos(vectorA.DotProduct(vectorB));

            return(angle);
        }