Empeld
Empeld plugin documentation.
pluginbase.Helpers.Geometry.AxisAlignedBox Struct Reference

Represents an axis-aligned bounding box More...

Inheritance diagram for pluginbase.Helpers.Geometry.AxisAlignedBox:
pluginbase.Helpers.Geometry.IIntersectable

Public Member Functions

 AxisAlignedBox (AxisAlignedBox aab)
 
 AxisAlignedBox (Vector3d a, Vector3d b)
 
AxisAlignedBox Merge (AxisAlignedBox other)
 
bool PointIn (Vector3d pt)
 
unsafe bool Intersects (Ray ray, out double distance)
 

Static Public Member Functions

static AxisAlignedBox FromPointCloud (IEnumerable< Vector3 > points)
 Gets the AABB from a set of points in a cloud More...
 
static AxisAlignedBox FromPointCloud (IEnumerable< Vector3d > points)
 Gets the AABB from a set of points in a cloud More...
 
static AxisAlignedBox Transform (AxisAlignedBox box, Matrix4d mat)
 Transform an AABB by a matrix and return that new value More...
 
static AxisAlignedBox Transform (AxisAlignedBox box, Matrix4 mat)
 Transforms an AABB by a matrix and returns that value More...
 

Public Attributes

readonly Vector3d Min
 The minimum point of the bounding box More...
 
readonly Vector3d Max
 The maximum point of the bounding box More...
 

Static Public Attributes

static readonly AxisAlignedBox Zero = new AxisAlignedBox(Vector3d.Zero, Vector3d.Zero)
 A zero-sized bounding box More...
 
static readonly AxisAlignedBox UnitBox = new AxisAlignedBox(-Vector3d.One * 0.5, Vector3d.One * 0.5)
 The unit box from -0.5 to 0.5 More...
 

Detailed Description

Represents an axis-aligned bounding box

Constructor & Destructor Documentation

◆ AxisAlignedBox() [1/2]

pluginbase.Helpers.Geometry.AxisAlignedBox.AxisAlignedBox ( AxisAlignedBox  aab)
24  {
25  Min = aab.Min;
26  Max = aab.Max;
27  }
readonly Vector3d Min
The minimum point of the bounding box
Definition: AxisAlignedBox.cs:16
readonly Vector3d Max
The maximum point of the bounding box
Definition: AxisAlignedBox.cs:21

◆ AxisAlignedBox() [2/2]

pluginbase.Helpers.Geometry.AxisAlignedBox.AxisAlignedBox ( Vector3d  a,
Vector3d  b 
)
30  {
31  Max = Vector3d.ComponentMax(a, b);
32  Min = Vector3d.ComponentMin(a, b);
33  }
readonly Vector3d Min
The minimum point of the bounding box
Definition: AxisAlignedBox.cs:16
readonly Vector3d Max
The maximum point of the bounding box
Definition: AxisAlignedBox.cs:21

Member Function Documentation

◆ FromPointCloud() [1/2]

static AxisAlignedBox pluginbase.Helpers.Geometry.AxisAlignedBox.FromPointCloud ( IEnumerable< Vector3 >  points)
static

Gets the AABB from a set of points in a cloud

Returns
The point cloud.
Parameters
pointsPoints.
55  {
56  Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
57  Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
58  foreach(Vector3 pt in points)
59  {
60  if (pt.X < min.X) min.X = pt.X;
61  if (pt.Y < min.Y) min.Y = pt.Y;
62  if (pt.Z < min.Z) min.Z = pt.Z;
63 
64  if (pt.X > max.X) max.X = pt.X;
65  if (pt.Y > max.Y) max.Y = pt.Y;
66  if (pt.Z > max.Z) max.Z = pt.Z;
67  }
68  return new AxisAlignedBox((Vector3d)min, (Vector3d)max);
69  }
AxisAlignedBox(AxisAlignedBox aab)
Definition: AxisAlignedBox.cs:23

◆ FromPointCloud() [2/2]

