Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 1x 10x 6x 6x | import barycentricCoordinates from "./barycentricCoordinates.js";
import Cartesian3 from "./Cartesian3.js";
import defined from "./defined.js";
const scratchBarycentricCoords = new Cartesian3();
/**
* Determines if a point is inside a triangle.
*
* @function pointInsideTriangle
*
* @param {Cartesian2|Cartesian3} point The point to test.
* @param {Cartesian2|Cartesian3} p0 The first point of the triangle.
* @param {Cartesian2|Cartesian3} p1 The second point of the triangle.
* @param {Cartesian2|Cartesian3} p2 The third point of the triangle.
* @returns {boolean} <code>true</code> if the point is inside the triangle; otherwise, <code>false</code>.
*
* @example
* // Returns true
* const p = new Cesium.Cartesian2(0.25, 0.25);
* const b = Cesium.pointInsideTriangle(p,
* new Cesium.Cartesian2(0.0, 0.0),
* new Cesium.Cartesian2(1.0, 0.0),
* new Cesium.Cartesian2(0.0, 1.0));
*/
function pointInsideTriangle(point, p0, p1, p2) {
const coords = barycentricCoordinates(
point,
p0,
p1,
p2,
scratchBarycentricCoords,
);
Iif (!defined(coords)) {
return false;
}
return coords.x > 0.0 && coords.y > 0.0 && coords.z > 0;
}
export default pointInsideTriangle;
|