I’ve searched and searched and I can’t seem to find any plausible way to do this. I’ve tried pretty much all equations on stackflow, I’ve tried substituting the Y for the Z, but nothing seems to work well.
I’m looking to check if a part is within three other vectors, a triangle, I don’t want the Y-Axis to be taken in to account.
if the y axis doesn’t need to be taken in consideration then this problem becomes rather 2D. So using a normal 2d point in triangle function should work with just substituting the y for z . For example, using barycentric coordinates (for efficiency) and some math described all over this StackOverFlow thread, something like this should work:
local function PointInTriangle(p, p0, p1,p2)
local s = p0.Z * p2.X - p0.X * p2.Z + (p2.Z - p0.Z) * p.X + (p0.X - p2.X) * p.Z
local t = p0.X * p1.Z - p0.Z * p1.X + (p0.Z - p1.Z) * p.X + (p1.X - p0.X) * p.Z
if (s < 0) ~= (t < 0) then
return false
end
local Area = -p1.Z * p2.X + p0.Z * (p2.X - p1.X) + p0.X * (p1.Z - p2.Z) + p1.X * p2.Z
if Area < 0 then
return (s <= 0 and s + t >= Area)
else
return(s >= 0 and s + t <= Area)
end
end
no problem, but don’t give me all the credit!..this time…, just some simple conversion from a C# function to a Lua one was all. Anyways, if you want to there were some other really good/interesting answers on that stackoverflow thread i would recommend checking out.