parameters: (tri, trg)
docstring: Finds where an origin-centered ray going in direction trg intersects a triangle.
      Args:
          tri: 3 X 3 vertex locations. tri[0, :] is 0th vertex.
      Returns:
          alpha, beta, gamma
docstring_summary: Finds where an origin-centered ray going in direction trg intersects a triangle.
      Args:
          tri: 3 X 3 vertex locations. tri[0, :] is 0th vertex.
      Returns:
          alpha, beta, gamma
docstring_tokens: Finds where an origin - centered ray going in direction trg intersects a triangle . Args : tri : 3 X 3 vertex locations . tri [ 0 : ] is 0th vertex . Returns : alpha beta gamma
function: def triangle_direction_intersection(tri, trg):
      '''
      Finds where an origin-centered ray going in direction trg intersects a triangle.
      Args:
          tri: 3 X 3 vertex locations. tri[0, :] is 0th vertex.
      Returns:
          alpha, beta, gamma
      '''
      p0 = np.copy(tri[0, :])
      # Don't normalize
      d1 = np.copy(tri[1, :]) - p0;
      d2 = np.copy(tri[2, :]) - p0;
      d = trg / np.linalg.norm(trg)
  
      mat = np.stack([d1, d2, d], axis=1)
  
      try:
        inv_mat = np.linalg.inv(mat)
      except np.linalg.LinAlgError:
        return False, 0
  
      # inv_mat = np.linalg.inv(mat)
      
      a_b_mg = -1*np.matmul(inv_mat, p0)
      is_valid = (a_b_mg[0] >= 0) and (a_b_mg[1] >= 0) and ((a_b_mg[0] + a_b_mg[1]) <= 1) and (a_b_mg[2] < 0)
      if is_valid:
          return True, -a_b_mg[2]*d
      else:
          return False, 0
function_tokens: def triangle_direction_intersection ( tri , trg ) : p0 = np . copy ( tri [ 0 , : ] ) # Don't normalize d1 = np . copy ( tri [ 1 , : ] ) - p0 d2 = np . copy ( tri [ 2 , : ] ) - p0 d = trg / np . linalg . norm ( trg ) mat = np . stack ( [ d1 , d2 , d ] , axis = 1 ) try : inv_mat = np . linalg . inv ( mat ) except np . linalg . LinAlgError : return False , 0 # inv_mat = np.linalg.inv(mat) a_b_mg = - 1 * np . matmul ( inv_mat , p0 ) is_valid = ( a_b_mg [ 0 ] >= 0 ) and ( a_b_mg [ 1 ] >= 0 ) and ( ( a_b_mg [ 0 ] + a_b_mg [ 1 ] ) <= 1 ) and ( a_b_mg [ 2 ] < 0 ) if is_valid : return True , - a_b_mg [ 2 ] * d else : return False , 0