コード例 #1
0
        private double FaceVariance(short v1, short v2, short v3)
        {
            double MaxVar = 0;

            if ((v1 - v2 <= 1 && v1 - v2 >= -1) || (v3 - v2 <= 1 && v3 - v2 >= -1) || v3 == v1)
            {
                MaxVar = 0; // minimal face, no variance
            }
            else
            {
                try
                {
                    // find vertice in middle of hypothenuse
                    short mid_hyp_indice = MidHypVerticeIndice(v1, v3);
                    // find real elevation in middle of hypothenuse
                    CustomVertex.PositionColoredTextured vh = this._elevatedVertices[mid_hyp_indice];
                    Vector3d v    = SMath.CartesianToSpherical((double)vh.X, (double)vh.Y, (double)vh.Z);
                    double   real = v.X - this._layerRadius;
                    // find extrapolated elevation in middle hyp.
                    double xe = (this._elevatedVertices[v1].X + this._elevatedVertices[v3].X) / 2;
                    double ye = (this._elevatedVertices[v1].Y + this._elevatedVertices[v3].Y) / 2;
                    double ze = (this._elevatedVertices[v1].Z + this._elevatedVertices[v3].Z) / 2;
                    v = SMath.CartesianToSpherical(xe, ye, ze);
                    double extrapolated = v.X - this._layerRadius;
                    // variance Note: could be done w/out MathEngine by computing raw cartesian distance
                    MaxVar = real - extrapolated;
                    // recurse for potential childs until unit face

                    if (v2 != v1 || mid_hyp_indice != v2 || v1 != v3)
                    {
                        MaxVar = Math.Max(MaxVar, FaceVariance(v2, mid_hyp_indice, v1));
                    }
                    if (v3 != v1 || mid_hyp_indice != v2 || v2 != v3)
                    {
                        MaxVar = Math.Max(MaxVar, FaceVariance(v3, mid_hyp_indice, v2));
                    }
                }
                catch
                {
                }
            }
            return(MaxVar);
        }