예제 #1
0
        private void drawSingleStrecke(int i)
        {
            Line tempLine = new Line();

            tempLine.Stroke          = System.Windows.Media.Brushes.Red;
            tempLine.StrokeThickness = 3;
            cStrecken Strecke = meineStrecken[i];

            tempLine.X1 = Strecke.Ep1X;
            tempLine.Y1 = Strecke.Ep1Y;
            tempLine.X2 = Strecke.Ep2X;
            tempLine.Y2 = Strecke.Ep2Y;
            CanvasEinlesen.Children.Add(tempLine);
        }
예제 #2
0
        private void miEinselen_Click(object sender, RoutedEventArgs e)
        {
            clearAll();

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Text Files|*.txt";
            openFileDialog1.Title  = "Select a Text File";

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string[] dateiinhalt = File.ReadAllLines(openFileDialog1.FileName);
                for (int i = 1; i < dateiinhalt.Length; i++)
                {
                    string[]  tempCoord   = dateiinhalt[i].Split(' ');
                    float     tempEp1X    = float.Parse(tempCoord[0], CultureInfo.InvariantCulture);
                    float     tempEp1Y    = float.Parse(tempCoord[1], CultureInfo.InvariantCulture);
                    float     tempEp2X    = float.Parse(tempCoord[2], CultureInfo.InvariantCulture);
                    float     tempEp2Y    = float.Parse(tempCoord[3], CultureInfo.InvariantCulture);
                    cStrecken tempStrecke = new cStrecken(tempEp1X, tempEp1Y, tempEp2X, tempEp2Y);
                    meineStrecken.Add(tempStrecke);
                }

                foreach (cStrecken Strecke in meineStrecken)
                {
                    lbCoord.Items.Add("ID: " + Strecke.MyId + " P1: (" + Strecke.Ep1X + "|" + Strecke.Ep1Y + ") P2: (" + Strecke.Ep2X + "|" + Strecke.Ep2Y + ")");
                    Line tempLine = new Line();
                    tempLine.Stroke          = System.Windows.Media.Brushes.Black;
                    tempLine.StrokeThickness = 3;
                    tempLine.X1 = Strecke.Ep1X;
                    tempLine.Y1 = Strecke.Ep1Y;
                    tempLine.X2 = Strecke.Ep2X;
                    tempLine.Y2 = Strecke.Ep2Y;
                    CanvasEinlesen.Children.Add(tempLine);
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Keine Datei gewählt");
            }
        }
예제 #3
0
        private void FindIntersection(cStrecken linie1, cStrecken linie2,
                                      out bool lines_intersect, out bool segments_intersect,
                                      out PointF intersection,
                                      out PointF close_p1, out PointF close_p2)
        {
            PointF p1 = new PointF(linie1.Ep1X, linie1.Ep1Y);
            PointF p2 = new PointF(linie1.Ep2X, linie1.Ep2Y);
            PointF p3 = new PointF(linie2.Ep1X, linie2.Ep1Y);
            PointF p4 = new PointF(linie2.Ep2X, linie2.Ep2Y);

            // Get the segments' parameters.
            float dx12 = p2.X - p1.X;
            float dy12 = p2.Y - p1.Y;
            float dx34 = p4.X - p3.X;
            float dy34 = p4.Y - p3.Y;

            // Solve for t1 and t2
            float denominator = (dy12 * dx34 - dx12 * dy34);

            float t1 =
                ((p1.X - p3.X) * dy34 + (p3.Y - p1.Y) * dx34)
                / denominator;

            if (float.IsInfinity(t1))
            {
                // The lines are parallel (or close enough to it).
                lines_intersect    = false;
                segments_intersect = false;
                intersection       = new PointF(float.NaN, float.NaN);
                close_p1           = new PointF(float.NaN, float.NaN);
                close_p2           = new PointF(float.NaN, float.NaN);
                return;
            }
            lines_intersect = true;

            float t2 =
                ((p3.X - p1.X) * dy12 + (p1.Y - p3.Y) * dx12)
                / -denominator;

            // Find the point of intersection.
            double tempX = p1.X + dx12 * t1;
            double tempY = p1.Y + dy12 * t1;

            intersection = new PointF(Convert.ToSingle(Math.Round(tempX, 2)), Convert.ToSingle(Math.Round(tempY, 2)));

            // The segments intersect if t1 and t2 are between 0 and 1.
            segments_intersect =
                ((t1 >= 0) && (t1 <= 1) &&
                 (t2 >= 0) && (t2 <= 1));

            // Find the closest points on the segments.
            if (t1 < 0)
            {
                t1 = 0;
            }
            else if (t1 > 1)
            {
                t1 = 1;
            }

            if (t2 < 0)
            {
                t2 = 0;
            }
            else if (t2 > 1)
            {
                t2 = 1;
            }

            close_p1 = new PointF(p1.X + dx12 * t1, p1.Y + dy12 * t1);
            close_p2 = new PointF(p3.X + dx34 * t2, p3.Y + dy34 * t2);
        }