- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check whether a given point lies inside a Trianglen
Three points of a triangle are given; another point P is also given to check whether the point P is inside the triangle or not.
To solve the problem, let consider the points of the triangle are A, B, and C. When the area of triangle Δ𝐴𝐵𝐶 = Δ𝐴𝐵𝑃 + Δ𝑃𝐵𝐶 + Δ𝐴𝑃𝐶, then the point P is inside the triangle.
Input and Output
Input: Points of the triangle {(0, 0), (20, 0), (10, 30)} and point p (10, 15) to check. Output: Point is inside the triangle.
Algorithm
isInside(p1, p2, p3, p)
Input: Three points of a triangle, the point p to check.
Output: True, when p is inside the triangle.
Begin area := area of triangle(p1, p2, p3) area1 := area of triangle(p, p2, p3) area2 := area of triangle(p1, p, p3) area3 := area of triangle(p1, p2, p) if area = (area1 + area2 + area3), then return true else return false End
Example
#include <iostream> #include<cmath> using namespace std; struct Point { int x, y; }; float triangleArea(Point p1, Point p2, Point p3) { //find area of triangle formed by p1, p2 and p3 return abs((p1.x*(p2.y-p3.y) + p2.x*(p3.y-p1.y)+ p3.x*(p1.yp2.y))/2.0); } bool isInside(Point p1, Point p2, Point p3, Point p) { //check whether p is inside or outside float area = triangleArea (p1, p2, p3); //area of triangle ABC float area1 = triangleArea (p, p2, p3); //area of PBC float area2 = triangleArea (p1, p, p3); //area of APC float area3 = triangleArea (p1, p2, p); //area of ABP return (area == area1 + area2 + area3); //when three triangles are forming the whole triangle } int main() { Point p1={0, 0}, p2={20, 0}, p3={10, 30}; Point p = {10, 15}; if (isInside(p1, p2, p3, p)) cout << "Point is inside the triangle."; else cout << "Point is not inside the triangle"; }
Output
Point is inside the triangle.
- Related Articles
- Check if a given point lies inside a Polygon
- How To Check if a Given Point Lies Inside a Rectangle in Java?
- Check whether the point (x, y) lies on a given line in Python
- Check if a point lies on or inside a rectangle in Python
- Find if a point lies inside a Circle in C++
- Check if a given circle lies completely inside the ring formed by two concentric circles in C++
- C++ Program to Check if a Point d lies inside or outside a circle defined by Points a, b, c in a Plane
- Check if a circle lies inside another circle or not in C++
- Check whether the given sides of a triangle form a right angled triangle.$a = 9, b = 12$ and $c = 16
- Program to check given point in inside or boundary of given polygon or not in python
- Check whether given floating point number is even or odd in Python
- Check whether triangle is valid or not if sides are given in Python
- Check whether a given number is Polydivisible or Not
- Check if a point is inside, outside or on the ellipse in C++
- Check if a point is inside, outside or on the parabola in C++

Advertisements