Giter Club home page Giter Club logo

quadtreejs's Introduction

QuadTree

The QuadTree data structure is a hierarchical spatial partitioning method used to efficiently organize and query data in a two-dimensional space. It recursively divides space into quadrants, allowing for faster search and retrieval of points within a defined boundary.

Overview

This repository contains an implementation of a QuadTree in JavaScript, providing a structure for spatial partitioning and point insertion/retrieval within a given boundary.

Play with a QuadTree on p5js!

QuadTree Render

Features

  • Insertion: Efficiently add points into the QuadTree.
  • Querying: Retrieve points within a specified range.
  • Spatial Partitioning: Divide space into quadrants for optimized data organization.

Usage

To use the QuadTree in your JavaScript project:

  1. Initialization:
const boundary = new Rectangle(x, y, width, height);
const quadTree = new QuadTree(boundary, capacity);
  1. Insertion:
const point = new Point(x, y);
quadTree.insert(point);
  1. Querying:
const queryBoundary = new Rectangle(x, y, width, height);
const pointsInRange = quadTree.queryRange(queryBoundary);

Example

// Initialize a boundary and QuadTree
const boundary = new Boundary(0, 0, 500, 500);
const quadTree = new QuadTree(boundary, 4);

// Insert points into the QuadTree
const points = [
  new Point(100, 100),
  new Point(200, 200),
  // ...more points
];
quadTree.insertPoints(points);

// Query points within a range
const queryBoundary = new Rectangle(50, 50, 100, 100);
const pointsInRange = quadTree.queryRange(queryBoundary);

quadtreejs's People

Contributors

awakenedhaki avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.