题目如下:
代码如下:
package huawei; public final class Demo { public static boolean isInTriangle(POINT A, POINT B, POINT C, POINT P) { double ABC = triAngleArea(A, B, C); double ABp = triAngleArea(A, B, P); double ACp = triAngleArea(A, C, P); double BCp = triAngleArea(B, C, P); if (ABC == ABp + ACp + BCp) {// 若面积之和等于原三角形面积,证明点在三角形内 return true; } else { return false; } } private static double triAngleArea(POINT A, POINT B, POINT C) {// 由三个点计算这三个点组成三角形面积 double result = Math.abs((A.x * B.y + B.x * C.y + C.x * A.y - B.x * A.y - C.x * B.y - A.x * C.y) / 2.0D); return result; } }
原文:http://blog.csdn.net/yayun0516/article/details/50492226