Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data structure to hold list of rectangles?

I was wondering if there is a good data structure to hold a list of axis-aligned non overlapping discrete space rectangles. Thus each rectangle could be stored as the integers x, y, width, and height. It would be easy to just store such a list but I also want to be able to query if a given x,y coordinate is inside any other rectangle.

One easy solution would be to create a hash and fill it with the hashed lower left coordinates of the start of each rectangle. This would not allow me to test a given x,y coordinate because it would hit an empty space in the middle. Another answer is to create a bunch of edges into the hash table that cover the entire rectangle with unit squares. This would create too many needless entries for a rectangle of say 100 by 100.

like image 609
Michael Avatar asked Dec 17 '12 07:12

Michael


People also ask

What is rectangular data structure?

Rectangular data are multivariate cross-sectional data (i.e. not time-series or repeated measure) in which each column is a variable (feature), and each row is a case or record.

Which data structure is best for storing data?

Arrays. An array is the simplest and most widely used data structure. Other data structures like stacks and queues are derived from arrays.

What data structure does list use?

A list is an ordered data structure with elements separated by a comma and enclosed within square brackets. For example, list1 and list2 shown below contains a single type of data. Here, list1 has integers while list2 has strings. Lists can also store mixed data types as shown in the list3 here.

What is the best data structure type to store a list of numbers?

The number of items is extremely large. Dynamic linked list is a good solution.


1 Answers

R-Tree is the can be used. R-trees are tree data structures used for spatial access methods, i.e., for indexing multi-dimensional information such as geographical coordinates, rectangles or polygons. The information of all rectangles can be stored in tree form so searching will be easy

Wikipedia page, short ppt and the research paper will help you understand the concept. enter image description here

like image 96
Tejas Patil Avatar answered Sep 28 '22 18:09

Tejas Patil