Friday, 10 October 2014

Triangle Triangle everywhere not a point to think

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 = 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

 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 . 












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 . 

Sunday, 5 October 2014

Gaining the momentum

This week I was revising my previously learned algorithms/theorems . This includes sieve of Eratosthenes,Game theory,modular exponentiation,etc,.

Its time to increase my knowledge base . These days instead of participating in online contests(other than ACM related) I'll be only learning new things and posting about them in detail in my coming posts . So, stay tuned for some amazing stuff coming shortly ;)

I was also trying my hands on application development . I am learning to make a simple calculator using C++ .

Thanks for reading .
 

Saturday, 27 September 2014

Back in Action !

"Sometimes a break is all you need" . My mid semester exams are over and now, I am totally free as I  have holidays . I am not going to my home . Instead I've planned to add new data structures and algorithms in my arsenal . These 15 days will going to be a lot more exciting and adventurous as for past 14 odd days I wasn't coding .

After the break I am back and ready to give my 100% .

Let the code begin ! 

Sunday, 14 September 2014

Ups and downs again .

This week was not very good but still I learned a lot . Not very good because I didn't rise up in terms of ratings and scores but good as I still learned may new things , things which can only be learnt through failures after all a monotonously increasing graph is really 'monotonous' .

1. I couldn't solve a single question in the Codechef's long contest .(I just can't believe it,I think I didn't try much harder).
2. My last 2 matches on codeforces were not so good as my rating decreased heavily .
But at the end of the week.
My team got selected for Codesprint contest (National contest) and we solved all the questions given and in that I played a major role in solving 2 toughest questions(only 1 was a little bit trickier the other was easy).

Life is so much funny, sometimes you fall down sometimes you rise like anything.

I care less for results and more for actual learning because results are the outputs and if you don't give some input how will you get output ?

My mid semester Examinations are coming next week . So, I'll be taking a short break from programming because academics are also necessary .

Thanks for reading . Keep learning . Keep coding . 

Sunday, 7 September 2014

Another amazing week !

These days I am learning concepts related to number theory . As said by C.F. Gauss "Mathematics is the queen of sciences and number theory is the queen of mathematics" I learned a lot this week some of the things which I learned includes Fermat's Primality Test,Goldbach's conjecture, finding primitive root of a prime,etc,.

This week I participated in Topcoder SRM also and solved 2 problems out of three . In the beginning of the contest I was messing with the 250 pt problems and I took a lot of time to get it correct I was at the 18 or 19 th position in my room of around 25-30 contestants but I solved the 2nd problem slightly fast and ended up with 7th position and added some positive points in my rating :) .

Thanks for reading .