static AxisAlignedBox pluginbase.Helpers.Geometry.AxisAlignedBox.FromPointCloud ( IEnumerable< Vector3d >  points)
static

Gets the AABB from a set of points in a cloud

Returns
The point cloud.
Parameters
pointsPoints.
77  {
78  Vector3d min = new Vector3d(double.MaxValue, double.MaxValue, double.MaxValue);
79  Vector3d max = new Vector3d(double.MinValue, double.MinValue, double.MinValue);
80  foreach(Vector3d pt in points)
81  {
82  if (pt.X < min.X) min.X = pt.X;
83  if (pt.Y < min.Y) min.Y = pt.Y;
84  if (pt.Z < min.Z) min.Z = pt.Z;
85 
86  if (pt.X > max.X) max.X = pt.X;
87  if (pt.Y > max.Y) max.Y = pt.Y;
88  if (pt.Z > max.Z) max.Z = pt.Z;
89  }
90  return new AxisAlignedBox(min, max);
91  }
AxisAlignedBox(AxisAlignedBox aab)
Definition: AxisAlignedBox.cs:23

◆ Intersects()

unsafe bool pluginbase.Helpers.Geometry.AxisAlignedBox.Intersects ( Ray  ray,
out double  distance 
)

Attribute: 3

;

Attribute: 3

;

Attribute: i] < this.Min[i

)

Attribute: i

= LEFT;

Attribute: i] = this.Min[i

;

Attribute: i] > this.Max[i

)

Attribute: i

= RIGHT;

Attribute: i] = this.Max[i

;

Attribute: i

= MIDDLE;

Attribute: 3

;

Attribute: i] != MIDDLE && direction[i

!= 0)

Attribute: i] = (candidatePlane[i] - ray.Point[i])/direction[i

;

Attribute: i

= -1;

Attribute: whichPlane] < maxT[i

)

Attribute: whichPlane

< 0f)

Attribute: 3

;

Attribute: i] = ray.Point[i] + maxT[i] * direction[i

;

Attribute: i] == RIGHT && coord[i] < this.Min[i

) ||

Attribute: i] == LEFT && coord[i] > this.Max[i

))

