pointInsideTriangle.js 1.0 KB

1234567891011121314151617181920212223242526272829
  1. import barycentricCoordinates from "./barycentricCoordinates.js";
  2. import Cartesian3 from "./Cartesian3.js";
  3. var coords = new Cartesian3();
  4. /**
  5. * Determines if a point is inside a triangle.
  6. *
  7. * @function pointInsideTriangle
  8. *
  9. * @param {Cartesian2|Cartesian3} point The point to test.
  10. * @param {Cartesian2|Cartesian3} p0 The first point of the triangle.
  11. * @param {Cartesian2|Cartesian3} p1 The second point of the triangle.
  12. * @param {Cartesian2|Cartesian3} p2 The third point of the triangle.
  13. * @returns {Boolean} <code>true</code> if the point is inside the triangle; otherwise, <code>false</code>.
  14. *
  15. * @example
  16. * // Returns true
  17. * var p = new Cesium.Cartesian2(0.25, 0.25);
  18. * var b = Cesium.pointInsideTriangle(p,
  19. * new Cesium.Cartesian2(0.0, 0.0),
  20. * new Cesium.Cartesian2(1.0, 0.0),
  21. * new Cesium.Cartesian2(0.0, 1.0));
  22. */
  23. function pointInsideTriangle(point, p0, p1, p2) {
  24. barycentricCoordinates(point, p0, p1, p2, coords);
  25. return coords.x > 0.0 && coords.y > 0.0 && coords.z > 0;
  26. }
  27. export default pointInsideTriangle;