https://mooseframework.inl.gov
Functions
geom_utils Namespace Reference

Functions

bool isPointZero (const libMesh::Point &pt)
 Check whether a point is equal to zero. More...
 
libMesh::Point unitVector (const libMesh::Point &pt, const std::string &name)
 Get the unit vector for a point parameter. More...
 
libMesh::Point rotatePointAboutAxis (const libMesh::Point &p, const libMesh::Real angle, const libMesh::Point &axis)
 Rotate point about an axis. More...
 
libMesh::Real minDistanceToPoints (const libMesh::Point &pt, const std::vector< libMesh::Point > &candidates, const unsigned int axis)
 Get the minimum distance from a point to another set of points, in the plane perpendicular to the specified axis. More...
 
std::vector< libMesh::PointpolygonCorners (const unsigned int num_sides, const libMesh::Real radius, const unsigned int axis)
 Get the corner coordinates of a regular 2-D polygon, assuming a face of the polygon is parallel to the x0 axis. More...
 
std::pair< unsigned int, unsigned intprojectedIndices (const unsigned int axis)
 Get the indices of the plane perpendicular to the specified axis. More...
 
libMesh::Point projectPoint (const libMesh::Real x0, const libMesh::Real x1, const unsigned int axis)
 Given two coordinates, construct a point in the 2-D plane perpendicular to the specified axis. More...
 
libMesh::Point projectedUnitNormal (libMesh::Point pt1, libMesh::Point pt2, const unsigned int axis)
 Get the unit normal vector between two points (which are first projected onto the plane perpendicular to the 'axis'), such that the cross product of the unit normal with the line from pt1 to pt2 has a positive 'axis' component. More...
 
libMesh::Real distanceFromLine (const libMesh::Point &pt, const libMesh::Point &line0, const libMesh::Point &line1)
 Compute the distance from a 3-D line, provided in terms of two points on the line. More...
 
libMesh::Real projectedDistanceFromLine (libMesh::Point pt, libMesh::Point line0, libMesh::Point line1, const unsigned int axis)
 Compute the distance from a 3-D line, provided in terms of two points on the line. More...
 
libMesh::Real projectedLineHalfSpace (libMesh::Point pt1, libMesh::Point pt2, libMesh::Point pt3, const unsigned int axis)
 If positive, point is on the positive side of the half space (and vice versa). More...
 
bool pointInPolygon (const libMesh::Point &point, const std::vector< libMesh::Point > &corners, const unsigned int axis)
 Whether a point is in 2-D a polygon in the plane perpendicular to the specified axis, given by corner points. More...
 
bool pointOnEdge (const libMesh::Point &point, const std::vector< libMesh::Point > &corners, const unsigned int axis)
 Whether a point is on the edge of a 2-D polygon in the plane perpendicular to the specified axis, given its corner points. More...
 
std::vector< libMesh::PointboxCorners (const libMesh::BoundingBox &box, const libMesh::Real factor)
 Get corner points of a bounding box, with side length re-scaled. More...
 
bool isPointZero (const Point &pt)
 
Point unitVector (const Point &pt, const std::string &name)
 
Real minDistanceToPoints (const Point &pt, const std::vector< Point > &candidates, const unsigned int axis)
 
Point projectPoint (const Real x0, const Real x1, const unsigned int axis)
 
Real projectedLineHalfSpace (Point pt1, Point pt2, Point pt3, const unsigned int axis)
 
bool pointInPolygon (const Point &point, const std::vector< Point > &corners, const unsigned int axis)
 
bool pointOnEdge (const Point &point, const std::vector< Point > &corners, const unsigned int axis)
 
Point projectedUnitNormal (Point pt1, Point pt2, const unsigned int axis)
 
Real distanceFromLine (const Point &pt, const Point &line0, const Point &line1)
 
Real projectedDistanceFromLine (Point pt, Point line0, Point line1, const unsigned int axis)
 
std::vector< Point > polygonCorners (const unsigned int num_sides, const Real radius, const unsigned int axis)
 
Point rotatePointAboutAxis (const Point &p, const Real angle, const Point &axis)
 
std::vector< Point > boxCorners (const libMesh::BoundingBox &box, const Real factor)
 

Function Documentation

◆ boxCorners() [1/2]

std::vector<libMesh::Point> geom_utils::boxCorners ( const libMesh::BoundingBox box,
const libMesh::Real  factor 
)

Get corner points of a bounding box, with side length re-scaled.

Parameters
[in]boxbounding box to start from
[in]factorby which to multiply the bounding box side

◆ boxCorners() [2/2]

std::vector<Point> geom_utils::boxCorners ( const libMesh::BoundingBox box,
const Real  factor 
)

