Esempio n. 1
0
    public static void desglosarFloatArrayEnVectoresNormales(FloatArray fa, out float[] xx, out float[] yy)
    {
        xx = new float[fa.size / 2];
        yy = new float[fa.size / 2];


        List <float> l4 = fa.toArray().ToList();

        for (int i = 0; i < l4.Count; i++)
        {
            if (i % 2 == 0)
            {
                xx[i / 2] = l4.ElementAt(i);
            }
            else
            {
                yy[(i - 1) / 2] = l4.ElementAt(i);
            }
        }
    }
Esempio n. 2
0
    public FloatArray computePolygon(float[] points, int offset, int count, bool sorted)
    {
        int end = offset + count;

        if (!sorted)
        {
            if (sortedPoints == null || sortedPoints.Length < count)
            {
                sortedPoints = new float[count];
            }
            Array.Copy(points, offset, sortedPoints, 0, count);
            points = sortedPoints;
            offset = 0;
            sort(points, count);
        }

        FloatArray hull = this.hull;

        hull.clear();

        // Lower hull.
        for (int i = offset; i < end; i += 2)
        {
            float x = points[i];
            float y = points[i + 1];
            while (hull.size >= 4 && ccw(x, y) <= 0)
            {
                hull.size -= 2;
            }
            hull.Add(x);
            hull.Add(y);
        }
        List <float> l1 = new List <float>();
        List <float> l2 = new List <float>();

        float[] xx = new float[hull.size];
        float[] yy = new float[hull.size];
        l1 = hull.toArray().ToList();
        l2 = hull.toArray().ToList();
        for (int i = 0; i < l1.Count; i++)
        {
            if (i % 2 == 0)
            {
                xx[i / 2] = l1.ElementAt(i);
            }
            else
            {
                yy[(i - 1) / 2] = l1.ElementAt(i);
            }
        }
        abajo = Punto.getArreglo(xx, yy);

        FloatArray hullAUX = new FloatArray();

        // Upper hull.
        for (int i = end - 4, t = hull.size + 2; i >= offset; i -= 2)
        {
            float x = points[i];
            float y = points[i + 1];
            while (hull.size >= t && ccw(x, y) <= 0)
            {
                hull.size -= 2;
            }
            hull.Add(x);
            hull.Add(y);
        }

        for (int i = end - 4, t = hullAUX.size + 2; i >= offset; i -= 2)
        {
            float x = points[i];
            float y = points[i + 1];
            while (hullAUX.size >= t && ccw(x, y) <= 0)
            {
                hullAUX.size -= 2;
            }
            hullAUX.Add(x);
            hullAUX.Add(y);
        }

        l1 = hullAUX.toArray().ToList();
        l2 = hullAUX.toArray().ToList();
        for (int i = 0; i < l1.Count; i++)
        {
            if (i % 2 == 0)
            {
                xx[i / 2] = l1.ElementAt(i);
            }
            else
            {
                yy[(i - 1) / 2] = l1.ElementAt(i);
            }
        }
        arriba = Punto.getArreglo(xx, yy);

        Array.Sort(arriba, ConvexHull.compararPorAbsisa());
        return(hull);
    }