dhart.spatialstructures.Graph.get_closest_nodes¶
- Graph.get_closest_nodes(p_desired, x=True, y=True, z=True)¶
Get the closet nodes to the input set of points
- Parameters:
p_desired (ndarray) – n x m shape where n is the number of points an m is equal to the axis set to True
x (bool, optional) – Include x axis in the distance comparison, Default True
y (bool, optional) – Include y axis in the distance comparison, Default True
z (bool, optional) – Include z axis in the distance comparison, Default True
- Returns:
int if a single point is passed, ndarray if multiple points are passed, where ndarray is size of number of points passed in p_desired
- Return type:
Warning
Size of points in p_desired must be same as the number of x,y,z axis set to True
Note
In future this should be calling a method in C interface instead of implemented in Python
Examples
>>> import numpy as np
>>> import dhart >>> from dhart.geometry import LoadOBJ >>> from dhart.graphgenerator import GenerateGraph >>> from dhart.raytracer import EmbreeBVH
>>> # Load BVH >>> obj_path = dhart.get_sample_model("energy_blob_zup.obj") >>> loaded_obj = LoadOBJ(obj_path) >>> embree_bvh = EmbreeBVH(loaded_obj)
>>> # Set graph parameters >>> start_point, spacing, max_nodes = (-30, 0, 20), (1, 1, 10), 100000
>>> # Generate the graph >>> graph = GenerateGraph(embree_bvh, start_point, spacing, max_nodes)
Check closest nodes using single x,y point
>>> closest_node = graph.get_closest_nodes(np.array([30,0]), z=False) >>> print("Closest Node: ", closest_node) Closest Node: 2421
Check closest nodes using multiple x,y points
>>> closest_node = graph.get_closest_nodes(np.array([[30,0],[20,20]]), z=False) >>> print("Closest Node: ", closest_node) Closest Node: [2421 2450]
Check closest nodes using single x,y,z point
>>> closest_node = graph.get_closest_nodes(np.array([30,0,0])) >>> print("Closest Node: ", closest_node) Closest Node: 2422
Check closest nodes using multiple x,y,z points
>>> closest_node = graph.get_closest_nodes(np.array([[30,0,0],[20,20,0]])) >>> print("Closest Node: ", closest_node) Closest Node: [2422 2450]