--三角形与点的碰撞 function TriangleToPoint(trianglePos1, trianglePos2,trianglePos3,point)--这里有多种做法,--一种是让三角形三个点顺时针或逆时针组合成三个向量 再让各自向量起点与point构成一个新的向量 然后分别取叉乘,得到的数是同正或者同负(当然还需要判断点是否在直线上的情况就是叉乘结果为0的情况)--以下第二种做法,大家可以去了解一下 叉乘的模 / 2 为两个向量围成的三角形面积,下面以面积的方式进行运算--叉乘公式自己可以去了解一下 二维叉乘 A X B = (0,0,A.x * B.y - A.y * B.x)向量local vec12 = {x = (trianglePos2.x - trianglePos1.x) , y = (trianglePos2.y - trianglePos1.y)}local vec1ToPoint = {x = (point.x - trianglePos1.x) , y = (point.y - trianglePos1.y)}local vec23 = {x = (trianglePos3.x - trianglePos2.x) , y = (trianglePos3.y - trianglePos2.y)}local vec2ToPoint = {x = (point.x - trianglePos2.x) , y = (point.y - trianglePos2.y)}local vec31 = {x = (trianglePos1.x - trianglePos3.x) , y = (trianglePos1.y - trianglePos3.y)}local vec3ToPoint = {x = (point.x - trianglePos3.x) , y = (point.y - trianglePos3.y)}local area1 = math.abs(vec12.x * vec1ToPoint.y - vec12.y * vec1ToPoint.x)local area2 = math.abs(vec23.x * vec2ToPoint.y - vec23.y * vec2ToPoint.x)local area3 = math.abs(vec31.x * vec3ToPoint.y - vec31.y * vec3ToPoint.x)local areaAll = math.abs(vec12.x * (0 - vec31.y) - vec12.y * (0-vec31.x))return areaAll == (area1+area2+area3)end