Suppose we have 3 points which are making a triangle and we need to find whether a given point P is in the triangle or not .
There are many ways to do this problem but a very simple method is -
Lets say the triangle is made by three vertices A,B,C and the coordinates of the points are (x1,y1) , (x2,y2) , (x3,y3) and lets say point P is (a,b) so we just need to check whether the sum of the area of the triangle formed by the points A,B,C taken 2 at a time and P is equal to the area of the triangle ABC or not . Not getting it right ? No need to worry at all :)
Let ar(ABC) denotes the area of the triangle ABC. So, we just need to check whether
ar(ABC) = ar(ABP) + ar(BCP) + ar(CAP)
we can calculate the area of the triangle by the formula -
area =
To understand it better lets look at the figures below -
In this figure P is inside the triangle ABC and this can be easily seen that ar(ABP) + ar(BCP) + ar(CAP) = ar(ABC)
so we conclude that P lies inside ABC .
In this figure P is outside the triangle ABC so the ar(ABP) + ar(BCP) + ar(CAP) is not equal to ar(ABC) as they include additional area of triangles BDP and DCP .
There are many ways to do this problem but a very simple method is -
Lets say the triangle is made by three vertices A,B,C and the coordinates of the points are (x1,y1) , (x2,y2) , (x3,y3) and lets say point P is (a,b) so we just need to check whether the sum of the area of the triangle formed by the points A,B,C taken 2 at a time and P is equal to the area of the triangle ABC or not . Not getting it right ? No need to worry at all :)
Let ar(ABC) denotes the area of the triangle ABC. So, we just need to check whether
ar(ABC) = ar(ABP) + ar(BCP) + ar(CAP)
we can calculate the area of the triangle by the formula -
area =
abs
((x1*(y2-y3) + x2*(y3-y1)+ x3*(y1-y2))/2.0)
If it is equal then the given point P is in the triangle ABC .To understand it better lets look at the figures below -
When P lies inside the triangle ABC |
In this figure P is inside the triangle ABC and this can be easily seen that ar(ABP) + ar(BCP) + ar(CAP) = ar(ABC)
so we conclude that P lies inside ABC .
When P lies outside the triangle ABC |
TIP : This observation can be applied to find whether a given point lies inside a given n-polygon or not by taking the area of triangles and equating it to the total area of the polygon .
I hope you would've found this post informative and useful . For any suggestions just post a comment below.
Have a good day .
No comments:
Post a Comment