コード例 #1
0
ファイル: GeometryUtil.cs プロジェクト: AMEE/revit
        /// <summary>
        /// Check if the given bottom edge was shared by a trapezoid face with left edge vertical.
        /// </summary>
        /// <param name="hostNormal">Corbel Host face Normal</param>
        /// <param name="corbelBottomFace">Bottom Face of Corbel</param>
        /// <param name="bottomEdge">Given bottom edge to test</param>
        /// <param name="trapezoidFace">Output the trapezoid Face</param>
        /// <param name="topEdge">Output trapezoid top edge</param>
        /// <param name="leftEdge">Output trapezoid left edge</param>
        /// <param name="rightEdge">Output trapezoid right edge</param>
        /// <returns>True if there is a trapezoid face share the given bottom edge, otherwise false.</returns>
        private static bool IsTrapezoid(
            XYZ hostNormal, PlanarFace corbelBottomFace, Edge bottomEdge, 
            out PlanarFace trapezoidFace, out Edge topEdge, 
            out Edge leftEdge, out Edge rightEdge)
        {
            PlanarFace face1 = bottomEdge.get_Face(0) as PlanarFace;
            PlanarFace face2 = bottomEdge.get_Face(1) as PlanarFace;

            trapezoidFace = face1 == corbelBottomFace ? face2 : face1;

            EdgeArray trapezoidFaceEdges = trapezoidFace.EdgeLoops.get_Item(0);
            XYZ bottomEdgeDir = (bottomEdge.Evaluate(1.0) - bottomEdge.Evaluate(0.0)).Normalize();
            int bottomEdgeIndex = -1;
            topEdge = null;
            for (int i = 0; i < trapezoidFaceEdges.Size; i++)
            {
                Edge edge = trapezoidFaceEdges.get_Item(i);
                XYZ edgeDir = (edge.Evaluate(1.0) - edge.Evaluate(0.0)).Normalize();
                if (edgeDir.IsAlmostEqualTo(bottomEdgeDir) ||
                    edgeDir.IsAlmostEqualTo(-bottomEdgeDir))
                {
                    if (edge.Evaluate(0.0).IsAlmostEqualTo(bottomEdge.Evaluate(0.0)))
                    {
                        bottomEdge = edge;
                        bottomEdgeIndex = i;
                    }
                    else
                    {
                        topEdge = edge;
                    }
                }
            }

            leftEdge = trapezoidFaceEdges.get_Item((trapezoidFaceEdges.Size + bottomEdgeIndex - 1) % trapezoidFaceEdges.Size);
            rightEdge = trapezoidFaceEdges.get_Item((bottomEdgeIndex + 1) % trapezoidFaceEdges.Size);

            XYZ leftEdgeDir = (leftEdge.Evaluate(1.0) - leftEdge.Evaluate(0.0)).Normalize();
            bool isLeftEdgeVertical = false;
            if (leftEdgeDir.IsAlmostEqualTo(hostNormal) ||
                leftEdgeDir.IsAlmostEqualTo(-hostNormal))
            {
                isLeftEdgeVertical = true;
            }

            XYZ rightEdgeDir = (rightEdge.Evaluate(1.0) - rightEdge.Evaluate(0.0)).Normalize();
            bool rightEdgeIsVertical = false;
            if (rightEdgeDir.IsAlmostEqualTo(hostNormal) ||
                rightEdgeDir.IsAlmostEqualTo(-hostNormal))
            {
                rightEdgeIsVertical = true;
            }

            return isLeftEdgeVertical && !rightEdgeIsVertical;
        }