A point quadtree is a 4-way tree used to represent points on a plane (Samet 2006). A node contains a pair of coordinates (latitude,longitude) and pointers to four children that represent four quadrants: NW, NE, SW, and SE. These quadrants are generated by the intersection of the vertical and horizontal lines passing through point (lat,lon) of the plane. Write a program that accepts the names of cities and their geographical locations (lat,lon) and inserts them into the quadtree. Then, the program should give the names of all cities located within distance r from a location (lat,lon) or, alternatively, within distance r from a city C Figure 2 contains an example. Locations on the map in Figure 2a are inserted into the quadtree in Figure 2b in the order indicated by the encircled numbers shown next to the city names. For instance, when inserting Pittsburgh into the quadtree, we check in which direction it is with respect to the root. The root stores the coordinates of Louisville, and Pittsburgh is NE from it, that is, it belongs to the second child of the root. But this child already stores a city Washington. Therefore, we ask the same question concerning Pittsburgh with respect to the current node, the second child of the root: in which direction with respect to this city is Pittsburgh? This time the answer is NW. Therefore, we go to the first child of the current node The child is a null node, and therefore, the Pittsburgh node can be inserted here The problem is to not have do an exhaustive search of the quadtree. So, if we are after cities within a radius r from a city C, then, for a particular node nd you find the distance between C and the city represented by nd. If the distance is within r, you have to continue to all four descendants of nd. If not, you continue to the descendants indicated by the relative positions To measure a distance between cities with coordinates (lat1, lon1) and (lat2, lon2), the great circle distance formula can be used:s assuming that the earth radius R = 3,956 miles and latitudes and longitudes are expressed in radians (to convert decimal degrees to radians, multiply the number of degrees by TT/180 = 0.017453293 radians/degree). Also, for the directions west and south, negative angles should be used d = R arccos(sin(lat1 ) . sin(lat2) + cos(lat1 ) . cos(lat2) . cos(lon2-lon1 )) For example, to find cities within the distance of 200 miles from Pittsburgh, begin with the root and d((38,85)(40,79)) = 350, so Louisville does not qualify, but now you need to continue only in the SE and NE descendants of Louisville after comparing the coordinates of Louisville and Pittsburgh. Then you try Washington, which qualifies (d= 175), so, from Washington you go to Pittsburgh and then to both Pittsburgh\'s descendants. But when you get to the NE node from Washington, you see that New York does not qualify (d 264), and from New York you would have to continue in SW and NW descendants, but they are null, so you stop right there. Also, Atlanta needs to be checked
It decides that quadrant of the foundation node that the purpose ought to be in ( by checking the point\'s x and y against the horiontal center and vertical centers of the node\'s quad).
If there\'s a leaf node (let\'s decision it N) therein quadrant, it moves N\'s purpose into a toddler of N and adds the new purpose as a toddler of N also.
N is marked as a non-leaf as a result of it\'s kids.
By definition, a quadtree could be a tree during which every node has at the most four kids. Quadtree implementations — like D3\'s (source) — make sure that as points area unit further to the tree, nodes area unit rearranged such none of them have quite four kids.
Below area unit the graph of the quadtree and therefore the map of the points and rectangles it represents once more, side-by-side in order that you\'ll see however they relate to every different.
When a replacement purpose is inserted into a D3 quadtree:
It decides that quadrant of the foundation node that the purpose ought to be in ( by checking the point\'s x and y against the horiontal center and vertical centers of the node\'s quad).
If there\'s a leaf node (let\'s decision it N) therein quadrant, it moves N\'s purpose into a toddler of N and adds the new purpose as a toddler of N also.
N is marked as a non-leaf as a result of it\'s kids.
1. check out however the map correlates to the tree.
Click on Associate in Nursing parallelogram or purpose within the map read (below on the left). The tree read (below on the right) can pan to the corresponding node within the tree.
Zoom out and pan round the tree read to visualize the node in context.
2. check out however the tree correlates to the map.
Click on a tree node within the tree read. The map can highlight the realm or purpose that it represents.