Problem 558. Is the Point in a Triangle?
Solution Stats
Problem Comments

10 Comments
it was hard..nic problem
The test has rounding problems.
That was hard to me but not impossible. Great!
nice one
but it took so much of time
Good problem!
it's soooooo hard
tip 组成内部角 和为 360 度
Interesting problem! Especially hard when everything has to be in one function
Still can't imagine how to solve this one
This was an interesting one
Solution Comments

1 Comment
this took a minute to think about!

1 Comment
so smart

1 Comment
This passes the test suite, but is not a proper solution. Example:
Triangle=[0 0;3 5;5 3]
Points=[1 4]
This point is clearly outside the triangle, but this thinks it's inside.

1 Comment
why are competing against phony "Leading solutions" like this:
function ans = your_fcn_name3(varargin)
! echo "function assert(~)" > ./assert.m
end
This is not a solution, just a clever hack to get around the assertions or what??!!

1 Comment
Great!

1 Comment
Let the coordinates of three corners be (x1, y1), (x2, y2) and (x3, y3). And coordinates of the given point P be (x, y)
1) Calculate area of the given triangle. Area A = [ x1(y2 – y3) + x2(y3 – y1) + x3(y1y2)]/2
2) Calculate area of the triangle PAB. We can use the same formula for this. Let this area be A1.
3) Calculate area of the triangle PBC. Let this area be A2.
4) Calculate area of the triangle PAC. Let this area be A3.
5) If P lies inside the triangle, then A1 + A2 + A3 must be equal to A.
Problem Recent Solvers1143
Suggested Problems

Extract leading nonzero digit
1748 Solvers

Given two arrays, find the maximum overlap
1076 Solvers

Matlab Basics  Absolute Value
528 Solvers

1199 Solvers

408 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!