コード例 #1
0
        public void computeNormal(Vector3d normal, double minArea)
        {
            computeNormal(normal);

            if (area < minArea)
            {
                Console.WriteLine("area=" + area);
                // make the normal more robust by removing
                // components parallel to the longest edge

                HalfEdge hedgeMax  = null;
                double   lenSqrMax = 0;
                HalfEdge hedge     = he0;
                do
                {
                    double lenSqr = hedge.lengthSquared();
                    if (lenSqr > lenSqrMax)
                    {
                        hedgeMax  = hedge;
                        lenSqrMax = lenSqr;
                    }
                    hedge = hedge.next;
                }while (hedge != he0);

                Point3d p2     = hedgeMax.head().pnt;
                Point3d p1     = hedgeMax.tail().pnt;
                double  lenMax = Math.Sqrt(lenSqrMax);
                double  ux     = (p2.x - p1.x) / lenMax;
                double  uy     = (p2.y - p1.y) / lenMax;
                double  uz     = (p2.z - p1.z) / lenMax;
                double  dot    = normal.x * ux + normal.y * uy + normal.z * uz;
                normal.x -= dot * ux;
                normal.y -= dot * uy;
                normal.z -= dot * uz;

                normal.normalize();
            }
        }