Пример #1
0
    public static void XAxisWeightMinDistance2()
    {
        XAxisWeightMinDistanceData test = new XAxisWeightMinDistanceData();
        double total = 0;

        foreach (var iter in test.m_posList)
        {
            total += iter;
        }

        // f(x) = Abs(x - x1) * weight1 + ...Abs(x - xN) * weightN - ( total / 2)
        double t1 = 20d, t2 = 0;

        do
        {
            double sum = test.GetDistance(t1);
            t2 = t1 - (sum - total / 2) / test.GetDistanceDerivative(t1);

            if (Math.Abs(t1 - t2) < 0.001d)
            {
                break;
            }

            t1 = t2;
        } while (true);

        double minSum = test.GetDistance(t2);

        Debug.Log("XAxisWeightMinDistance2 " + minSum + " minPos " + t2);
    }
Пример #2
0
    public static void XAxisWeightMinDistance3()
    {
        XAxisWeightMinDistanceData test = new XAxisWeightMinDistanceData();
        double minX   = test.GetMinWeightDistanceX();
        double minSum = test.GetDistance(minX);

        Debug.Log("XAxisWeightMinDistance3 " + minSum + " minX " + minX);
    }
Пример #3
0
    public static void XAxisWeightMinDistance()
    {
        XAxisWeightMinDistanceData test = new XAxisWeightMinDistanceData();

        double total = 0;

        foreach (var iter in test.m_posList)
        {
            total += iter;
        }

        double minDistance = double.MaxValue;
        double minPos      = double.MaxValue;
        double step        = 0.1d;

        for (int i = 0; i < 1000; ++i)
        {
            double curPos = step * i;
            double sum    = 0;
            foreach (var iter in test.m_posList)
            {
                //double weight = iter.Item2;
                sum += Math.Abs(curPos - iter);
            }
            if (sum < minDistance)
            {
                minDistance = sum;
                minPos      = curPos;
            }
        }
        Debug.Log("total " + total + " XAxisWeightMinDistance " + minDistance + " minPos " + minPos);

        List <FunctionDraw> drawList = new List <FunctionDraw>();

        drawList.Add(new FunctionDraw(test.GetDistance, 0.001d));
        Bitmap bitmap = DrawFunctionHelper.DrawFunction(drawList,
                                                        test.m_posList[0] - 10, test.m_posList[test.m_posList.Count - 1], -10, +100, "XAxisWeightMinDistance");
        string fileName = "XAxisWeightMinDistance" + Debug.GetTime() + ".bmp";

        bitmap.Save(fileName);
    }