Class: KDTree3D

PD.Path. KDTree3D

A class that implements a KDTree for 3D nearest neighbor search.

This class is used to build a KDTree from a set of 3D points and perform nearest neighbor and bounding box searches. It is particularly useful for efficiently finding points that are close to a given point within a specified radius or within a given radius.


new KDTree3D(points)

Creates a new KDTree instance from an array of 3D points.

Parameters:
Name Type Description
points Array.<PD.Point>

The array of points to search through.

Author:
  • drajmarsh

Methods


buildTree(points, depth)

Recursively builds a 3D KD tree.

Parameters:
Name Type Description
points Array.<Object>

Array of points, each with {x, y, z}.

depth number

The current depth within the tree.

Returns:

A node representing part of the KD tree.

Type
Object | null

closestPoints(queryPoint, radius)

Finds all points within a given radius from the query point.

Parameters:
Name Type Description
queryPoint Object

The query point {x, y, z}.

radius number

The radius within which to search.

Returns:

Array of points within the given radius.

Type
Array.<Object>

nearest(queryPoint [, k])

Finds the k-nearest neighbors to the given query point.

Parameters:
Name Type Argument Default Description
queryPoint Object

The query point {x, y, z}.

k number <optional>
1

Number of nearest neighbors to return.

Returns:

Array of the k closest points.

Type
Array.<Object>

squaredDistance(a, b)

Computes the squared Euclidean distance between two 3D points.

Parameters:
Name Type Description
a Object

First point {x, y, z}.

b Object

Second point {x, y, z}.

Returns:

The squared distance.

Type
number

fromPath(path) <static>

Creates a new KDTree instance from path points in a given path.

Parameters:
Name Type Description
path Array.<BIM.Path>

The path to search through.

Returns:

Returns a new KDTree instance.

Type
KDTree

fromPaths(paths) <static>

Creates a new KDTree instance from points in the given paths.

Parameters:
Name Type Description
paths Array.<BIM.Path>

The list of paths to search through.

Returns:

Returns a new KDTree instance.

Type
KDTree