DeadlyNightshade

08-12-2012, 12:51 PM

Ok so I know how to do this in theory, but what I need help with is the code.

The idea is to make a procedure that runs a set of command "for" each selected face.

The following is the pseudo code part:

$faces = polyEvaluate -f;

for each face/polygon(

select face

convert face selection to uv's

numPoints = selected uv count

enter each uv coordinate into two arrays, one for X and one for Y

(so that $X[0] is the X and $Y[0] is the y of the same coordinates)

Then run the following function (JAVA!! Has to be converted to MEL):

function polygonArea(X, Y, numPoints)

{

area = 0; // Accumulates area in the loop

j = numPoints-1; // The last vertex is the 'previous' one to the first

for (i=0; i<numPoints; i++)

{ area = area + (X[j]+X[i]) * (Y[j]-Y[i]);

j = i; //j is previous vertex to i

}

return area/2;

}

I started by looking up the Shoelace formula (aka Gauss area formula) which calculates the area of a polygon based on it's coordinates. But then I found out that someone has already made a computer algoritm for this at mathopenref:

http://www.mathopenref.com/coordpolygonarea2.html

Converting the JAVA to MEL is the lesser problem. My bigger problem is constructing a good for-loop that selects one face, inserts it's UV's into two arrays, runs the algoritm and then moves on to the next face in the selection.

Any help is appreaciated.

The idea is to make a procedure that runs a set of command "for" each selected face.

The following is the pseudo code part:

$faces = polyEvaluate -f;

for each face/polygon(

select face

convert face selection to uv's

numPoints = selected uv count

enter each uv coordinate into two arrays, one for X and one for Y

(so that $X[0] is the X and $Y[0] is the y of the same coordinates)

Then run the following function (JAVA!! Has to be converted to MEL):

function polygonArea(X, Y, numPoints)

{

area = 0; // Accumulates area in the loop

j = numPoints-1; // The last vertex is the 'previous' one to the first

for (i=0; i<numPoints; i++)

{ area = area + (X[j]+X[i]) * (Y[j]-Y[i]);

j = i; //j is previous vertex to i

}

return area/2;

}

I started by looking up the Shoelace formula (aka Gauss area formula) which calculates the area of a polygon based on it's coordinates. But then I found out that someone has already made a computer algoritm for this at mathopenref:

http://www.mathopenref.com/coordpolygonarea2.html

Converting the JAVA to MEL is the lesser problem. My bigger problem is constructing a good for-loop that selects one face, inserts it's UV's into two arrays, runs the algoritm and then moves on to the next face in the selection.

Any help is appreaciated.