pointInsideTriangle

pointInsideTriangle

Computes the barycentric coordinates for a point with respect to a triangle.

Parameters:
Name Type Argument Description
point Cartesian2 | Cartesian3 The point to test.
p0 Cartesian2 | Cartesian3 The first point of the triangle, corresponding to the barycentric x-axis.
p1 Cartesian2 | Cartesian3 The second point of the triangle, corresponding to the barycentric y-axis.
p2 Cartesian2 | Cartesian3 The third point of the triangle, corresponding to the barycentric z-axis.
result Cartesian3 <optional>
The object onto which to store the result.
Throws:
DeveloperError : point, p0, p1, and p2 are required.
Returns:
Cartesian3 The modified result parameter or a new Cartesian3 instance if one was not provided.
Example
// Returns Cartesian3.UNIT_X
var p = new Cartesian3(-1.0, 0.0, 0.0);
var b = barycentricCoordinates(p,
  new Cartesian3(-1.0, 0.0, 0.0),
  new Cartesian3( 1.0, 0.0, 0.0),
  new Cartesian3( 0.0, 1.0, 1.0));
Source:

pointInsideTriangle

Determines if a point is inside a triangle.

Parameters:
Name Type Description
point Cartesian2 | Cartesian3 The point to test.
p0 Cartesian2 | Cartesian3 The first point of the triangle.
p1 Cartesian2 | Cartesian3 The second point of the triangle.
p2 Cartesian2 | Cartesian3 The third point of the triangle.
Throws:
DeveloperError : point, p0, p1, and p2 are required.
Returns:
Boolean true if the point is inside the triangle; otherwise, false.
Example
// Returns true
var p = new Cartesian2(0.25, 0.25);
var b = pointInsideTriangle(p,
  new Cartesian2(0.0, 0.0),
  new Cartesian2(1.0, 0.0),
  new Cartesian2(0.0, 1.0));
Source: