Determine whether the vertex is on the online segment:
If the vertex is set to Q and the line segment is P1P2, the basis for determining the vertex Q on this line segment is: (q-P1) × (P2-P1) = 0 and Q is in P1, p2 is inside the rectangle of the diagonal vertex. The former ensures that the qpoint is on the P1P2 line, and the latter ensures that the qpoint is not on the extended or reverse extended line of the P1P2 line. The following process can be used to determine this step:
On-segment (PI, PJ, PK)
If min (XI, XJ) <= XK <= max (XI, XJ) and min (Yi, YJ) <= yk <= max (Yi, YJ)
Then return true;
Else return false;
Note that, due to the special situations of horizontal and vertical line segments, min (XI, XJ) <= XK <= max (XI, XJ) and min (Yi, YJ) <= yk <= max (Yi, YJ) conditions must be met at the same time to return the true value.
BOOL CGe: PtInLine (double x, double y, double z,
Double x1, double y1, double z1,
Double x2, double y2, double z2)
{// From http://blog.csdn.net/hoya5121
// Determine whether the target point is an endpoint
If (DoubleComp (x, x1) = 0 & DoubleComp (y, y1) = 0 & DoubleComp (z, z1) = 0)
{
Return TRUE;
}
If (DoubleComp (x, x2) = 0 & DoubleComp (y, y2) = 0 & DoubleComp (z, z2) = 0)
{
Return TRUE;
}
//
Double D = distpt2line (X, Y, Z, X1, Y1, Z1, X2, Y2, Z2 );
If (doublecomp (D, 1e-6)> 0) // (D> 1e-6)
{
Return false;
}
If (DoubleComp (x1, x2 )! = 0) // (x1! = X2)
{
If (DoubleComp (x-x1), 0) <0) & (DoubleComp (x-x2), 0)> 0) |
(DoubleComp (x-x1), 0)> 0) & (DoubleComp (x-x2), 0) <0 )))
{
Return TRUE;
}
}
If (DoubleComp (y1, y2 )! = 0) // (y1! = Y2)
{
If (DoubleComp (y-y1), 0) <0) & (DoubleComp (y-y2), 0)> 0) |
(DoubleComp (y-y1), 0)> 0) & (DoubleComp (y-y2), 0) <0 )))
{
Return TRUE;
}
}
If (DoubleComp (z1, z2 )! = 0)
{
If (DoubleComp (z-z1), 0) <0) & (DoubleComp (z-z2), 0)> 0) |
(Doublecomp (z-z1), 0)> 0) & (doublecomp (z-z2), 0) <0 )))
{
Return true;
}
}
Return false;
}