I have a little Windows program that reads T3D files and does some checks on it. Concerning brushes I'm interested how to check if a surface with more than 3 vertices is planar, but the time I did vector analysis is long ago and I've rarely used it since then...^^ One approach is to build all possible planes with exact 3 vertices and verify that the normal vectors are linearly dependent.
But perhaps anybody has vector calculations in shorter memory access and can provide a simpler solution.
Math: is a surface planar?
Math: is a surface planar?
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Re: Math: is a surface planar?
If you don't mind inconsistancies on very small surfaces.
OPEN UnMath.h (from ut public sources) to see how to use the following operations.
Create the FPlane struct using 3 points of the face.
Then perform 'PlaneDot' for any other points (from point 4 and onwards) using that FPlane.
If the absolute value of that 'PlaneDot' result is greater than... let's say 1, then surface isn't planar.
PlaneDot tells you how far out (or in) a point is towards a plane, in unreal units, can have negative values.
Values close to zero mean that the point is in that plane.
OPEN UnMath.h (from ut public sources) to see how to use the following operations.
Create the FPlane struct using 3 points of the face.
Then perform 'PlaneDot' for any other points (from point 4 and onwards) using that FPlane.
If the absolute value of that 'PlaneDot' result is greater than... let's say 1, then surface isn't planar.
PlaneDot tells you how far out (or in) a point is towards a plane, in unreal units, can have negative values.
Values close to zero mean that the point is in that plane.
Re: Math: is a surface planar?
From top of my head:
- Pick three different vertices A, B and C.
(Make sure they are distinct locations. If not, pick a different combination of three vertices from the surface.) - Define two vectors a = C - A and b = C - B to establish the surface orientation.
(Make sure the two vectors are not parallel, otherwise start over with a different combination of vertices.) - Define a vector that is perpendicular to the surface: n = a cross b. You might want to normalize it.
(The cross product can act as both your distinct-edges check and your parallelity check, because it will yield a vector of length zero if either the input vectors are parallel or at least one of them is a zero vector itself.) - Pick one vertex R of the surface as reference. (Could also be A, B or C.)
- For each other vertex V of the surface, define a vector v = R - V. This vector will be perpendicular to the surface normal vector if the surface is planar, i.e. their dot product will be zero: n dot v == 0