1

Check whether a given point lies inside a triangle or not

 1 year ago
source link: https://www.geeksforgeeks.org/videos/check-whether-a-given-point-lies-inside-a-triangle-or-not/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Check whether a given point lies inside a triangle or not

Check whether a given point lies inside a triangle or not
  • 28/06/2022

Let the coordinates of three corners be (x1, y1), (x2, y2) and (x3, y3). And coordinates of the given point P be (x, y)

Calculate area of the given triangle, i.e., area of the triangle ABC in the above diagram. Area A = [ x1(y2 – y3) + x2(y3 – y1) + x3(y1-y2)]/2 Calculate area of the triangle PAB. We can use the same formula for this. Let this area be A1. Calculate area of the triangle PBC. Let this area be A2. Calculate area of the triangle PAC. Let this area be A3. If P lies inside the triangle, then A1 + A2 + A3 must be equal to A. Input: A = (0, 0), B = (10, 30), C = (20, 0), P(10, 15) Output: Inside Explanation: B(10,30) / \ / \ / \ / P \ P' / \ A(0,0) ----------- C(20,0)

Check whether a given point lies inside a triangle or not: https://www.geeksforgeeks.org/check-whether-a-given-point-lies-inside-a-triangle-or-not/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK