# MEL How-To #90

 Back · Previous · Next Maya

## How can I determine if a polygon face component is planar?

The following MEL procedure can be used to determine if a polymesh face is planar.

Some error-checking is avoided in the following example code. The downloadable script (at left) contains robust error-checking.

```global proc int isPlanar( string \$mesh, int \$face )
{
// Get vertices for this face
string \$vertices[] = `polyListComponentConversion -toVertex ( \$mesh + ".f[" + \$face + "]" )`;

// Because the -toVertex result is non-expanded, select and get expanded version

select -r \$vertices;
\$vertices = `filterExpand -sm 31 -ex true`;

// If this face is triangular, it is a given that it is planar.
if ( size( \$vertices ) == 3 )
return true;

// Derive normal from first three vertices in face
float \$f0 = `xform -ws -q -t \$vertices`;
float \$f1 = `xform -ws -q -t \$vertices`;
float \$f2 = `xform -ws -q -t \$vertices`;

vector \$v1 = << \$f1, \$f1, \$f1 >> - << \$f0, \$f0, \$f0 >>;
vector \$v2 = << \$f2, \$f2, \$f2 >> - << \$f0, \$f0, \$f0 >>;

vector \$normal = unit( \$v1 ^ \$v2 );   // cross product

// For each additional vertex, generate vector from vertex to plane of triangle
for ( \$v = 3; \$v < size( \$vertices ); \$v++ )
{
float \$f = `xform -ws -q -t \$vertices[\$v]`;
vector \$vp  = << \$f - \$f0, \$f - \$f0, \$f - \$f0 >>;

// Take dot-product of vector to normal of plane
float \$dot = \$vp * \$normal;

// If distance determined by dot-product is not equal to 0, this face is not planar
if ( \$dot != 0 )
return false;
}

// The face is planar
return true;
}
```

### Related How-To's

Tuesday, December 05, 2000