private static double calculateYValue(double[] v, Punkt point)
 {
     return v[1] * point.getX() - v[0] * point.getY() + v[3];
 }
        // Matrix 
        public static double[] calcVecABCD(Punkt oP1, Punkt oP2, Punkt rP1, Punkt rP2)
        {
            // Matrixattribute
            double x1 = oP1.getX(), y1 = oP1.getY(), x2 = oP2.getX(), y2 = oP2.getY();
            double rx1 = rP1.getX(), ry1 = rP1.getY(), rx2 = rP2.getX(), ry2 = rP2.getY();

            // Vektor u
            double[] u = new double[] { rx1, ry1, rx2, ry2 };

            double[] m1 = new double[] { x1, y1, 1, 0 };
            double[] m2 = new double[] {-1 * y1, x1, 0, 1};
            double[] m3 = new double[] { x2, y2, 1, 0 };
            double[] m4 = new double[] {-1* y2, x2, 0, 1};

            List<double[]> tmp = new List<double[]>();
            tmp.Add(m1);
            tmp.Add(m2);
            tmp.Add(m3);
            tmp.Add(m4);

            // Matrix M
            double[][] M = new double[4][];
            for (int i = 0; i < tmp.Count; i++){
                M[i] = new double[4];
                for (int j = 0; j < tmp[i].Length; j++){
                    M[i][j] = tmp[i][j];
                }
            }

            // inverse Matrix M
            double[][] M1 = inverse2DMatrix(M);

            // invM multipliziert mit u
            double[] v = multiplyMatrix1D(M1, u);

            // Zielvektor v
            return v;
        }
        // berechnet den Flächeninhalt eines Polygons
        static public double calcAreaPolygon(List<Punkt> inputPoints)
        {
            List<Punkt> points = new List<Punkt>();
            // transferieren der Punktdaten
            for (int i = 0; i < inputPoints.Count; i++)
            {
                points.Add(inputPoints[i]);
            }

            // Liste mit sortierten Punkten
            List<Punkt> calcPoints = new List<Punkt>();
            Punkt tmpPoint = null;

            // Punkt 1
            double a = 100000.00;
            for (int i = 0; i < points.Count; i++)
            {
                // suche nach der geringsten Distanz zum Ursprung
                double t = Math.Sqrt(Math.Pow(points[i].getX(), 2) + Math.Pow(points[i].getY(), 2));
                if (t < a) {
                    a = t;
                    tmpPoint = points[i];
                }
            }

            calcPoints.Add(tmpPoint);
            points.Remove(tmpPoint);

            tmpPoint = null;
            
            // Punkt 2
            Punkt y_min = new Punkt(100000.0, 10000.0);
            tmpPoint = new Punkt(100000.0, 100000.0);

            for (int i = 0; i < points.Count; i++)
            {
                if (y_min.getY() > points[i].getY())
                {
                    y_min = points[i];
                }
            }

            for (int i = 0; i < points.Count; i++)
            {
                if (points[i] != y_min)
                {
                    if (tmpPoint.getX() > points[i].getX())
                    {
                        tmpPoint = points[i];
                    }
                }
            }

            calcPoints.Add(tmpPoint);
            points.Remove(tmpPoint);

            tmpPoint = null;
            y_min = null;

            // Punkt 3
            y_min = new Punkt(100000.0, 10000.0);
            tmpPoint = new Punkt(0.0, 0.0);

            for (int i = 0; i < points.Count; i++)
            {
                if (y_min.getY() > points[i].getY())
                {
                    y_min = points[i];
                }
            }

            for (int i = 0; i < points.Count; i++)
            {
                if (points[i] != y_min)
                {
                    if (tmpPoint.getX() < points[i].getX())
                    {
                        tmpPoint = points[i];
                    }
                }
            }

            calcPoints.Add(tmpPoint);
            points.Remove(tmpPoint);

            tmpPoint = null;

            // Punkt 4
            calcPoints.Add(points[0]);

            // Berechnung der Fläche anhand eines Polygonzuges
            double area = (calcPoints[0].getY() + calcPoints[1].getY()) * (calcPoints[0].getX() - calcPoints[1].getX()) +
                (calcPoints[1].getY() + calcPoints[2].getY()) * (calcPoints[1].getX() - calcPoints[2].getX()) +
                (calcPoints[2].getY() + calcPoints[3].getY()) * (calcPoints[2].getX() - calcPoints[3].getX()) +
                (calcPoints[3].getY() + calcPoints[0].getY()) * (calcPoints[3].getX() - calcPoints[0].getX());

            if (area < 0)
            {
                area = area * -1;
            }

            return area / 2;
        }
 // Berechnet die Distanz zwischen zwei Punkten
 public static double calculateEukDistance(Punkt p1, Punkt p2)
 {
     return Math.Sqrt(Math.Pow(p1.getX() - p2.getX(), 2) + Math.Pow(p1.getY() - p2.getY(), 2));
 }
        // berechnet den Mittelpunkt eines Viereckes
        static public Punkt calcCenterCube(List<Punkt> inputPoints)
        {
            List<Punkt> points = new List<Punkt>();
            // transferieren der Punktdaten
            for (int i = 0; i < inputPoints.Count; i++)
            {
                points.Add(inputPoints[i]);    
            }

            // Liste mit sortierten Punkten
            List<Punkt> calcPoints = new List<Punkt>();
            Punkt tmpPoint = null;

            // Punkt 1
            double a = 100000.00;
            for (int i = 0; i < points.Count; i++)
            {
                // suche nach der geringsten Distanz zum Ursprung
                double t = Math.Sqrt(Math.Pow(points[i].getX(), 2) + Math.Pow(points[i].getY(), 2));
                if (t < a)
                {
                    a = t;
                    tmpPoint = points[i];
                }
            }

            calcPoints.Add(tmpPoint);
            points.Remove(tmpPoint);

            tmpPoint = null;

            // Punkt 2
            Punkt y_min = new Punkt(100000.0, 10000.0);
            tmpPoint = new Punkt(100000.0, 100000.0);

            for (int i = 0; i < points.Count; i++)
            {
                if (y_min.getY() > points[i].getY())
                {
                    y_min = points[i];
                }
            }

            for (int i = 0; i < points.Count; i++)
            {
                if (points[i] != y_min)
                {
                    if (tmpPoint.getX() > points[i].getX())
                    {
                        tmpPoint = points[i];
                    }
                }
            }

            calcPoints.Add(tmpPoint);
            points.Remove(tmpPoint);

            tmpPoint = null;
            y_min = null;

            // Punkt 3
            y_min = new Punkt(100000.0, 10000.0);
            tmpPoint = new Punkt(0.0, 0.0);

            for (int i = 0; i < points.Count; i++)
            {
                if (y_min.getY() > points[i].getY())
                {
                    y_min = points[i];
                }
            }

            for (int i = 0; i < points.Count; i++)
            {
                if (points[i] != y_min)
                {
                    if (tmpPoint.getX() < points[i].getX())
                    {
                        tmpPoint = points[i];
                    }
                }
            }

            calcPoints.Add(tmpPoint);
            points.Remove(tmpPoint);

            tmpPoint = null;

            // Punkt 4
            calcPoints.Add(points[0]);

            // Gerade 1
            double m1 = 0.0;
            if ((calcPoints[0].getY() == calcPoints[2].getY()) || (calcPoints[0].getX() == calcPoints[2].getX())){
                m1 = 0.0;
            }
            else
            {
                m1 = (calcPoints[0].getY() - calcPoints[2].getY()) / (calcPoints[0].getX() - calcPoints[2].getX());
            }
            double b1 = calcPoints[0].getY() - calcPoints[0].getX() * m1;

            // Gerade 2
            double m2 = 0.0;
            if ((calcPoints[1].getY() == calcPoints[3].getY()) || (calcPoints[1].getX() == calcPoints[3].getX()))
            {
                m2 = 0.0;
            }
            else
            {
                m2 = (calcPoints[1].getY() - calcPoints[3].getY()) / (calcPoints[1].getX() - calcPoints[3].getX());
            }
            double b2 = calcPoints[1].getY() - calcPoints[1].getX() * m2;

            // Berechnung des Schnittpunktes
            double xs = m1 - m2;
            double bs = b2 - b1;
            double x = bs / xs;
            double y = x * m1 + b1;
            return new Punkt(x, y);
        }