public static bool Overlap(TreeNode nd1, TreeNode nd2) { if (RRT.DistanceOf2PointsSquared(nd1.Position, nd2.Position) <= 4) { return(true); } return(false); }
public TreeEdge AddNeighbour(TreeNode neighbour) { foreach (TreeEdge node in adjacentEdges) { if (node.Destination.GetID == this.index) { return(null); } } TreeEdge edge = new TreeEdge(this, neighbour, RRT.DistanceOf2PointsSquared(this.position, neighbour.position)); adjacentEdges.AddFirst(edge); return(edge); }
private void buttonDrawPath_Click(object sender, EventArgs e) { if (colorOrder < 4) { comboBoxAttempts.Enabled = false; Graphics g = this.CreateGraphics(); Pen myPen = new Pen(Brushes.LightGray, 2); RRT rrtStartNode = new RRT(5, validLocations, height, width, primaryPoint, secondaryPoint, Convert.ToInt32(comboBoxStepSize.SelectedItem)); RRT rrtEndNode = new RRT(0, validLocations, height, width, secondaryPoint, primaryPoint, Convert.ToInt32(comboBoxStepSize.SelectedItem)); DateTime dt = DateTime.Now; bool merged = rrtStartNode.MergeWith(rrtEndNode, Convert.ToInt32(comboBoxAttempts.SelectedItem), directPath); if (merged) { foreach (TreeEdge te in rrtStartNode.Edges) { myPen.Color = colorSet[colorOrder]; g.DrawLine(myPen, te.Source.Position, te.Destination.Position); } foreach (TreeNode tn in rrtStartNode.Nodes) { DrawPoint(g, tn.Position, 1, Pens.Green); } textBoxNodes.Text = rrtStartNode.Nodes.Count.ToString(); textBoxEdges.Text = rrtStartNode.Edges.Count.ToString(); textBoxTrueTime.Text = (DateTime.Now.Subtract(dt).TotalMilliseconds).ToString(); colorOrder++; labelToDo.Text = "Path found !"; } else { labelToDo.Text = "Path not found !!!"; } } else { labelToDo.Text = "Available colors used," + Environment.NewLine + "press the Clear button"; buttonDrawPath.Enabled = false; } }
public bool MergeWith(RRT destinationTree, int numberOfAttempts, bool directPath) { RRT tree1 = this; RRT tree2 = destinationTree; TreeNode newnode1 = tree2.root; for (int i = 0; i < numberOfAttempts; i++) { TreeNode rand = new TreeNode(TreeNode.RandomPoint(maxHeight, maxWidth, 1)); newnode1 = tree1.ExtendTreeRand(rand, 10, StepSize); if (newnode1 != null) { TreeNode newnode2 = tree2.ExtendTree(newnode1, 10, StepSize); if (newnode2 != null) { if (TreeNode.Overlap(newnode1, newnode2)) { foreach (TreeEdge edge in destinationTree.treeEdges) { this.treeEdges.AddFirst(edge); } foreach (TreeNode tn in destinationTree.treeNodes) { this.treeNodes.AddFirst(tn); } return(true); } } if (directPath) { RRT tmp = tree1; tree1 = tree2; tree2 = tmp; } } } return(false); }