Attribute: i] = candidatePlane[i

;

Attribute: whichPlane

;

Implements pluginbase.Helpers.Geometry.IIntersectable.

136  {
137  const int RIGHT = 0;
138  const int LEFT = 1;
139  const int MIDDLE = 2;
140 
141  double* candidatePlane = stackalloc double[3];
142  byte* quadrant = stackalloc byte[3];
143  bool inside = true;
144  distance = 0f;
145 
146  for (int i = 0; i < 3; i++)
147  {
148  if (ray.Point[i] < this.Min[i])
149  {
150  quadrant[i] = LEFT;
151  candidatePlane[i] = this.Min[i];
152  inside = false;
153  }
154  else if (ray.Point[i] > this.Max[i])
155  {
156  quadrant[i] = RIGHT;
157  candidatePlane[i] = this.Max[i];
158  inside = false;
159  }
160  else
161  {
162  quadrant[i] = MIDDLE;
163  }
164  }
165 
166  if (inside)
167  {
168  return false;
169  }
170 
171  double* maxT = stackalloc double[3];
172  var direction = ray.Direction;
173  for (int i = 0; i < 3; i++)
174  {
175  if (quadrant[i] != MIDDLE && direction[i] != 0)
176  {
177  maxT[i] = (candidatePlane[i] - ray.Point[i])/direction[i];
178  }
179  else
180  {
181  maxT[i] = -1;
182  }
183  }
184 
185  int whichPlane = 0;
186  for (int i = 1; i < 3; i++)
187  {
188  if (maxT[whichPlane] < maxT[i])
189  {
190  whichPlane = i;
191  }
192  }
193 
194  if (maxT[whichPlane] < 0f)
195  {
196  return false;
197  }
198 
199  double* coord = stackalloc double[3];
200  for (int i = 0; i < 3; i++)
201  {
202  if (whichPlane != i)
203  {
204  coord[i] = ray.Point[i] + maxT[i] * direction[i];
205  if ((quadrant[i] == RIGHT && coord[i] < this.Min[i]) ||
206  (quadrant[i] == LEFT && coord[i] > this.Max[i]))
207  {
208  return false;
209  }
210  }
211  else
212  {
213  coord[i] = candidatePlane[i];
214  }
215  }
216 
217  distance = maxT[whichPlane];
218  return true;
219 
220  }
readonly Vector3d Min
The minimum point of the bounding box
Definition: AxisAlignedBox.cs:16
readonly Vector3d Max
The maximum point of the bounding box
Definition: AxisAlignedBox.cs:21

◆ Merge()

AxisAlignedBox pluginbase.Helpers.Geometry.AxisAlignedBox.Merge ( AxisAlignedBox  other)
36  {
37  return new AxisAlignedBox(
38  Vector3d.ComponentMin(this.Min, other.Min),
39  Vector3d.ComponentMax(this.Max, other.Max));
40  }
AxisAlignedBox(AxisAlignedBox aab)
Definition: AxisAlignedBox.cs:23
readonly Vector3d Max
The maximum point of the bounding box
Definition: AxisAlignedBox.cs:21

◆ PointIn()

bool pluginbase.Helpers.Geometry.AxisAlignedBox.PointIn ( Vector3d  pt)
43  {
44  return pt.X > Min.X && pt.X < Max.X
45  && pt.Y > Min.Y && pt.Y < Max.Y
46  && pt.Z > Min.Z && pt.Z < Max.Z;
47  }
readonly Vector3d Min
The minimum point of the bounding box
Definition: AxisAlignedBox.cs:16
readonly Vector3d Max
The maximum point of the bounding box
Definition: AxisAlignedBox.cs:21

◆ Transform() [1/2]

static AxisAlignedBox pluginbase.Helpers.Geometry.AxisAlignedBox.Transform ( AxisAlignedBox  box,
Matrix4d  mat 
)
static

Transform an AABB by a matrix and return that new value

Parameters
boxBox.
matMat.
99  {
100  return new AxisAlignedBox(
101  Vector3d.Transform(box.Min, mat),
102  Vector3d.Transform(box.Max, mat)
103  );
104  }
AxisAlignedBox(AxisAlignedBox aab)
Definition: AxisAlignedBox.cs:23

◆ Transform() [2/2]

static AxisAlignedBox pluginbase.Helpers.Geometry.AxisAlignedBox.Transform ( AxisAlignedBox  box,
Matrix4  mat 
)
static

Transforms an AABB by a matrix and returns that value

Parameters
boxBox.
matMat.
112  {
113  return new AxisAlignedBox(
114  (Vector3d)Vector3.TransformPosition((Vector3)box.Min, mat),
115  (Vector3d)Vector3.TransformPosition((Vector3)box.Max, mat)
116  );
117  }
AxisAlignedBox(AxisAlignedBox aab)
Definition: AxisAlignedBox.cs:23

Member Data Documentation

◆ Max

readonly Vector3d pluginbase.Helpers.Geometry.AxisAlignedBox.Max

The maximum point of the bounding box

◆ Min

readonly Vector3d pluginbase.Helpers.Geometry.AxisAlignedBox.Min

The minimum point of the bounding box

◆ UnitBox

readonly AxisAlignedBox pluginbase.Helpers.Geometry.AxisAlignedBox.UnitBox = new AxisAlignedBox(-Vector3d.One * 0.5, Vector3d.One * 0.5)
static

The unit box from -0.5 to 0.5

◆ Zero

readonly AxisAlignedBox pluginbase.Helpers.Geometry.AxisAlignedBox.Zero = new AxisAlignedBox(Vector3d.Zero, Vector3d.Zero)
static

A zero-sized bounding box


The documentation for this struct was generated from the following file: