Point_in_triangle - hpgDesigns/hpgdesigns-dev.io GitHub Wiki

Description

Checks if the given point is inside the given triangle and returns the result.

Parameters

Parameter Data Type Description
px double x coordinate of the point
py double y coordinate of the point
x1 double x coordinate of the first side of the triangle
y1 double y coordinate of the first side of the triangle
x2 double x coordinate of the second side of the triangle
y2 double y coordinate of the second side of the triangle
x3 double x coordinate of the third side of the triangle
y3 double y coordinate of the third side of the triangle

Return Values

boolean: Returns whether the point lies inside the triangle.

Example Call

// demonstrates checking if an instance of the enemy object is in the calling instances field of view
var inst = instance_nearest(x, y, obj_enemy);
if (instance_exists(inst)) {
  var x1 = x + lengthdir_x(100, image_angle - 45),
      y1 = y + lengthdir_y(100, image_angle - 45),
      x2 = x + lengthdir_x(100, image_angle + 45),
      y2 = y + lengthdir_y(100, image_angle + 45);
  if (point_in_triangle(inst.x, inst.y, x, y, x1, y1, x2, y2)) {
      // enemy is in field of view
  }
}

NOTOC

Category:Function:Real