# Quadtree
This is a Java implementation of Quadtree, a tree data structure useful to store 2D positional data.
# Usage
## Creating new Quad tree
initialize the world with a 400 by 400 dimension starting at point (0,0)
```java
//init.
Dimension dimension = new Dimension(400, 400);
Position2D position = new Position2D(0, 0);
QuadTree<Point> KD = new QuadTree<Point>(position, dimension);
//populate with random points.
Random random = new Random();
List<Point> pointList = new LinkedList<>();
for (int i = 0; i < 500; i++) {
Point point = new Point(
random.nextInt((int) (dimension.getWidth()+1)),
random.nextInt((int) (dimension.getHeight()+1)));
//insert in the QuadTree
KD.insert(point);
}
```
## Query points from QuadTree
You can query points from the tree using a `Boundary` object. Use the default `Rectangle` or create one yourself just by implementing the `Boundary` interface and overriding the `contains(Point2D point)` methode.
Default query using the rectangle class.
```java
//init.
Dimension dimension = new Dimension(400, 400);
Position2D position = new Position2D(0, 0);
QuadTree<Point> KD = new QuadTree<Point>(position, dimension);
...
Rectangle rect = new Rectangle(new Dimension(200,100), new Position2D(100,100));
//query the result is a list of all points within the rectangle.
KD.query(rect);
}
```
## Debug
There is also a drawing tool for the QuadTree.
```java
//Create new visual window for the quadtree.
//PointsList = list of all points in the tree.
//seletecPoints = selected Points from the query.
//rect = rectangle boundary.
//KD = the QuadTree.
//dimension = the dimension of the screen/ world space
new Window(pointList, seletecPoints, rect, KD,dimension);
}
```
没有合适的资源?快使用搜索试试~ 我知道了~
Quadtree:Java中的四叉树实现
共16个文件
java:11个
xml:2个
name:1个
需积分: 38 8 下载量 136 浏览量
2021-05-11
12:11:20
上传
评论
收藏 14KB ZIP 举报
温馨提示
四叉树 这是Quadtree的Java实现,Quadtree是一种树数据结构,可用于存储2D位置数据。 用法 创建新的四叉树 从点(0,0)开始以400 x 400尺寸初始化世界 // init. Dimension dimension = new Dimension ( 400 , 400 ); Position2D position = new Position2D ( 0 , 0 ); QuadTree< Point> KD = new QuadTree< Point> (position, dimension); // populate with random points. Random random = new Random (); List< Point> pointList = new LinkedList<> (); for ( int i = 0 ;
资源详情
资源评论
资源推荐
收起资源包目录
Quadtree-master.zip (16个子文件)
Quadtree-master
.gitignore 2KB
src
src
drawer
ShapeDrawer.java 1KB
Window.java 1KB
quattree
QuadTree.java 5KB
Vector2D.java 529B
Position2D.java 969B
Rectangle.java 834B
Point2D.java 639B
Boundary.java 390B
Dimension.java 2KB
Point.java 1KB
Main.java 882B
.idea
misc.xml 271B
workspace.xml 20KB
.name 8B
README.md 2KB
共 16 条
- 1
狛绝的追随者
- 粉丝: 23
- 资源: 4611
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0