|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap<Vector3D,V>
org.simtk.geometry3d.Hash3D<V>
public class Hash3D<V>
Container class to speed up finding objects that are near one another in 3D Cartesian space.
This data structure and algorithm can be used to answer the question "Find all pairs of objects withing 50 meters of one another" in linear time and space complexity, O(n), where n is the number of objects. The naive method takes O(n2) time. Linear time complexity can be achieved under the following circumstances:
1) There is an upper bound on the density of objects in the volume. (Collections of objects with arbitrarily high densities may tend to have O(n2) asymptotic *size* complexity for the *answer* to the question "How many pairs with distance less than X, and thus cannot have linear time complexity for producing that answer.)
2) Each object is located at a single distinct point in space. This works well for atoms and other spherically symmetric objects in Cartesian space.
This implementation does NOT require that the objects in the volume satisfy any minimum density criterion, unlike some neighbor list methods in molecular simulation.
Only one object should be placed at each unique position. If another one is placed at the same location, the one that was there earlier will be gone. There may also be a problem with having the same object at multiple positions.
TODO - modify data structure to remove these restrictions.
Set the size parameter in the constructor a bit lower than the distances you intend to query.
A size parameter, s, much larger than the test distance will tend to slow the method by a factor of O(s3).
A size parameter, s, much smaller than the test distance will tend to slow the method by a factor of O((1/s)3 * ln(1/s)). This effect will kick in more slowly than the "s too big" effect.
Constructor Summary | |
---|---|
Hash3D(double r)
|
Method Summary | |
---|---|
void |
clear()
|
java.lang.Object |
clone()
|
V |
getClosest(Vector3D position,
double radius)
Return the closest object to a particular position If no object is within the specified radius, return null. |
java.util.Collection<Vector3D> |
neighborKeys(Vector3D position,
double radius)
Find positions of all objects within a specified radius of a specified point. |
java.util.Collection<V> |
neighborValues(Vector3D position,
double radius)
Find all objects within a specified radius of a specified point This method has constant asymptotic time complexity. |
V |
put(Vector3D position,
V object)
Inserts an object into the data structure at a particular position. |
java.lang.Object |
remove(Vector3D vec)
Remove the object at a particular position |
Methods inherited from class java.util.HashMap |
---|
containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, remove, size, values |
Methods inherited from class java.util.AbstractMap |
---|
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Constructor Detail |
---|
public Hash3D(double r)
Method Detail |
---|
public V put(Vector3D position, V object)
put
in interface java.util.Map<Vector3D,V>
put
in class java.util.HashMap<Vector3D,V>
position
- object
-
public java.lang.Object remove(Vector3D vec)
vec
- the position of the object to removepublic void clear()
clear
in interface java.util.Map<Vector3D,V>
clear
in class java.util.HashMap<Vector3D,V>
public java.lang.Object clone()
clone
in class java.util.HashMap<Vector3D,V>
public V getClosest(Vector3D position, double radius)
position
- radius
-
public java.util.Collection<V> neighborValues(Vector3D position, double radius)
position
- radius
-
public java.util.Collection<Vector3D> neighborKeys(Vector3D position, double radius)
position
- radius
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |