PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
geom.h
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#ifndef UTIL_GEOMETRY_H
12#define UTIL_GEOMETRY_H
13
14#include "point.h" // definition of Point
15#include <vector>
16
17namespace util {
18
25std::vector<util::Point> getCornerPoints(size_t dim, const
26std::pair<util::Point, util::Point> &box);
27
34std::vector<std::pair<util::Point, util::Point>> getEdges(size_t dim, const
35std::pair<util::Point, util::Point> &box);
36
43util::Point getCenter(size_t dim,
44 const std::pair<util::Point, util::Point> &box);
45
54double inscribedRadiusInBox(size_t dim,
55 const std::pair<util::Point, util::Point> &box);
56
65double circumscribedRadiusInBox(size_t dim,
66 const std::pair<util::Point, util::Point> &box);
67
80bool isPointInsideBox(util::Point x, size_t dim,
81 const std::pair<util::Point, util::Point> &box);
82
92bool isPointInsideRectangle(util::Point x, double x_min, double x_max,
93 double y_min, double y_max);
94
103 util::Point x_rt);
104
115bool isPointInsideAngledRectangle(util::Point x, double x_min, double x_max,
116 double y_min, double y_max, double theta);
117
126 util::Point x_rtf);
127
137bool isPointInsideCylinder(const util::Point &p, const double &length, const double
138&radius, const util::Point &axis);
139
149bool isPointInsideCylinder(const util::Point &p, const double &radius, const util::Point &x1,
150 const util::Point &x2);
151
161bool isPointInsideEllipse(const util::Point &p, const util::Point &center, const
162std::vector<double> &radius_vec, unsigned int dim);
163
177bool isPointInsideEllipse(const util::Point &p, const util::Point &center, const
178std::vector<double> &radius_vec, unsigned int dim, double &d);
179
197bool areBoxesNear(const std::pair<util::Point, util::Point> & b1,
198 const std::pair<util::Point, util::Point> & b2,
199 const double & tol,
200 size_t dim);
201
209bool doLinesIntersect(const std::pair<util::Point, util::Point> &line_1,
210 const std::pair<util::Point, util::Point> &line_2);
211
219double distanceBetweenLines(const std::pair<util::Point, util::Point> &line_1,
220 const std::pair<util::Point, util::Point> &line_2);
221
229double distanceBetweenSegments(const std::pair<util::Point, util::Point> &line_1,
230 const std::pair<util::Point, util::Point> &line_2);
231
241double distanceBetweenPlanes(const std::pair<util::Point, util::Point> &plane_1,
242 const std::pair<util::Point, util::Point> &plane_2);
243
251double pointDistanceLine(const util::Point &p,
252 const std::pair<util::Point, util::Point> &line);
253
261double pointDistanceSegment(const util::Point &p,
262 const std::pair<util::Point, util::Point> &line);
263
272double pointDistancePlane(const util::Point &p,
273 const std::pair<util::Point, util::Point> &plane);
274
275
286util::Point getPointOnLine(const util::Point &p1, const util::Point &p2, const double &s);
287
294double computeMeshSize(const std::vector<util::Point> &nodes);
295
306double computeMeshSize(const std::vector<util::Point> &nodes, size_t start,
307 size_t end);
308
315std::pair<util::Point, util::Point> computeBBox(const
316 std::vector<util::Point> &nodes);
317
324double computeInscribedRadius(const std::pair<util::Point, util::Point>
325 &box);
326
334std::pair<util::Point, util::Point> toPointBox(const std::vector<double>
335 &p1, const std::vector<double>
336&p2);
337
346double triangleArea(const util::Point &x1, const util::Point &x2,
347 const util::Point &x3);
348
356template <class T>
357inline T l2Dist(const std::vector<T> &x1, const std::vector<T> &x2) {
358
359 if (x1.size() != x2.size())
360 throw std::invalid_argument("size of two vectors not matching");
361
362 T sum = 0.;
363 for (size_t i=0; i<x1.size(); i++)
364 sum += (x1[i] - x2[i]) * (x1[i] - x2[i]);
365
366 return std::sqrt(sum);
367}
368
369} // namespace util
370
371#endif // UTIL_GEOMETRY_H
Collection of methods useful in simulation.
T l2Dist(const std::vector< T > &x1, const std::vector< T > &x2)
Computes l2 distance between two vectors.
Definition geom.h:357
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.
Definition geom.cpp:159
double pointDistanceLine(const util::Point &p, const std::pair< util::Point, util::Point > &line)
Compute distance between point and line.
Definition geom.cpp:502
double computeMeshSize(const std::vector< util::Point > &nodes)
Computes minimum distance between any two nodes.
Definition geom.cpp:551
bool isPointInsideEllipse(const util::Point &p, const util::Point &center, const std::vector< double > &radius_vec, unsigned int dim)
Returns true if point is inside the ellipsoid.
Definition geom.cpp:328
double pointDistancePlane(const util::Point &p, const std::pair< util::Point, util::Point > &plane)
Compute distance between point and plane.
Definition geom.cpp:540
bool areBoxesNear(const std::pair< util::Point, util::Point > &b1, const std::pair< util::Point, util::Point > &b2, const double &tol, size_t dim)
Checks if given two boxes are within given distance from each other.
Definition geom.cpp:109
bool doLinesIntersect(const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
Do lines intersect.
Definition geom.cpp:356
double distanceBetweenPlanes(const std::pair< util::Point, util::Point > &plane_1, const std::pair< util::Point, util::Point > &plane_2)
Compute distance between planes.
Definition geom.cpp:490
bool isPointInsideCuboid(util::Point x, util::Point x_lbb, util::Point x_rtf)
Checks if point is inside a cuboid.
Definition geom.cpp:286
std::vector< std::pair< util::Point, util::Point > > getEdges(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
Definition geom.cpp:43
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
Definition geom.cpp:14
util::Point getPointOnLine(const util::Point &p1, const util::Point &p2, const double &s)
Returns point in line formed by points p1 and p2.
Definition geom.cpp:350
double distanceBetweenLines(const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
Compute distance between lines.
Definition geom.cpp:387
std::pair< util::Point, util::Point > computeBBox(const std::vector< util::Point > &nodes)
Computes bounding box for vector nodes.
Definition geom.cpp:606
util::Point getCenter(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns center point.
Definition geom.cpp:91
double distanceBetweenSegments(const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
Compute distance between lines.
Definition geom.cpp:412
double inscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of biggest circle/sphere completely within the object.
Definition geom.cpp:183
bool isPointInsideAngledRectangle(util::Point x, double x_min, double x_max, double y_min, double y_max, double theta)
Checks if point is inside an angled rectangle.
Definition geom.cpp:249
bool isPointInsideCylinder(const util::Point &p, const double &length, const double &radius, const util::Point &axis)
Returns true if point is inside the cylinder.
Definition geom.cpp:296
double pointDistanceSegment(const util::Point &p, const std::pair< util::Point, util::Point > &line)
Compute distance between point and line.
Definition geom.cpp:517
std::pair< util::Point, util::Point > toPointBox(const std::vector< double > &p1, const std::vector< double > &p2)
Create box from two coordinate data.
Definition geom.cpp:634
double triangleArea(const util::Point &x1, const util::Point &x2, const util::Point &x3)
Compute area of triangle.
Definition geom.cpp:642
double computeInscribedRadius(const std::pair< util::Point, util::Point > &box)
Computes maximum radius of circle/sphere within a given box.
Definition geom.cpp:628
bool isPointInsideRectangle(util::Point x, double x_min, double x_max, double y_min, double y_max)
Checks if point is inside a rectangle.
Definition geom.cpp:231
double circumscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of smallest circle/sphere which can have the box inside.
Definition geom.cpp:208
A structure to represent 3d vectors.
Definition point.h:30