Пример #1
0
    Vector3 CalculateSurfaceNormal(Vector3 p)
    {
        float H  = 0.001f;
        float dx = DensityFunctions.Density_Func(p + new Vector3(H, 0.0f, 0.0f)) - DensityFunctions.Density_Func(p - new Vector3(H, 0.0f, 0.0f));
        float dy = DensityFunctions.Density_Func(p + new Vector3(0.0f, H, 0.0f)) - DensityFunctions.Density_Func(p - new Vector3(0.0f, H, 0.0f));
        float dz = DensityFunctions.Density_Func(p + new Vector3(0.0f, 0.0f, H)) - DensityFunctions.Density_Func(p - new Vector3(0.0f, 0.0f, H));

        return(Vector3.Normalize(new Vector3(dx, dy, dz)));
    }
Пример #2
0
    Vector3 ApproximateZeroCrossingPosition(Vector3 p0, Vector3 p1)
    {
        // approximate the zero crossing by finding the min value along the edge
        float minValue  = 100000.0f;
        float t         = 0.0f;
        float currentT  = 0.0f;
        int   steps     = 8;
        float increment = 1.0f / (float)steps;

        while (currentT <= 1.0f)
        {
            Vector3 p       = p0 + ((p1 - p0) * currentT);
            float   density = Mathf.Abs(DensityFunctions.Density_Func(p));
            if (density < minValue)
            {
                minValue = density;
                t        = currentT;
            }

            currentT += increment;
        }

        return(p0 + ((p1 - p0) * t));
    }