For my OBJ optimizer, I need a way to determine if a point is co-planar, with the input being a Vector3 point on the plane, a unit Vector3 for the normal, and a point to check if it is co-planar. I want to avoid CFrame math since I don’t want to re-implement CFrames in the language I am using.
Not sure if correct.
function IsCoplanar(origin, normal, point)
return (point-origin):Dot(normal) == 0
end
5 Likes
Works for me.
Validation code:
function Coplanar(origin, normal, point)
return (point-origin):Dot(normal) == 0
end
local Normal = Vector3.new(0,0,1)
local Point1 = Vector3.new(0,3,2)
local Point2 = Vector3.new(-2,3,2)
local Point3 = Vector3.new(3,5,2)
local Point4 = Vector3.new(2,4,5)
print("Same point: "..(Coplanar(Point1,Normal,Point1) and "Pass" or "Fail"))
print("Generic point 1: "..(Coplanar(Point1,Normal,Point2) and "Pass" or "Fail"))
print("Generic point 2: "..(Coplanar(Point1,Normal,Point3) and "Pass" or "Fail"))
print("Non co-planar point: "..(not Coplanar(Point1,Normal,Point4) and "Pass" or "Fail"))
Output:
1 Like
I would probably replace the == 0
with math.abs(...) < eps
for the more general solution, you don’t have to deal with floating point errors in your test cases because your normal is axis-aligned and all the coordinates are integers here. For the general case == 0
won’t be sufficient.
7 Likes