void CalculatePlaneEquation() { double len; int i; Vector3d ref1, norm, v1, v2; Point3d vert1, vert2; ref1 = new Vector3d(); norm = new Vector3d(); v1 = new Vector3d(); v2 = new Vector3d(); for(i=0; i < m_points.Length; i++) { vert1 = m_points[i]; vert2 = m_points[(i+1) % m_points.Length]; v1.x = vert1.x; v1.y = vert1.y; v1.z = vert1.z; v2.x = vert2.x; v2.y = vert2.y; v2.z = vert2.z; norm.x += (v1.y - v2.y)*(v1.z + v2.z); norm.y += (v1.z - v2.z)*(v1.x + v2.x); norm.z += (v1.x - v2.x)*(v1.y + v2.y); ref1.x += v1.x; ref1.y += v1.y; ref1.z += v1.z; } len = norm.Mag(); plane.a = norm.x / len; plane.b = norm.y / len; plane.c = norm.z / len; len *= m_points.Length; plane.d = -ref1.Dot(norm) / len; }