i want create quad tree doesn't work correctly. rectangle , divide until width , height greater 1 . doesn't divide correctly. can me? thanks. here code.
public class quadtree { public treenode mainroot; bool switch=false; public quadtree(rectangle r) { mainroot = new treenode(); mainroot.rectangle = r; mainroot.leftchild = null; mainroot.rightchild = null; } public void createtree(treenode root, rectangle r) { if (root.rectangle.width<=1 || root.rectangle.height <=1) { return; } root.leftchild = new treenode(); root.rightchild = new treenode(); if (!switch) { root.leftchild.rectangle = new rectangle(r.x, r.y, r.width / 2, r.height); root.rightchild.rectangle = new rectangle(r.x + r.width / 2, r.y, r.width/2, r.height); } if (switch) { root.leftchild.rectangle = new rectangle(r.x, r.y, r.width, r.height / 2); root.rightchild.rectangle = new rectangle(r.x, r.y - r.height / 2, r.width, r.height / 2); } switch = !switch; createtree(root.leftchild, root.leftchild.rectangle); createtree(root.rightchild, root.rightchild.rectangle); }
}
Comments
Post a Comment