Definition at line 257 of file GeometryUtils.C.

258 {
259  Point diff = (box.max() - box.min()) / 2.0;
260  const Point origin = box.min() + diff;
261 
262  // Rescale side length of box by specified factor
263  diff *= factor;
264 
265  // Vectors for sides of box
266  const Point dx(2.0 * diff(0), 0.0, 0.0);
267  const Point dy(0.0, 2.0 * diff(1), 0.0);
268  const Point dz(0.0, 0.0, 2.0 * diff(2));
269 
270  std::vector<Point> verts(8, origin - diff);
271  const unsigned int pts_per_dim = 2;
272  for (const auto z : make_range(pts_per_dim))
273  for (const auto y : make_range(pts_per_dim))
274  for (const auto x : make_range(pts_per_dim))
275  verts[pts_per_dim * pts_per_dim * z + pts_per_dim * y + x] += x * dx + y * dy + z * dz;
276 
277  return verts;
278 }
const Point & min() const
IntRange< T > make_range(T beg, T end)
const Point & max() const

◆ distanceFromLine() [1/2]

libMesh::Real geom_utils::distanceFromLine ( const libMesh::Point pt,
const libMesh::Point line0,
const libMesh::Point line1 
)

Compute the distance from a 3-D line, provided in terms of two points on the line.

Parameters
[in]ptpoint of interest
[in]line0first point on line
[in]line1second point on line
Returns
distance from line

Referenced by projectedDistanceFromLine().

◆ distanceFromLine() [2/2]

Real geom_utils::distanceFromLine ( const Point &  pt,
const Point &  line0,
const Point &  line1 
)

Definition at line 188 of file GeometryUtils.C.

189 {
190  const Point a = pt - line0;
191  const Point b = pt - line1;
192  const Point c = line1 - line0;
193 
194  return (a.cross(b).norm()) / c.norm();
195 }

◆ isPointZero() [1/2]

bool geom_utils::isPointZero ( const Point &  pt)

Definition at line 17 of file GeometryUtils.C.

18 {
19  const Point zero(0.0, 0.0, 0.0);
20  return pt.absolute_fuzzy_equals(zero);
21 }
const Number zero

◆ isPointZero() [2/2]

bool geom_utils::isPointZero ( const libMesh::Point pt)

Check whether a point is equal to zero.

Parameters
[in]ptpoint
Returns
whether point is equal to the zero point

Referenced by unitVector().

◆ minDistanceToPoints() [1/2]

Real geom_utils::minDistanceToPoints ( const Point &  pt,
const std::vector< Point > &  candidates,
const unsigned int  axis 
)

Definition at line 33 of file GeometryUtils.C.

36 {
37  const auto idx = projectedIndices(axis);
38 
40  for (const auto & c : candidates)
41  {
42  const Real dx = c(idx.first) - pt(idx.first);
43  const Real dy = c(idx.second) - pt(idx.second);
44  const Real d = std::sqrt(dx * dx + dy * dy);
45  distance = std::min(d, distance);
46  }
47 
48  return distance;
49 }
Real distance(const Point &p)
auto max(const L &left, const R &right)
std::pair< unsigned int, unsigned int > projectedIndices(const unsigned int axis)
Get the indices of the plane perpendicular to the specified axis.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
auto min(const L &left, const R &right)
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)

◆ minDistanceToPoints() [2/2]

libMesh::Real geom_utils::minDistanceToPoints ( const libMesh::Point pt,
const std::vector< libMesh::Point > &  candidates,
const unsigned int  axis 
)

Get the minimum distance from a point to another set of points, in the plane perpendicular to the specified axis.

Parameters
[in]ptpoint
[in]candidatesset of points we will find the nearest of
[in]axisaxis perpendicular to the plane of the polygon
Returns
minimum distance to the provided points

◆ pointInPolygon() [1/2]

bool geom_utils::pointInPolygon ( const Point &  point,
const std::vector< Point > &  corners,
const unsigned int  axis 
)

Definition at line 78 of file GeometryUtils.C.

