コード例 #1
0
        //! BAsically we check the quadrant (0 to 3), then intersect the radius with the face corresponding to that quadrant
        // The cut starts from the clockwise-end vertex of quadrant 0, and rotates anticlockwise; assuming x points right and y points up
        GLVector3d GetCutIntersect( int iCut, double fCubeHalfWidth )
        {
            int iCutQuadrant = GetCutQuadrant( iCut );
            double fCutRatio = (double)iCut / (double)MaxCut;

            GLVector3d lineend = null;
            GLVector3d linestart = ReferenceVertices[ iCutQuadrant] * fCubeHalfWidth / 0.5;
            if( iCutQuadrant < iNumberFaces - 1 )
            {
                lineend = ReferenceVertices[ iCutQuadrant + 1 ]  * fCubeHalfWidth / 0.5;
            }
            else
            {
                lineend = ReferenceVertices[ 0 ]  * fCubeHalfWidth / 0.5;
            }

            double fAngle = GetAngleWithXAxis( fCutRatio );
            // CutVectorPerp is perpendicular to the radius vector, I think
            GLVector3d CutVectorPerp = new GLVector3d( - Math.Sin( fAngle ), Math.Cos( fAngle ), 0 );

            // Grabbed this from http://softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm
            GLVector3d IntersectPoint = linestart - ( lineend - linestart ) * CutVectorPerp.dot( linestart ) / CutVectorPerp.dot( lineend - linestart );
            //Console.WriteLine( "GetCutIntersect iCut " + iCut.ToString() + " cubehalfwidth " + fCubeHalfWidth.ToString() + " linestart " + linestart.ToString() +
            //    lineend.ToString() + " fAngle " + fAngle.ToString() + " CutVectorPerp " + CutVectorPerp.ToString() + " intersectpoint " + IntersectPoint.ToString() );
            return IntersectPoint;
        }
コード例 #2
0
        //! BAsically we check the quadrant, then intersect it, then we just intersect the radius with the appropriate face
        protected virtual GLVector3d GetCutIntersect( int iCut, double fCubeHalfWidth )
        {
            int iCutQuadrant = GetCutQuadrant( iCut );
            double fCutRatio = (double)iCut / (double)MaxCut;

            GLVector3d linestart = ReferenceVertices[ iCutQuadrant] * fCubeHalfWidth / 0.5;
            GLVector3d lineend = null;
            if( iCutQuadrant < iNumberFaces - 1 )
            {
                lineend = ReferenceVertices[ iCutQuadrant + 1 ]  * fCubeHalfWidth / 0.5;
            }
            else
            {
                lineend = ReferenceVertices[ 0 ]  * fCubeHalfWidth / 0.5;
            }

            double fAngle = GetAngleWithXAxis( fCutRatio );

            GLVector3d CutVectorPerp = new GLVector3d( - Math.Sin( fAngle ), Math.Cos( fAngle ), 0 );

            // Grabbed this from http://softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm
            return linestart - ( lineend - linestart ) * CutVectorPerp.dot( linestart ) / CutVectorPerp.dot( lineend - linestart );
        }