Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
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)
 
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

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
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

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.
48  {
49  Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
50  Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
51  foreach(Vector3 pt in points)
52  {
53  if (pt.X < min.X) min.X = pt.X;
54  if (pt.Y < min.Y) min.Y = pt.Y;
55  if (pt.Z < min.Z) min.Z = pt.Z;
56 
57  if (pt.X > max.X) max.X = pt.X;
58  if (pt.Y > max.Y) max.Y = pt.Y;
59  if (pt.Z > max.Z) max.Z = pt.Z;
60  }
61  return new AxisAlignedBox((Vector3d)min, (Vector3d)max);
62  }
AxisAlignedBox(AxisAlignedBox aab)
Definition: AxisAlignedBox.cs:23
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.
70  {
71  Vector3d min = new Vector3d(double.MaxValue, double.MaxValue, double.MaxValue);
72  Vector3d max = new Vector3d(double.MinValue, double.MinValue, double.MinValue);
73  foreach(Vector3d pt in points)
74  {
75  if (pt.X < min.X) min.X = pt.X;
76  if (pt.Y < min.Y) min.Y = pt.Y;
77  if (pt.Z < min.Z) min.Z = pt.Z;
78 
79  if (pt.X > max.X) max.X = pt.X;
80  if (pt.Y > max.Y) max.Y = pt.Y;
81  if (pt.Z > max.Z) max.Z = pt.Z;
82  }
83  return new AxisAlignedBox(min, max);
84  }
AxisAlignedBox(AxisAlignedBox aab)
Definition: AxisAlignedBox.cs:23
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.

129  {
130  const int RIGHT = 0;
131  const int LEFT = 1;
132  const int MIDDLE = 2;
133 
134  double* candidatePlane = stackalloc double[3];
135  byte* quadrant = stackalloc byte[3];
136  bool inside = true;
137  distance = 0f;
138 
139  for (int i = 0; i < 3; i++)
140  {
141  if (ray.Point[i] < this.Min[i])
142  {
143  quadrant[i] = LEFT;
144  candidatePlane[i] = this.Min[i];
145  inside = false;
146  }
147  else if (ray.Point[i] > this.Max[i])
148  {
149  quadrant[i] = RIGHT;
150  candidatePlane[i] = this.Max[i];
151  inside = false;
152  }
153  else
154  {
155  quadrant[i] = MIDDLE;
156  }
157  }
158 
159  if (inside)
160  {
161  return false;
162  }
163 
164  double* maxT = stackalloc double[3];
165  var direction = ray.Direction;
166  for (int i = 0; i < 3; i++)
167  {
168  if (quadrant[i] != MIDDLE && direction[i] != 0)
169  {
170  maxT[i] = (candidatePlane[i] - ray.Point[i])/direction[i];
171  }
172  else
173  {
174  maxT[i] = -1;
175  }
176  }
177 
178  int whichPlane = 0;
179  for (int i = 1; i < 3; i++)
180  {
181  if (maxT[whichPlane] < maxT[i])
182  {
183  whichPlane = i;
184  }
185  }
186 
187  if (maxT[whichPlane] < 0f)
188  {
189  return false;
190  }
191 
192  double* coord = stackalloc double[3];
193  for (int i = 0; i < 3; i++)
194  {
195  if (whichPlane != i)
196  {
197  coord[i] = ray.Point[i] + maxT[i] * direction[i];
198  if ((quadrant[i] == RIGHT && coord[i] < this.Min[i]) ||
199  (quadrant[i] == LEFT && coord[i] > this.Max[i]))
200  {
201  return false;
202  }
203  }
204  else
205  {
206  coord[i] = candidatePlane[i];
207  }
208  }
209 
210  distance = maxT[whichPlane];
211  return true;
212 
213  }
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
bool pluginbase.Helpers.Geometry.AxisAlignedBox.PointIn ( Vector3d  pt)
36  {
37  return pt.X > Min.X && pt.X < Max.X
38  && pt.Y > Min.Y && pt.Y < Max.Y
39  && pt.Z > Min.Z && pt.Z < Max.Z;
40  }
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
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.
92  {
93  return new AxisAlignedBox(
94  Vector3d.Transform(box.Min, mat),
95  Vector3d.Transform(box.Max, mat)
96  );
97  }
AxisAlignedBox(AxisAlignedBox aab)
Definition: AxisAlignedBox.cs:23
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.
105  {
106  return new AxisAlignedBox(
107  (Vector3d)Vector3.Transform((Vector3)box.Min, mat),
108  (Vector3d)Vector3.Transform((Vector3)box.Max, mat)
109  );
110  }
AxisAlignedBox(AxisAlignedBox aab)
Definition: AxisAlignedBox.cs:23

Member Data Documentation

readonly Vector3d pluginbase.Helpers.Geometry.AxisAlignedBox.Max

The maximum point of the bounding box

readonly Vector3d pluginbase.Helpers.Geometry.AxisAlignedBox.Min

The minimum point of the bounding box

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

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: