Check if a point is inside, outside, or on an edge of a polygon Parameters: checkv - the point to be checked v1,v0 - the edge to check against. Two sequential verts in a clockwise polygon. normal - the surface normal of the polygon Returns: 1 if the point in inside the edge 0 if the point is on the edge -1 if the point is outside the edge
| 1462 | // 0 if the point is on the edge |
| 1463 | // -1 if the point is outside the edge |
| 1464 | int CheckPointAgainstEdge(vector *checkv, vector *v0, vector *v1, vector *normal) { |
| 1465 | int ii, jj; |
| 1466 | float edge_i, edge_j, check_i, check_j; |
| 1467 | float *vv0, *vv1, *checkvv; |
| 1468 | float edge_mag, dot; |
| 1469 | |
| 1470 | // Get the vertices for projection |
| 1471 | GetIJ(normal, &ii, &jj); |
| 1472 | |
| 1473 | // Get pointers to elements of our vectors |
| 1474 | vv0 = (float *)v0; |
| 1475 | vv1 = (float *)v1; |
| 1476 | checkvv = (float *)checkv; |
| 1477 | |
| 1478 | // Get 2d vector for edge |
| 1479 | edge_i = vv1[ii] - vv0[ii]; |
| 1480 | edge_j = vv1[jj] - vv0[jj]; |
| 1481 | edge_mag = sqrt(edge_i * edge_i + edge_j * edge_j); |
| 1482 | |
| 1483 | // Get 2d vector for check point |
| 1484 | check_i = checkvv[ii] - vv0[ii]; |
| 1485 | check_j = checkvv[jj] - vv0[jj]; |
| 1486 | |
| 1487 | // Now do the dot product to see if the check point is on the front |
| 1488 | dot = ((-edge_j * check_i) + (edge_i * check_j)) / edge_mag; |
| 1489 | |
| 1490 | // Check dot value and return appropriate code |
| 1491 | if (dot > POINT_TO_EDGE_EPSILON) |
| 1492 | return -1; |
| 1493 | else if (dot < -POINT_TO_EDGE_EPSILON) |
| 1494 | return 1; |
| 1495 | else |
| 1496 | return 0; |
| 1497 | } |
| 1498 | |
| 1499 | // Clips on edge of a polygon against another edge |
| 1500 | // Parameters: normal - defines the plane in which these edgs lie |
no test coverage detected