我正在尝试将四叉树代码更新为Octree

问题描述 投票:0回答:1

我正在尝试使用QuadTree代码来开发Octree代码。但是,在将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)));
 }
c# rhino grasshopper
1个回答
0
投票

也许晚了点,但是就到这里了:

考虑到您已经在3D空间中构建了Box。为了将其分成8个较小的框,可以使用每个角和框中心点之间的X,Y,Z坐标间隔。因此,您将遇到类似这样的内容:


private Split(Box box)
{
    List<Box> boxes = new List<Box>();
    foreach(Point3d corner in box.GetCorners())
    {
        CreateBoxFromPlaneAndTwoCorners(box.Plane, box.Center, corner);
    }
    return boxes;
}

private CreateBoxFromPlaneAndTwoCorners(Plane plane, Point3d cornerA, Point3d cornerB) {
    Interval intX = new Interval(cornerA.X,cornerB.X);
    Interval intY = new Interval(cornerA.Y,cornerB.Y);
    Interval intZ = new Interval(cornerA.Z,cornerB.Z);

    return new Box(plane,intX,intY,intZ);
}

我在不测试的情况下就编写了该anwser,因此您可能需要将box.Plane更改为Plane.WorldXY,因为我似乎记得始终将角坐标指定为通用坐标,而与用于计算盒子的平面无关。

© www.soinside.com 2019 - 2024. All rights reserved.