79 {
80  const auto n_pts = corners.size();
81 
82  std::vector<bool> negative_half_space;
83  std::vector<bool> positive_half_space;
84  for (const auto i : index_range(corners))
85  {
86  const int next = (i == n_pts - 1) ? 0 : i + 1;
87  const auto half = projectedLineHalfSpace(point, corners[i], corners[next], axis);
88  negative_half_space.push_back(half < 0);
89  positive_half_space.push_back(half > 0);
90  }
91 
92  const bool negative = std::find(negative_half_space.begin(), negative_half_space.end(), true) !=
93  negative_half_space.end();
94  const bool positive = std::find(positive_half_space.begin(), positive_half_space.end(), true) !=
95  positive_half_space.end();
96 
97  const bool in_polygon = !(negative && positive);
98  if (in_polygon)
99  return true;
100 
101  if (pointOnEdge(point, corners, axis))
102  return true;
103 
104  return false;
105 }
Real projectedLineHalfSpace(Point pt1, Point pt2, Point pt3, const unsigned int axis)
Definition: GeometryUtils.C:64
bool pointOnEdge(const Point &point, const std::vector< Point > &corners, const unsigned int axis)
auto index_range(const T &sizable)

◆ pointInPolygon() [2/2]

bool geom_utils::pointInPolygon ( const libMesh::Point point,
const std::vector< libMesh::Point > &  corners,
const unsigned int  axis 
)

Whether a point is in 2-D a polygon in the plane perpendicular to the specified axis, given by corner points.

Parameters
[in]pointpoint of interest
[in]cornerscorner points of polygon
[in]axisaxis perpendicular to the plane of the polygon
Returns
whether point is inside the polygon

◆ pointOnEdge() [1/2]

bool geom_utils::pointOnEdge ( const Point &  point,
const std::vector< Point > &  corners,
const unsigned int  axis 
)

Definition at line 108 of file GeometryUtils.C.

109 {
110  const auto n_pts = corners.size();
111  const auto idx = projectedIndices(axis);
112 
113  constexpr Real tol = 1e-8;
114  for (const auto i : index_range(corners))
115  {
116  const int next = (i == n_pts - 1) ? 0 : i + 1;
117  const auto & pt1 = corners[i];
118  const auto & pt2 = corners[next];
119  const bool close_to_line = projectedDistanceFromLine(point, pt1, pt2, axis) < tol;
120 
121  // we can stop early if we know we're not close to the line
122  if (!close_to_line)
123  continue;
124 
125  // check that the point is "between" the two points; TODO: first pass
126  // we can just compare x and y coordinates
127  const bool between_points = (point(idx.first) >= std::min(pt1(idx.first), pt2(idx.first))) &&
128  (point(idx.first) <= std::max(pt1(idx.first), pt2(idx.first))) &&
129  (point(idx.second) >= std::min(pt1(idx.second), pt2(idx.second))) &&
130  (point(idx.second) <= std::max(pt1(idx.second), pt2(idx.second)));
131 
132  // point needs to be close to the line AND "between" the two points
133  if (close_to_line && between_points)
134  return true;
135  }
136 
137  return false;
138 }
Real projectedDistanceFromLine(Point pt, Point line0, Point line1, const unsigned int axis)
auto max(const L &left, const R &right)
std::pair< unsigned int, unsigned int > projectedIndices(const unsigned int axis)
Get the indices of the plane perpendicular to the specified axis.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto min(const L &left, const R &right)
auto index_range(const T &sizable)
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)

◆ pointOnEdge() [2/2]

bool geom_utils::pointOnEdge ( const libMesh::Point point,
const std::vector< libMesh::Point > &  corners,
const unsigned int  axis 
)

Whether a point is on the edge of a 2-D polygon in the plane perpendicular to the specified axis, given its corner points.

Parameters
[in]pointpoint of interest
[in]cornerscorner points of polygon
[in]axisaxis perpendicular to the plane of the polygon
Returns
whether point is on edge of polygon

Referenced by pointInPolygon().

◆ polygonCorners() [1/2]

std::vector<libMesh::Point> geom_utils::polygonCorners ( const unsigned int  num_sides,
const libMesh::Real  radius,
const unsigned int  axis 
)

Get the corner coordinates of a regular 2-D polygon, assuming a face of the polygon is parallel to the x0 axis.

Parameters
[in]num_sidesnumber of sides to polygon
[in]radiusdistance from polygon center to a corner
[in]axisaxis perpendicular to the plane of the polygon
Returns
corner coordinates

◆ polygonCorners() [2/2]

std::vector<Point> geom_utils::polygonCorners ( const unsigned int  num_sides,
const Real  radius,
const unsigned int  axis 
)

Definition at line 209 of file GeometryUtils.C.

