Problem 558. Is the Point in a Triangle?
Solution Stats
Problem Comments
-
9 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
Solution Comments
-
1 Comment
this took a minute to think about!
-
1 Comment
so smart
-
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(y1-y2)]/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 Solvers888
Suggested Problems
-
Find common elements in matrix rows
1843 Solvers
-
Renaming a field in a structure array
1027 Solvers
-
Return the first and last characters of a character array
5992 Solvers
-
Fix the last element of a cell array
694 Solvers
-
8633 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!