Vector3 generateTarget() { // generate according to the robot's position //Vector3 robotDis = rbtObj.transform.position - _table.transform.position; Vector3 mir = 2 * _table.transform.position - rbtObj.transform.position; float tableSize = 1f; // generate two points for bezier generation and // algorithms3 float deltax = Random.Range(Mathf.Max(-20f + _table.transform.position.x * 100f, -15 + mir.x * 100f), Mathf.Min(20f + _table.transform.position.x * 100f, 15 + mir.x * 100f)) / 100.0f; float deltaz = Random.Range(Mathf.Max(-20f + _table.transform.position.z * 100f, -15 + mir.z * 100f), Mathf.Min(20f + _table.transform.position.z * 100f, 15 + mir.z * 100f)) / 100.0f; print("dx:\t" + deltax + "\tdy:\t" + deltaz + "\trbt:\t" + rbtObj.transform.position + "\ttbl:\t" + _table.transform.position); while (Vector3.Distance(rbtObj.transform.position, new Vector3(deltax, rbtObj.transform.position.y, deltaz)) < 0.2f) { print("redo"); deltax = Random.Range(-20, 20) / 100.0f + _table.transform.position.x; deltaz = Random.Range(-20, 20) / 100.0f + _table.transform.position.z; } deltax = Mathf.Min(_table.transform.position.x + 0.2f, deltax); deltax = Mathf.Max(_table.transform.position.x - 0.2f, deltax); deltaz = Mathf.Min(_table.transform.position.z + 0.2f, deltaz); deltaz = Mathf.Max(_table.transform.position.z - 0.2f, deltaz); Vector3 des = new Vector3(deltax * tableSize, _table.transform.position.y, deltaz * tableSize); // + _table.transform.position; print("des:\t" + des.ToString("F3")); //ONLY FOR TEST if (_DEBUG) { des = _table.transform.position; } // try two way animation that it goes to some floating place first and then get on the table Vector3 desForRbt = des; des.y += (transform.position.y - _table.transform.position.y) / 3f; // another two points float disx = Random.Range(1, 3) * (Random.Range(0, 1) * 2 - 1); float disy = Random.Range(1, 3) * (Random.Range(0, 1) * 2 - 1); Vector3 p2 = (transform.position + des) / 2 + new Vector3(disx, disy, 0); Vector3 p3 = (transform.position + des) / 2 - new Vector3(disx, disy, 0); // generate bezier path _path = new bezier(transform.position, p2, p3, des); // generate the first destination moveDestination = _path.getPoint(0.0f); // reset the speed speed = 0.05f; return(desForRbt); }
private void silum(object sender, RoutedEventArgs e) { canvas.Children.Clear(); double sun = 0; try { //sun = double.Parse(silumto.Text); if (sun > 1) { canvas.Width *= sun; canvas.Height *= sun; } } catch (Exception) { return; } string path = str; using (StreamReader sr = File.OpenText(path)) { double x1 = 0, x2 = 0, y1 = 0, y2 = 0; string s = ""; char[] outline = { '(', ',', ')' }; while ((s = sr.ReadLine()) != null) { if (s.IndexOf("#") > -1) { switch (s) { case "#Lines": while ((s = sr.ReadLine()) != null && s != "" && s.Length > 2) { string[] arr = s.Split(outline); arr = func(arr); x1 = int.Parse(arr[0]) * sun; y1 = int.Parse(arr[1]) * sun; x2 = int.Parse(arr[2]) * sun; y2 = int.Parse(arr[3]) * sun; x1 *= scale; y1 *= scale; x2 *= scale; y2 *= scale; Line l = new Line(); l.X1 = x1; l.Y1 = y1; l.X2 = x2; l.Y2 = y2; l.StrokeThickness = 4; l.Stroke = System.Windows.Media.Brushes.LightSteelBlue; canvas.Children.Add(l); } break; case "#Circles": while ((s = sr.ReadLine()) != null && s != "" && s.Length > 2) { string[] arr = s.Split(outline); arr = func(arr); x1 = int.Parse(arr[0]) * sun; y1 = int.Parse(arr[1]) * sun; //x2 = int.Parse(arr[2]); y2 = int.Parse(arr[3]) * sun; // RADIUS x1 *= scale; y1 *= scale; y2 *= scale; Ellipse ell = new Ellipse(); ell.Width = 2 * y2; ell.Height = 2 * y2; InkCanvas.SetTop(ell, y1 - y2); InkCanvas.SetLeft(ell, x1 - y2); ell.StrokeThickness = 4; ell.Fill = System.Windows.Media.Brushes.Transparent; ell.Stroke = System.Windows.Media.Brushes.LightSteelBlue; canvas.Children.Add(ell); } break; case "#Cruves": while ((s = sr.ReadLine()) != null && s != "" && s.Length > 2) { string[] arr = s.Split(outline); arr = func(arr); Point p1 = new Point((int.Parse(arr[0]) * sun) * scale, (int.Parse(arr[1]) * sun) * scale); Point p2 = new Point((int.Parse(arr[2]) * sun) * scale, (int.Parse(arr[3]) * sun) * scale); Point p3 = new Point((int.Parse(arr[4]) * sun) * scale, (int.Parse(arr[5]) * sun) * scale); Point p4 = new Point((int.Parse(arr[6]) * sun) * scale, (int.Parse(arr[7]) * sun) * scale); Point[] points = new[] { p1, p2, p3, p4 }; bezier bz = new bezier(); var Bezier_btb = bz.CreatebezierLinepoly(points, 500); PathFigure pathDiscriptionFigure = new PathFigure(Bezier_btb.Points[0], new[] { Bezier_btb }, false); PathFigureCollection pathColletion_ = new PathFigureCollection(); pathColletion_.Add(pathDiscriptionFigure); var GeomtricPath = new PathGeometry(); GeomtricPath.Figures = pathColletion_; System.Windows.Shapes.Path Path_Shapepattern = new System.Windows.Shapes.Path(); Path_Shapepattern.Data = GeomtricPath; Path_Shapepattern.Stroke = new SolidColorBrush(Color.FromRgb(255, 0, 0)); canvas.Children.Add(Path_Shapepattern); } break; } } } } }
private void preview_mouseup(object sender, MouseButtonEventArgs e) { if (gameclick % 2 == 0) { try { if (shapeFlag < 3) { if (gameclick % 2 == 0) { par[1] = Mouse.GetPosition(canvas); } } else { } switch (shapeFlag) { case 1: Ellipse ell = new Ellipse(); if (par[0].X < par[1].X) { ell.Width = par[1].X - par[0].X; ell.Height = par[1].Y - par[0].Y; InkCanvas.SetTop(ell, par[0].Y); InkCanvas.SetLeft(ell, par[0].X); } else { ell.Width = par[0].X - par[1].X; ell.Height = par[0].Y - par[1].Y; InkCanvas.SetTop(ell, par[1].Y); InkCanvas.SetLeft(ell, par[1].X); } ell.StrokeThickness = 4; ell.Fill = System.Windows.Media.Brushes.Transparent; ell.Stroke = System.Windows.Media.Brushes.LightSteelBlue; canvas.Children.Add(ell); break; case 2: Line l = new Line(); l.X1 = par[0].X; l.Y1 = par[0].Y; l.X2 = par[1].X; l.Y2 = par[1].Y; l.StrokeThickness = 4; l.Stroke = System.Windows.Media.Brushes.LightSteelBlue; canvas.Children.Add(l); break; case 3: if (i == 4) { Point[] points = new[] { par[0], par[1], par[2], par[3] }; bezier bz = new bezier(); var Bezier_btb = bz.CreatebezierLinepoly(points, 256); PathFigure pathDiscriptionFigure = new PathFigure(Bezier_btb.Points[0], new[] { Bezier_btb }, false); PathFigureCollection pathColletion_ = new PathFigureCollection(); pathColletion_.Add(pathDiscriptionFigure); var GeomtricPath = new PathGeometry(); GeomtricPath.Figures = pathColletion_; System.Windows.Shapes.Path Path_Shapepattern = new System.Windows.Shapes.Path(); Path_Shapepattern.Data = GeomtricPath; Path_Shapepattern.Stroke = new SolidColorBrush(Color.FromRgb(255, 0, 0)); curve_list.Add(Path_Shapepattern); canvas.Children.Add(Path_Shapepattern); } break; } }catch (Exception) { return; } } }