210 {
211  std::vector<Point> corners;
212  const Real theta = 2.0 * M_PI / num_sides;
213  const Real first_angle = M_PI / 2.0 - theta / 2.0;
214 
215  for (const auto i : make_range(num_sides))
216  {
217  const Real angle = first_angle + i * theta;
218  const Real x = radius * cos(angle);
219  const Real y = radius * sin(angle);
220 
221  corners.push_back(projectPoint(x, y, axis));
222  }
223 
224  return corners;
225 }
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sin(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tan
const Real radius
Point projectPoint(const Real x0, const Real x1, const unsigned int axis)
Definition: GeometryUtils.C:52
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template cos(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(cos
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)

◆ projectedDistanceFromLine() [1/2]

libMesh::Real geom_utils::projectedDistanceFromLine ( libMesh::Point  pt,
libMesh::Point  line0,
libMesh::Point  line1,
const unsigned int  axis 
)

Compute the distance from a 3-D line, provided in terms of two points on the line.

Both the input point and the points on the line are projected into the 2-d plane perpendicular to the specified axis.

Parameters
[in]ptpoint of interest
[in]line0first point on line
[in]line1second point on line
[in]axisaxis index (0 = x, 1 = y, 2 = z) perpendicular to the projection plane
Returns
distance from line

Referenced by pointOnEdge().

◆ projectedDistanceFromLine() [2/2]

Real geom_utils::projectedDistanceFromLine ( Point  pt,
Point  line0,
Point  line1,
const unsigned int  axis 
)

Definition at line 198 of file GeometryUtils.C.

199 {
200  // project all the points to the plane perpendicular to the axis
201  pt(axis) = 0.0;
202  line0(axis) = 0.0;
203  line1(axis) = 0.0;
204 
205  return distanceFromLine(pt, line0, line1);
206 }
Real distanceFromLine(const Point &pt, const Point &line0, const Point &line1)

◆ projectedIndices()

std::pair< unsigned int, unsigned int > geom_utils::projectedIndices ( const unsigned int  axis)

Get the indices of the plane perpendicular to the specified axis.

For example, if the axis is the y-axis (1), then this will return (0, 2), indicating that the coordinates of a general 3-D point once projected onto the x-z plane can be obtained with the 0 and 2 indices.

Parameters
[in]axisaxis perpendicular to the projection plane
Returns
indices of coordinates on plane

Definition at line 141 of file GeometryUtils.C.

Referenced by minDistanceToPoints(), pointOnEdge(), projectedLineHalfSpace(), projectedUnitNormal(), and projectPoint().

142 {
143  std::pair<unsigned int, unsigned int> indices;
144 
145  if (axis == 0)
146  {
147  indices.first = 1;
148  indices.second = 2;
149  }
150  else if (axis == 1)
151  {
152  indices.first = 0;
153  indices.second = 2;
154  }
155  else
156  {
157  indices.first = 0;
158  indices.second = 1;
159  }
160 
161  return indices;
162 }

◆ projectedLineHalfSpace() [1/2]

Real geom_utils::projectedLineHalfSpace ( Point  pt1,
Point  pt2,
Point  pt3,
const unsigned int  axis 
)

Definition at line 64 of file GeometryUtils.C.

65 {
66  // project points onto plane perpendicular to axis
67  pt1(axis) = 0.0;
68  pt2(axis) = 0.0;
69  pt3(axis) = 0.0;
70 
71  const auto i = projectedIndices(axis);
72 
73  return (pt1(i.first) - pt3(i.first)) * (pt2(i.second) - pt3(i.second)) -
74  (pt2(i.first) - pt3(i.first)) * (pt1(i.second) - pt3(i.second));
75 }
std::pair< unsigned int, unsigned int > projectedIndices(const unsigned int axis)
Get the indices of the plane perpendicular to the specified axis.

◆ projectedLineHalfSpace() [2/2]

libMesh::Real geom_utils::projectedLineHalfSpace ( libMesh::Point  pt1,
libMesh::Point  pt2,
libMesh::Point  pt3,
const unsigned int  axis 
)

If positive, point is on the positive side of the half space (and vice versa).

Because a 3-D line does not have a negative or positive "side," you must provide the 'axis' perpendicular to the plane into which the point and line are first projected.

Parameters
[in]pt1point of interest
[in]pt2one end point of line
[in]pt3other end point of line
[in]axisaxis perpendicular to plane onto which point and line are first projected
Returns
half space of line

Referenced by pointInPolygon().

◆ projectedUnitNormal() [1/2]

libMesh::Point geom_utils::projectedUnitNormal ( libMesh::Point  pt1,
libMesh::Point  pt2,
const unsigned int  axis 
)

Get the unit normal vector between two points (which are first projected onto the plane perpendicular to the 'axis'), such that the cross product of the unit normal with the line from pt1 to pt2 has a positive 'axis' component.

Parameters
[in]pt1first point for line
[in]pt2second point for line
[in]axisproject points onto plane perpendicular to this axis
Returns
unit normal

◆ projectedUnitNormal() [2/2]

Point geom_utils::projectedUnitNormal ( Point  pt1,
Point  pt2,
const unsigned int  axis 
)

Definition at line 165 of file GeometryUtils.C.

166 {
167  // project the points to the plane perpendicular to the axis
168  pt1(axis) = 0.0;
169  pt2(axis) = 0.0;
170 
171  const auto i = projectedIndices(axis);
172 
173  const Real dx = pt2(i.first) - pt1(i.first);
174  const Real dy = pt2(i.second) - pt1(i.second);
175 
176  const Point normal = projectPoint(dy, -dx, axis);
177  const Point gap_line = pt2 - pt1;
178 
179  const auto cross_product = gap_line.cross(normal);
180 
181  if (cross_product(axis) > 0)
182  return normal.unit();
183  else
184  return projectPoint(-dy, dx, axis).unit();
185 }
Point projectPoint(const Real x0, const Real x1, const unsigned int axis)
Definition: GeometryUtils.C:52
std::pair< unsigned int, unsigned int > projectedIndices(const unsigned int axis)
Get the indices of the plane perpendicular to the specified axis.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ projectPoint() [1/2]

Point geom_utils::projectPoint ( const Real  x0,
const Real  x1,
const unsigned int  axis 
)

Definition at line 52 of file GeometryUtils.C.

53 {
54  const auto i = projectedIndices(axis);
55  Point point;
56  point(i.first) = x0;
57  point(i.second) = x1;
58  point(axis) = 0.0;
59 
60  return point;
61 }
std::pair< unsigned int, unsigned int > projectedIndices(const unsigned int axis)
Get the indices of the plane perpendicular to the specified axis.

◆ projectPoint() [2/2]

libMesh::Point geom_utils::projectPoint ( const libMesh::Real  x0,
const libMesh::Real  x1,
const unsigned int  axis 
)

Given two coordinates, construct a point in the 2-D plane perpendicular to the specified axis.

Parameters
[in]x0first coordinate
[in]x1second coordinate
[in]axisaxis perpendicular to the projection plane
Returns
point

Referenced by polygonCorners(), and projectedUnitNormal().

◆ rotatePointAboutAxis() [1/2]

libMesh::Point geom_utils::rotatePointAboutAxis ( const libMesh::Point p,
const libMesh::Real  angle,
const libMesh::Point axis 
)

Rotate point about an axis.

Parameters
[in]ppoint
[in]angleangle to rotate (radians)
[in]axisaxis expressed as vector
Returns
rotated point

Referenced by TransformedPositions::initialize().

◆ rotatePointAboutAxis() [2/2]

Point geom_utils::rotatePointAboutAxis ( const Point &  p,
const Real  angle,
const Point &  axis 
)

Definition at line 228 of file GeometryUtils.C.

229 {
230  const Real cos_theta = cos(angle);
231  const Real sin_theta = sin(angle);
232 
233  Point pt;
234  const Real xy = axis(0) * axis(1);
235  const Real xz = axis(0) * axis(2);
236  const Real yz = axis(1) * axis(2);
237 
238  const Point x_op(cos_theta + axis(0) * axis(0) * (1.0 - cos_theta),
239  xy * (1.0 - cos_theta) - axis(2) * sin_theta,
240  xz * (1.0 - cos_theta) + axis(1) * sin_theta);
241 
242  const Point y_op(xy * (1.0 - cos_theta) + axis(2) * sin_theta,
243  cos_theta + axis(1) * axis(1) * (1.0 - cos_theta),
244  yz * (1.0 - cos_theta) - axis(0) * sin_theta);
245 
246  const Point z_op(xz * (1.0 - cos_theta) - axis(1) * sin_theta,
247  yz * (1.0 - cos_theta) + axis(0) * sin_theta,
248  cos_theta + axis(2) * axis(2) * (1.0 - cos_theta));
249 
250  pt(0) = x_op * p;
251  pt(1) = y_op * p;
252  pt(2) = z_op * p;
253  return pt;
254 }
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sin(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tan
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template cos(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(cos
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ unitVector() [1/2]

Point geom_utils::unitVector ( const Point &  pt,
const std::string &  name 
)

Definition at line 24 of file GeometryUtils.C.

25 {
26  if (isPointZero(pt))
27  mooseError("'" + name + "' cannot have zero norm!");
28 
29  return pt.unit();
30 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
bool isPointZero(const Point &pt)
Definition: GeometryUtils.C:17

◆ unitVector() [2/2]

libMesh::Point geom_utils::unitVector ( const libMesh::Point pt,
const std::string &  name 
)

Get the unit vector for a point parameter.

Parameters
[in]ptpoint
[in]namename of the parameter