示例#1
0
        // vec2_LineStart = cVector_2d.MakeVector(aptDefinitionPoints[iLast].x,aptDefinitionPoints[iLast].y);
        // vec2_LineEnd = cVector_2d.MakeVector(aptDefinitionPoints[i].x,aptDefinitionPoints[i].y);
        // vec2_Point = cVector_2d.MakeVector(cptPointToAdd.x,cptPointToAdd.y);
        // nDistance = cVector_2d.DistanceOfPointToLine(vec2_Point, vec2_LineStart, vec2_LineEnd);
        // vec2_VecLine = cVector_2d.VectorSubtract(vec2_LineStart, vec2_LineEnd);
        // cptIntersectionPoint = cVector_2d.GetPointVerticalIntersection(aptDefinitionPoints[i], vec2_VecLine, cptPointToAdd);

        // cVector_2d.GetPointVerticalIntersection(aptDefinitionPoints[i], vec2_VecLine, cptPointToAdd);

        // vecInputLine: vector/line between two polygon points
        // cptPointQ: Origin of vector vecInputLine, one of the two polygon points
        // cpPointP: Click point
        // Schnittpunkt zwischen Normale zu vecInputLine und cpPointP auf vecInputLine
        public static cPoint GetPointVerticalIntersection(cPoint cptPointQ, cVector_2d vecInputLine, cPoint cpPointP)
        {
            // Q: Line start/endpoint
            // P + a * vecNormalVector = Intersection = Q + b * vecInputLine
            // a = (-(Px*vy-Py*vx-Qx*vy+Qy*vx))/(nx*vy-ny*vx)
            // b = (-(Px*ny-Py*nx-Qx*ny+Qy*nx))/(nx*vy-ny*vx)

            cVector_2d vecNormalVector = GetNormalVector(vecInputLine);
            double     nDenominator    = vecNormalVector.x * vecInputLine.y - vecNormalVector.y * vecInputLine.x;


            cPoint cptIntersectionPoint = new cPoint();

            if (nDenominator == 0)
            {
                // no intersection
                cptIntersectionPoint.bHasInterSection = false;
                return(cptIntersectionPoint);
            }

            double a = (-(cpPointP.x * vecInputLine.y - cpPointP.y * vecInputLine.x - cptPointQ.x * vecInputLine.y + cptPointQ.y * vecInputLine.x)) / nDenominator;
            double b = (-(cpPointP.x * vecNormalVector.y - cpPointP.y * vecNormalVector.x - cptPointQ.x * vecNormalVector.y + cptPointQ.y * vecNormalVector.x)) / nDenominator;

            cptIntersectionPoint.bHasInterSection = true;
            cptIntersectionPoint.x = cpPointP.x + a * vecNormalVector.x;
            cptIntersectionPoint.y = cpPointP.y + a * vecNormalVector.y;

            return(cptIntersectionPoint);
        }
示例#2
0
        }  // End Constructor

        public static cVector_2d GetNormalVector(cVector_2d vec)
        {
            return(null);
        }