我正在尝试使用 QuadTree 代码来开发八叉树代码。但是,在将 Rectangle3d 更改为 Box 时,我被卡住了。基本上我有一个分割节点的功能,在分割矩形时,我使用宽度和高度并将它们分割,然后使用构造函数 - Rectangle3d(Plane, Double, Double) 但我不知道要使用哪个构造函数以及如何使用当我从 Rectangle3d 更改为 Box 时计算它。谁能帮我这个?
public static Octree oct;
public static DataTree < Point3d > psOUT;
public static List<Line> lns = new List<Line>();
//////////Octree////////
public class Octree
{
public int MAX_OBJECTS = 10;
public int MAX_LEVELS = 8;
private int level;
private List<Point3d>objects;
private Box bounds;
private Octree[] nodes;
/*
* Constructor
*/
public Octree(int pLevel, Box pBounds)
{
level = pLevel;
objects = new List<Point3d>();
bounds = pBounds;
nodes = new Octree[8];
}
// implement the five methods of a Octree: clear, split, getIndex, insert, and retrieve.
/*
* Clears the Octree
*/
public void clear()
{
objects.Clear();
for (int i = 0; i < nodes.Length; i++)
{
if (nodes[i] != null)
{
nodes[i].clear();
nodes[i] = null;
}
}
}
/*
* Splits the node into 8 subnodes
*/
private void split()
{
double subWidth = bounds.X * 0.5;
double subDepth = bounds.Y * 0.5;
double subHeight = bounds.Z *0.5;
double x = bounds.X.T0;
double y = bounds.Y.T0;
double z = bounds.Z.T0;
nodes[3] = new Quadtree(level + 1, new Box(Plane.WorldXY, new Point3d(x + subWidth, y, 0), new Point3d(x + 2 * subWidth, y + subHeight, 0)));
nodes[2] = new Quadtree(level + 1, new Box(Plane.WorldXY, new Point3d(x, y, 0), new Point3d(x + subWidth, y + subHeight, 0)));
nodes[1] = new Quadtree(level + 1, new Box(Plane.WorldXY, new Point3d(x, y + subHeight, 0), new Point3d(x + subWidth, y + 2 * subHeight, 0)));
nodes[0] = new Quadtree(level + 1, new Box(Plane.WorldXY, new Point3d(x + subWidth, y + subHeight, 0), new Point3d(x + 2 * subWidth, y + 2 * subHeight, 0)));
}