Answers for "How to calculate the surface area of a irregular polygon"
http://answers.unity.com/questions/684909/how-to-calculate-the-surface-area-of-a-irregular-p.html
The latest answers for the question "How to calculate the surface area of a irregular polygon"Answer by fafase
http://answers.unity.com/answers/684919/view.html
Lucky you I did that a while ago. This only works on polygon that will not have crossing edges. The list is just the list of point you use as vertices of the polygon, they should be GameObject but you can make them Transform, you would then have to remove the transform part of the code.
float SuperficieIrregularPolygon(){
float temp = 0;
int i = 0 ;
for(; i < list.Count ; i++){
if(i != list.Count - 1){
float mulA = list[i].transform.position.x * list[i+1].transform.position.z;
float mulB = list[i+1].transform.position.x * list[i].transform.position.z;
temp = temp + ( mulA - mulB );
}else{
float mulA = list[i].transform.position.x * list[0].transform.position.z;
float mulB = list[0].transform.position.x * list[i].transform.position.z;
temp = temp + ( mulA - mulB );
}
}
temp *= 0.5f;
return Mathf.Abs(temp);
}
I did not invent that equation it comes from Wikipedia http://en.wikipedia.org/wiki/Polygon go down to Area and Centroid, first equation.
And that will return the area of the flat polygon but I guess that is what you are after since you mention a square. If you need the area of non-flat area then you would have to repeat the above process for all little areas and add them up.Fri, 11 Apr 2014 14:26:32 GMTfafase