Ejemplo n.º 1
0
        public List <Vector3> RadiusSearch(Vector3 center, float radius)
        {
            List <Vector3> neighbours = new List <Vector3>();

            root.RadiusSearchRec(center, radius * radius, ref neighbours, 0);
            return(neighbours);
        }
Ejemplo n.º 2
0
        public void RadiusSearchRec(Vector3 center, float radiusSquared, ref List <Vector3> neighbours, int axis)
        {
            float dist = Vector3.SqrMagnitude(center - position);

            if (dist < radiusSquared)
            {
                neighbours.Add(position);
            }
            float diff = (position[axis] - center[axis]);

            axis = (axis + 1) % 3;
            bool searchLeft  = diff * diff * Mathf.Sign(diff) > -radiusSquared / 4;
            bool searchRight = diff * diff * Mathf.Sign(diff) < radiusSquared / 4;

            if (searchLeft && left != null)
            {
                left.RadiusSearchRec(center, radiusSquared, ref neighbours, axis);
            }
            if (searchRight && right != null)
            {
                right.RadiusSearchRec(center, radiusSquared, ref neighbours, axis);
            }
        }