public void UpdateGraphics(object parameter) { IntersectionPointControl.viewPortCanvas.Children.Clear(); // Line T double tXstart = Convert.ToDouble(IntersectionPointControl.txtTXstart.Text); double tYstart = Convert.ToDouble(IntersectionPointControl.txtTYstart.Text); double tXend = Convert.ToDouble(IntersectionPointControl.txtTXend.Text); double tYend = Convert.ToDouble(IntersectionPointControl.txtTYend.Text); PointXY pointStartT = new PointXY(tXstart, tYstart); PointXY pointEndT = new PointXY(tXend, tYend); LineT = new LineSegment(pointStartT, pointEndT); Line pathT = new Line(); pathT.X1 = viewPortArea.XNormalize(tXstart, IntersectionPointControl.viewPortCanvas.Width); pathT.Y1 = viewPortArea.YNormalize(tYstart, IntersectionPointControl.viewPortCanvas.Height); pathT.X2 = viewPortArea.XNormalize(tXend, IntersectionPointControl.viewPortCanvas.Width); pathT.Y2 = viewPortArea.YNormalize(tYend, IntersectionPointControl.viewPortCanvas.Height); pathT.Stroke = Brushes.Blue; pathT.StrokeThickness = 2; IntersectionPointControl.viewPortCanvas.Children.Add(pathT); // Line V double vXstart = Convert.ToDouble(IntersectionPointControl.txtVXstart.Text); double vYstart = Convert.ToDouble(IntersectionPointControl.txtVYstart.Text); double vXend = Convert.ToDouble(IntersectionPointControl.txtVXend.Text); double vYend = Convert.ToDouble(IntersectionPointControl.txtVYend.Text); PointXY pointStartV = new PointXY(vXstart, vYstart); PointXY pointEndV = new PointXY(vXend, vYend); LineV = new LineSegment(pointStartV, pointEndV); Line pathV = new Line(); pathV.X1 = viewPortArea.XNormalize(vXstart, IntersectionPointControl.viewPortCanvas.Width); pathV.Y1 = viewPortArea.YNormalize(vYstart, IntersectionPointControl.viewPortCanvas.Height); pathV.X2 = viewPortArea.XNormalize(vXend, IntersectionPointControl.viewPortCanvas.Width); pathV.Y2 = viewPortArea.YNormalize(vYend, IntersectionPointControl.viewPortCanvas.Height); pathV.Stroke = Brushes.Red; pathV.StrokeThickness = 2; IntersectionPointControl.viewPortCanvas.Children.Add(pathV); // Intersection Point IntersectionPoint = new IntersectionPoint(lineT, lineV); if (IntersectionPoint.Intersection) { IntersectionPointControl.lblIntersection.Text = "Intersection? true!"; } else { IntersectionPointControl.lblIntersection.Text = "Intersection? false!"; } IntersectionPointControl.lblPointX.Text = "X: " + Math.Round(IntersectionPoint.PointOfIntersection.X, 2).ToString(); IntersectionPointControl.lblPointY.Text = "Y: " + Math.Round(IntersectionPoint.PointOfIntersection.Y, 2).ToString(); IntersectionPointControl.lblTb.Text = "Tb: " + Math.Round(IntersectionPoint.LineT.B, 2).ToString(); IntersectionPointControl.lblTm.Text = "Tm: " + Math.Round(IntersectionPoint.LineT.M, 2).ToString(); IntersectionPointControl.lblVb.Text = "Vb: " + Math.Round(IntersectionPoint.LineV.B, 2).ToString(); IntersectionPointControl.lblVm.Text = "Vm: " + Math.Round(IntersectionPoint.LineV.M, 2).ToString(); Ellipse circleAtPoint = new Ellipse(); circleAtPoint.Fill = new SolidColorBrush(Color.FromRgb(50, 50, 50)); circleAtPoint.Stroke = Brushes.Red; circleAtPoint.StrokeThickness = 2; circleAtPoint.Width = 10; circleAtPoint.Height = 10; Canvas.SetLeft(circleAtPoint, (viewPortArea.XNormalize(IntersectionPoint.PointOfIntersection.X, IntersectionPointControl.viewPortCanvas.Width) - 5)); Canvas.SetTop(circleAtPoint, (viewPortArea.YNormalize(IntersectionPoint.PointOfIntersection.Y, IntersectionPointControl.viewPortCanvas.Height) - 5)); IntersectionPointControl.viewPortCanvas.Children.Add(circleAtPoint); }
private void UpdateGraphics() { // Line T tXstart = Convert.ToDouble(txtTXstart.Text); tYstart = Convert.ToDouble(txtTYstart.Text); tXend = Convert.ToDouble(txtTXend.Text); tYend = Convert.ToDouble(txtTYend.Text); // Line V vXstart = Convert.ToDouble(txtVXstart.Text); vYstart = Convert.ToDouble(txtVYstart.Text); vXend = Convert.ToDouble(txtVXend.Text); vYend = Convert.ToDouble(txtVYend.Text); viewPortCanvas.Children.Remove(pathT); pathT = new Line(); pathT.X1 = viewPortArea.XNormalize(tXstart, viewPortCanvas.Width); pathT.Y1 = viewPortArea.YNormalize(tYstart, viewPortCanvas.Height); pathT.X2 = viewPortArea.XNormalize(tXend, viewPortCanvas.Width); pathT.Y2 = viewPortArea.YNormalize(tYend, viewPortCanvas.Height); pathT.Stroke = Brushes.Blue; pathT.StrokeThickness = 2; viewPortCanvas.Children.Add(pathT); viewPortCanvas.Children.Remove(pathV); pathV = new Line(); pathV.X1 = viewPortArea.XNormalize(vXstart, viewPortCanvas.Width); pathV.Y1 = viewPortArea.YNormalize(vYstart, viewPortCanvas.Height); pathV.X2 = viewPortArea.XNormalize(vXend, viewPortCanvas.Width); pathV.Y2 = viewPortArea.YNormalize(vYend, viewPortCanvas.Height); pathV.Stroke = Brushes.Red; pathV.StrokeThickness = 2; viewPortCanvas.Children.Add(pathV); // Line T PointXY pointStartT = new PointXY(tXstart, tYstart); PointXY pointEndT = new PointXY(tXend, tYend); LineSegment lineT = new LineSegment(pointStartT, pointEndT); // Line V PointXY pointStartV = new PointXY(vXstart, vYstart); PointXY pointEndV = new PointXY(vXend, vYend); LineSegment lineV = new LineSegment(pointStartV, pointEndV); // Intersection Point intersectionPoint = new IntersectionPoint(lineT, lineV); if (intersectionPoint.Intersection) { lblIntersection.Text = "Intersection? true!"; } else { lblIntersection.Text = "Intersection? false!"; } txtPointX.Text = intersectionPoint.PointOfIntersection.X.ToString(); txtPointY.Text = intersectionPoint.PointOfIntersection.Y.ToString(); txtTb.Text = intersectionPoint.LineT.B.ToString(); txtTm.Text = intersectionPoint.LineT.M.ToString(); txtVb.Text = intersectionPoint.LineV.B.ToString(); txtVm.Text = intersectionPoint.LineV.M.ToString(); viewPortCanvas.Children.Remove(circleAtPoint); circleAtPoint = new Ellipse(); circleAtPoint.Fill = new SolidColorBrush(Color.FromRgb(50, 50, 50)); circleAtPoint.Stroke = Brushes.Red; circleAtPoint.StrokeThickness = 2; circleAtPoint.Width = 10; circleAtPoint.Height = 10; Canvas.SetLeft(circleAtPoint, (viewPortArea.XNormalize(intersectionPoint.PointOfIntersection.X, viewPortCanvas.Width) - 5)); Canvas.SetTop(circleAtPoint, (viewPortArea.YNormalize(intersectionPoint.PointOfIntersection.Y, viewPortCanvas.Height) - 5)); viewPortCanvas.Children.Add(circleAtPoint); }