PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
geomUtilFunctions.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2026 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#include "geomUtilFunctions.h"
12#include "geomObjects.h"
13#include "util/function.h"
14#include <cmath>
15#include "util/io.h"
17#include "nsearch/nsearch.h"
18#include <format>
19#include <iostream>
20
22
23namespace geom {
24
25std::vector<util::Point> getCornerPoints(
26 size_t dim, const std::pair<util::Point, util::Point> &box) {
27
28 if (dim == 1)
29 return {box.first, box.second};
30 else if (dim == 2)
31 return {box.first,
32 util::Point(box.second.d_x, box.first.d_y, 0.),
33 box.second,
34 util::Point(box.first.d_x, box.second.d_y, 0.)};
35 else if (dim == 3) {
36 double a = box.second.d_x - box.first.d_x;
37 double b = box.second.d_y - box.first.d_y;
38 double c = box.second.d_z - box.first.d_z;
39 return {box.first,
40 box.first + util::Point(a, 0., 0.),
41 box.first + util::Point(a, b, 0.),
42 box.first + util::Point(0., b, 0.),
43 box.first + util::Point(0., 0., c),
44 box.first + util::Point(a, 0., c),
45 box.first + util::Point(a, b, c),
46 box.first + util::Point(0., b, c)};
47 }
48 else {
49 std::cerr << "Error: Check dimension = " << dim << ".\n";
50 exit(1);
51 }
52}
53
54std::vector<std::pair<util::Point, util::Point>> getEdges(size_t dim, const
55std::pair<util::Point, util::Point> &box) {
56
57 std::vector<std::pair<util::Point, util::Point>> data;
58 if (dim == 1) {
59 data.emplace_back(box);
60 return data;
61 } else if (dim == 2) {
62
63 // points returned by below function is in anti-clockwise order
64 auto corner_pts = getCornerPoints(dim, box);
65
66 data.emplace_back(corner_pts[0], corner_pts[1]);
67 data.emplace_back(corner_pts[1], corner_pts[2]);
68 data.emplace_back(corner_pts[2], corner_pts[3]);
69 data.emplace_back(corner_pts[3], corner_pts[0]);
70 return data;
71 } else if (dim == 3) {
72
73 // points returned by below function is in anti-clockwise order
74 // first 4 points are on lower z-plane, and remaining are in upper z-plane
75 auto corner_pts = getCornerPoints(dim, box);
76
77 // edges in lower plane
78 data.emplace_back(corner_pts[0], corner_pts[1]);
79 data.emplace_back(corner_pts[1], corner_pts[2]);
80 data.emplace_back(corner_pts[2], corner_pts[3]);
81 data.emplace_back(corner_pts[3], corner_pts[0]);
82
83 // edges in upper plane
84 data.emplace_back(corner_pts[4], corner_pts[5]);
85 data.emplace_back(corner_pts[5], corner_pts[6]);
86 data.emplace_back(corner_pts[6], corner_pts[7]);
87 data.emplace_back(corner_pts[7], corner_pts[4]);
88
89 // edges parrallel to z-axis
90 data.emplace_back(corner_pts[0], corner_pts[4]);
91 data.emplace_back(corner_pts[1], corner_pts[5]);
92 data.emplace_back(corner_pts[2], corner_pts[6]);
93 data.emplace_back(corner_pts[3], corner_pts[7]);
94
95 return data;
96 } else {
97 std::cerr << "getEdges(): Function implemented for dim = 1,2,3 only.\n";
98 exit(EXIT_FAILURE);
99 }
100}
101
103 const std::pair<util::Point, util::Point> &box) {
104
105 if (dim == 1)
106 return {0.5 * box.second.d_x + 0.5 * box.first.d_x, 0., 0.};
107 else if (dim == 2)
108 return {0.5 * box.second.d_x + 0.5 * box.first.d_x,
109 0.5 * box.second.d_y + 0.5 * box.first.d_y, 0.};
110 else if (dim == 3)
111 return {0.5 * box.second.d_x + 0.5 * box.first.d_x,
112 0.5 * box.second.d_y + 0.5 * box.first.d_y,
113 0.5 * box.second.d_z + 0.5 * box.first.d_z};
114 else {
115 std::cerr << "Error: Check dimension = " << dim << ".\n";
116 exit(1);
117 }
118}
119
120bool areBoxesNear(const std::pair<util::Point, util::Point>
121 &b1,
122 const std::pair<util::Point, util::Point> &b2,
123 const double &tol,
124 size_t dim) {
125
126 auto cp1 = getCornerPoints(dim, b1);
127 auto cp2 = getCornerPoints(dim, b2);
128
129 for (auto p : cp1) {
130
131 // check 1: If any of the corner points of box 1 are inside box 2
132 if (isPointInsideBox(p, dim, b2))
133 return true;
134
135 // check 2: If any pair of corner points of box 1 and box 2 are at
136 // distance smaller than the tolerance
137 for (auto pp : cp2) {
138 auto dx = pp - p;
139 if (util::isLess(dx.length(), tol))
140 return true;
141 }
142 }
143
144 // check 3: Check if distance between centers of box 1 and box 2 are below
145 // sum of tolerance, radius of circle inscribed in box 1, and radius of
146 // circle inscribed in box 2
147 auto dxc = getCenter(dim, b2) - getCenter(dim, b1);
148 auto dist = tol + inscribedRadiusInBox(dim, b1) + inscribedRadiusInBox(dim,
149 b2);
150
151 if (util::isLess(dxc.length(), dist))
152 return true;
153
154 // check 4: Check if distance between centers of box 1 and box 2 are below
155 // sum of tolerance, radius of circle inscribed in box 1, and radius of
156 // circle circumscribed in box 2
157 dist = tol + inscribedRadiusInBox(dim, b1) + circumscribedRadiusInBox(dim,
158 b2);
159 if (util::isLess(dxc.length(), dist))
160 return true;
161
162 dist = tol + circumscribedRadiusInBox(dim, b1) + inscribedRadiusInBox(dim,
163 b2);
164 if (util::isLess(dxc.length(), dist))
165 return true;
166
167 return false;
168}
169
170bool isPointInsideBox(util::Point x, size_t dim,
171 const std::pair<util::Point, util::Point> &box) {
172
173 if (dim == 1)
174 return !(util::isLess(x.d_x, box.first.d_x - 1.0E-12) or
175 util::isGreater(x.d_x, box.second.d_x + 1.0E-12));
176 else if (dim == 2)
177 return !(util::isLess(x.d_x, box.first.d_x - 1.0E-12) or
178 util::isLess(x.d_y, box.first.d_y - 1.0E-12) or
179 util::isGreater(x.d_x, box.second.d_x + 1.0E-12) or
180 util::isGreater(x.d_y, box.second.d_y + 1.0E-12));
181 else if (dim == 3)
182 return !(util::isLess(x.d_x, box.first.d_x - 1.0E-12) or
183 util::isLess(x.d_y, box.first.d_y - 1.0E-12) or
184 util::isLess(x.d_z, box.first.d_z - 1.0E-12) or
185 util::isGreater(x.d_x, box.second.d_x + 1.0E-12) or
186 util::isGreater(x.d_y, box.second.d_y + 1.0E-12) or
187 util::isGreater(x.d_z, box.second.d_z + 1.0E-12));
188 else {
189 std::cerr << "isPointInsideBox(): Function implemented for dim = 1,2,3 only.\n";
190 exit(EXIT_FAILURE);
191 }
192}
193
194double inscribedRadiusInBox(size_t dim,
195 const std::pair<util::Point, util::Point> &box) {
196
197 double r = 0.5 * std::abs(box.second.d_x - box.first.d_x);
198 if (dim == 1)
199 return r;
200 else if (dim == 2) {
201 if (util::isGreater(r, 0.5 * std::abs(box.second.d_y - box.first.d_y)))
202 return 0.5 * std::abs(box.second.d_y - box.first.d_y);
203 else
204 return r;
205 } else if (dim == 3) {
206 if (util::isGreater(r, 0.5 * std::abs(box.second.d_y - box.first.d_y)))
207 r = 0.5 * std::abs(box.second.d_y - box.first.d_y);
208
209 if (util::isGreater(r, 0.5 * std::abs(box.second.d_z - box.first.d_z)))
210 return 0.5 * std::abs(box.second.d_z - box.first.d_z);
211 else
212 return r;
213 } else {
214 std::cerr << "inscribedRadiusInBox(): Function implemented for dim = 1,2,3 only.\n";
215 exit(EXIT_FAILURE);
216 }
217}
218
219double circumscribedRadiusInBox(size_t dim,
220 const std::pair<util::Point, util::Point> &box) {
221
222 auto xc = getCenter(dim, box);
223 auto cp = getCornerPoints(dim, box);
224
225 auto dx = cp[0] - xc;
226 auto r = dx.length();
227
228 if (dim == 1)
229 return r;
230 else {
231 for (auto p : cp) {
232 dx = p - xc;
233 if (util::isGreater(dx.length(), r))
234 r = dx.length();
235 }
236
237 return r;
238 }
239}
240
241
243 double x_max, double y_min,
244 double y_max) {
245
246 return !(util::isLess(x.d_x, x_min - 1.0E-12) or
247 util::isLess(x.d_y, y_min - 1.0E-12) or
248 util::isGreater(x.d_x, x_max + 1.0E-12) or
249 util::isGreater(x.d_y, y_max + 1.0E-12));
250}
251
253 util::Point x_rt) {
254 return !(util::isLess(x.d_x, x_lb.d_x - 1.0E-12) or
255 util::isLess(x.d_y, x_lb.d_y - 1.0E-12) or
256 util::isGreater(x.d_x, x_rt.d_x + 1.0E-12) or
257 util::isGreater(x.d_y, x_rt.d_y + 1.0E-12));
258}
259
261 double x2, double y1,
262 double y2, double theta) {
263 // we assume that the rectangle has passed the test
264
265 //
266 // (x2,y2)
267 // o
268 //
269 //
270 //
271 //
272 //
273 // o
274 // (x1,y1)
275
276 // get divisors
278 util::Point(x2 - x1, y2 - y1, 0.0), theta);
279
280 // double lam1 = (x2-x1) * std::cos(theta) + (y2-y1) * std::sin(theta);
281 // double lam2 = -(x2-x1) * std::sin(theta) + (y2-y1) * std::cos(theta);
282
283 // get mapped coordinate of x
285 util::Point(x[0] - x1, x[1] - y1, 0.0), theta);
286
287 // double xmap = (x[0]-x1) * std::cos(theta) + (x[1]-y1) * std::sin(theta);
288 // double ymap = -(x[0]-x1) * std::sin(theta) + (x[1]-y1) * std::cos(theta);
289
290 // check if mapped coordinate are out of range [0, lam1] and [0, lam2]
291 return !(util::isLess(xmap[0], -1.0E-12) or
292 util::isLess(xmap[1], -1.0E-12) or
293 util::isGreater(xmap[0], lam[0] + 1.0E-12) or
294 util::isGreater(xmap[1], lam[1] + 1.0E-12));
295}
296
298 util::Point x_rtf) {
299 return !(util::isLess(x.d_x, x_lbb.d_x - 1.0E-12) or
300 util::isLess(x.d_y, x_lbb.d_y - 1.0E-12) or
301 util::isLess(x.d_z, x_lbb.d_z - 1.0E-12) or
302 util::isGreater(x.d_x, x_rtf.d_x + 1.0E-12) or
303 util::isGreater(x.d_y, x_rtf.d_y + 1.0E-12) or
304 util::isGreater(x.d_z, x_rtf.d_z + 1.0E-12));
305}
306
307bool isPointInsideCylinder(const util::Point &p, const double &length, const double
308&radius, const util::Point &axis) {
309
310 double p_dot_a = p * axis;
311 if (p_dot_a > length or p_dot_a < 0.)
312 return false;
313 else {
314
315 auto p_parallel = p - p_dot_a * axis;
316
317 return p_parallel.lengthSq() < radius * radius;
318 }
319}
320
321bool isPointInsideCylinder(const util::Point &p, const double &radius,
322 const util::Point &x1, const util::Point &x2) {
323
324 auto p_new = p - x1;
325 auto a = x2 - x1;
326 double p_dot_a = p_new * a;
327
328 // note here we should 1 if a is not normalized
329 if (p_dot_a > 1. or p_dot_a < 0.)
330 return false;
331 else {
332
333 auto p_parallel = p_new - p_dot_a * a;
334
335 return p_parallel.lengthSq() < radius * radius;
336 }
337}
338
339bool isPointInsideEllipse(const util::Point &p, const util::Point &center, const
340std::vector<double> &radius_vec, unsigned int dim) {
341
342 double d = 0.;
343 auto x = p - center;
344 for (unsigned int i=0; i<dim; i++)
345 d += x[i] * x[i] / (radius_vec[i] * radius_vec[i]);
346
347 return d < 1.;
348}
349
350bool isPointInsideEllipse(const util::Point &p, const util::Point &center, const
351std::vector<double> &radius_vec, unsigned int dim, double &d) {
352
353 d = 0.;
354 auto x = p - center;
355 for (unsigned int i=0; i<dim; i++)
356 d += x[i] * x[i] / (radius_vec[i] * radius_vec[i]);
357
358 return d < 1.;
359}
360
362util::Point &p2,
363 const double &s) {
364 return (1. - s) * p1 + s * p2;
365}
366
367bool doLinesIntersect(const std::pair<util::Point, util::Point> &line_1,
368 const std::pair<util::Point, util::Point> &line_2) {
369
370 // change of variable so that first point of line_1 is at origin
371 // After change of variables:
372 // a is the second point of line_1
373 // b is the first point of line_2
374 // c is the difference of second and first point of line_2
375 auto a = line_1.second - line_1.first;
376 auto b = line_2.first - line_1.first;
377 auto c = line_2.second - line_2.first;
378
379 // check if the two lines are parallel
380 if (util::angle(a / a.length(), c / c.length()) < 1.0E-8)
381 return false;
382
383 double a_dot_a = a.lengthSq();
384 double a_dot_b = a * b;
385 double a_dot_c = a * c;
386 double b_dot_c = b * c;
387 double c_dot_c = c.lengthSq();
388
389 double r = (a_dot_a * b_dot_c - a_dot_b * a_dot_c) /
390 (a_dot_c * a_dot_c - c_dot_c * a_dot_a);
391
392 // if r is in (0,1) then this gives the intersection point
393 // otherwise b + r c gives the point where two vectors originating from
394 // a and originating from b would intersect
395 return r > 0. and r < 1.;
396}
397
398double distanceBetweenLines(const std::pair<util::Point, util::Point> &line_1,
399 const std::pair<util::Point, util::Point>
400 &line_2) {
401
402 // let line 1 is l1(s) = p + s u
403 // and line 2 is l2(r) = q + r v
404 // and let normal to the plane containing line 1 and 2 is
405 // n = u x v / |u x v|
406
407 auto u = line_1.second - line_1.first;
408 auto v = line_2.second - line_2.first;
409 auto w0 = line_1.first - line_2.first;
410
411 double a = u * u;
412 double b = u * v;
413 double c = v * v;
414 double d = u * w0;
415 double e = v * w0;
416
417 auto dp = w0 + ((b * e - c * d) * u + (a * e - b * d) * v) / (a * c - b * b);
418
419 return dp.length();
420}
421
422double
423distanceBetweenSegments(const std::pair<util::Point, util::Point> &line_1,
424 const std::pair<util::Point, util::Point> &line_2) {
425
426 // let line 1 is l1(s) = p + s u
427 // and line 2 is l2(r) = q + r v
428 // and let normal to the plane containing line 1 and 2 is
429 // n = u x v / |u x v|
430
431 auto u = line_1.second - line_1.first;
432 auto v = line_2.second - line_2.first;
433 auto w0 = line_1.first - line_2.first;
434
435 double a = u * u;
436 double b = u * v;
437 double c = v * v;
438 double d = u * w0;
439 double e = v * w0;
440 double D = a * c - b * b;
441 double sc, sN, sD = D;
442 double tc, tN, tD = D;
443
444 // compute line parameters of two closest points
445 if (D < 1.0E-12) {
446
447 sN = 0.;
448 sD = 1.;
449 tN = e;
450 tD = c;
451 } else {
452
453 sN = b * e - c * d;
454 tN = a * e - b * d;
455
456 if (sN < 0.) {
457 sN = 0.;
458 tN = e;
459 tD = c;
460 } else if (sN > sD) {
461 sN = sD;
462 tN = e + b;
463 tD = c;
464 }
465 }
466
467 if (tN < 0.) {
468
469 tN = 0.;
470
471 if (-d < 0.)
472 sN = 0.;
473 else if (-d > a)
474 sN = sD;
475 else {
476 sN = -d;
477 sD = a;
478 }
479 } else if (tN > tD) {
480
481 tN = tD;
482
483 if (-d + b < 0.)
484 sN = 0.;
485 else if (-d + b > a)
486 sN = sD;
487 else {
488 sN = -d + b;
489 sD = a;
490 }
491 }
492
493 sc = std::abs(sN) < 1.0E-12 ? 0. : sN / sD;
494 tc = std::abs(tN) < 1.0E-12 ? 0. : tN / tD;
495
496 auto dp = w0 + sc * u - tc * v;
497
498 return dp.length();
499}
500
501double distanceBetweenPlanes(const std::pair<util::Point, util::Point> &plane_1,
502 const std::pair<util::Point, util::Point>
503 &plane_2) {
504
505 // check if planes are parallel
506 if (util::angle(plane_1.first, plane_2.first) < 1.0E-8)
507 return 0.;
508
509 return std::abs(plane_1.first * (plane_1.second - plane_2.second)) /
510 plane_1.first.length();
511}
512
514 const std::pair<util::Point, util::Point> &line) {
515
516 // line vector
517 auto v = line.second - line.first;
518
519 // vector from 1st point of line to p
520 auto w = p - line.first;
521
522 // project w onto v and add 1st point to get projected point's location
523 auto w_on_line = line.first + (w * v) * v / v.lengthSq();
524
525 return (p - w_on_line).length();
526}
527
529 const std::pair<util::Point, util::Point> &line) {
530
531 // line vector
532 auto v = line.second - line.first;
533
534 // vector from 1st point of line to p
535 auto w = p - line.first;
536
537 // determine if w is on left side or right side of line
538 double w_dot_v = w * v;
539 if (w_dot_v < 1.0E-12)
540 return (p - line.first).length();
541
542 if (w_dot_v > v.lengthSq() - 1.0E-12)
543 return (p - line.second).length();
544
545 // project w onto v and add 1st point to get projected point's location
546 auto w_on_line = line.first + w_dot_v * v / v.lengthSq();
547
548 return (p - w_on_line).length();
549}
550
552 const std::pair<util::Point, util::Point> &plane) {
553
554 // if plane is given by unit normal n and a point a which is contained in it
555 // then the distance of point p from plane is
556 // |(p - a) dot n| / |n|
557
558 auto pa = p - plane.second;
559 return std::abs(pa * plane.first) / plane.first.length();
560}
561
562double computeMeshSize(const std::vector<util::Point> &nodes) {
563
564 double guess = 0.;
565 if (nodes.size() < 2)
566 return guess;
567
568 guess = (nodes[0] - nodes[1]).length();
569 for (size_t i = 0; i < nodes.size(); i++)
570 for (size_t j = 0; j < nodes.size(); j++)
571 if (i != j) {
572 double val = nodes[i].dist(nodes[j]);
573
574 if (util::isLess(val, 1.0E-12)) {
575
576 std::cout << "Check nodes are too close = "
577 << util::io::printStr<util::Point>({nodes[i],
578 nodes[j]})
579 << "\n";
580 std::cout << "Distance = " << val << ", guess = " << guess << "\n";
581 }
582 if (util::isLess(val, guess))
583 guess = val;
584 }
585
586 return guess;
587}
588
589double computeMeshSize(const std::vector<util::Point> &nodes, size_t start,
590 size_t end) {
591
592 double guess = 0.;
593 if (nodes.size() < 2 or (end - start) < 2)
594 return guess;
595
596 guess = (nodes[start] - nodes[start + 1]).length();
597 for (size_t i = start; i < end; i++)
598 for (size_t j = start; j < end; j++)
599 if (i != j) {
600 double val = nodes[i].dist(nodes[j]);
601
602 if (util::isLess(val, 1.0E-12)) {
603
604 std::cout << "Check nodes are too close = "
605 << util::io::printStr<util::Point>({nodes[i],
606 nodes[j]})
607 << "\n";
608 std::cout << "Distance = " << val << ", guess = " << guess << "\n";
609 }
610 if (util::isLess(val, guess))
611 guess = val;
612 }
613
614 return guess;
615}
616
617std::pair<util::Point, util::Point> computeBBox(const std::vector<util::Point> &nodes) {
618
619 auto p1 = util::Point();
620 auto p2 = util::Point();
621 for (const auto& x : nodes) {
622 if (util::isLess(x.d_x, p1.d_x))
623 p1.d_x = x.d_x;
624 if (util::isLess(x.d_y, p1.d_y))
625 p1.d_y = x.d_y;
626 if (util::isLess(x.d_z, p1.d_z))
627 p1.d_z = x.d_z;
628 if (util::isLess(p2.d_x, x.d_x))
629 p2.d_x = x.d_x;
630 if (util::isLess(p2.d_y, x.d_y))
631 p2.d_y = x.d_y;
632 if (util::isLess(p2.d_z, x.d_z))
633 p2.d_z = x.d_z;
634 }
635
636 return {p1, p2};
637}
638
639double computeInscribedRadius(const std::pair<util::Point, util::Point>
640 &box) {
641
642 return 0.5 * (box.first - box.second).length();
643}
644
645std::pair<util::Point, util::Point> toPointBox(const std::vector<double>
646 &p1, const std::vector<double>
647 &p2) {
648 auto q1 = util::Point(p1[0], p1[1], p1[2]);
649 auto q2 = util::Point(p2[0], p2[1], p2[2]);
650 return {q1, q2};
651}
652
653double triangleArea(const util::Point &x1, const util::Point &x2,
654 const util::Point &x3) {
655 return 0.5 * ((x2.d_x - x1.d_x) * (x3.d_y - x1.d_y) -
656 (x3.d_x - x1.d_x) * (x2.d_y - x1.d_y));
657}
658
659void computeNonlocalNeighborhood(const std::vector<util::Point> &nodes,
660 double horizon,
661 std::vector<std::vector<size_t>> &nodeNeighs) {
662 nodeNeighs.resize(nodes.size());
663
664 auto nsearch_p = std::make_unique<NSearch>(nodes);
665 double set_tree_time = nsearch_p->updatePointCloud(nodes, true);
666 set_tree_time += nsearch_p->setInputCloud();
667 std::cout << std::format("Tree setup time (ms) = {}. \n", set_tree_time);
668
669 for (size_t i=0; i<nodes.size(); i++) {
670 std::vector<size_t> neighs;
671 std::vector<double> sqr_dist;
672 nodeNeighs[i].resize(0);
673
674 if (nsearch_p->radiusSearch(nodes[i], horizon, neighs, sqr_dist) > 0) {
675 for (std::size_t j = 0; j < neighs.size(); ++j)
676 if (neighs[j] != i) {
677 nodeNeighs[i].push_back(neighs[j]);
678 }
679 }
680 }
681}
682
683void ellipsoidRotationMatrix(const Ellipsoid &e, double R[9]) {
684
685 if (std::abs(e.d_theta) < 1.0e-15) {
686 R[0] = R[4] = R[8] = 1.;
687 R[1] = R[2] = R[3] = R[5] = R[6] = R[7] = 0.;
688 return;
689 }
690
691 const double kx = e.d_axis.d_x;
692 const double ky = e.d_axis.d_y;
693 const double kz = e.d_axis.d_z;
694 const double c = std::cos(e.d_theta);
695 const double s = std::sin(e.d_theta);
696 const double t = 1.0 - c;
697
698 R[0] = t * kx * kx + c;
699 R[1] = t * kx * ky - kz * s;
700 R[2] = t * kx * kz + ky * s;
701 R[3] = t * kx * ky + kz * s;
702 R[4] = t * ky * ky + c;
703 R[5] = t * ky * kz - kx * s;
704 R[6] = t * kx * kz - ky * s;
705 R[7] = t * ky * kz + kx * s;
706 R[8] = t * kz * kz + c;
707}
708
709} // namespace geom
Ellipsoid: center , semi-axes in a body frame rotated from world by axis–angle (Rodrigues)....
double d_theta
Rotation angle (radians) about d_axis.
util::Point d_axis
Unit rotation axis (axis–angle); default (0,0,1) when .
A class for nearest neighbor search using nanoflann library.
Definition nsearch.h:178
nsearch::NFlannSearchKd< 3 > NSearch
Definition contact.h:20
util::Point getCenter(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns center point.
double pointDistancePlane(const util::Point &p, const std::pair< util::Point, util::Point > &plane)
Compute distance between point and plane.
double pointDistanceSegment(const util::Point &p, const std::pair< util::Point, util::Point > &line)
Compute distance between point and line.
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.
double distanceBetweenSegments(const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
Compute distance between lines.
bool isPointInsideRectangle(util::Point x, double x_min, double x_max, double y_min, double y_max)
Checks if point is inside a rectangle.
std::pair< util::Point, util::Point > toPointBox(const std::vector< double > &p1, const std::vector< double > &p2)
Create box from two coordinate data.
bool doLinesIntersect(const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
Do lines intersect.
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.
bool isPointInsideAngledRectangle(util::Point x, double x1, double x2, double y1, double y2, double theta)
Checks if point is inside an angled rectangle.
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.
double distanceBetweenPlanes(const std::pair< util::Point, util::Point > &plane_1, const std::pair< util::Point, util::Point > &plane_2)
Compute distance between planes.
bool isPointInsideCylinder(const util::Point &p, const double &length, const double &radius, const util::Point &axis)
Returns true if point is inside the cylinder.
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.
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.
util::Point getPointOnLine(const util::Point &p1, const util::Point &p2, const double &s)
Returns point in line formed by points p1 and p2.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
double triangleArea(const util::Point &x1, const util::Point &x2, const util::Point &x3)
Compute area of triangle.
double pointDistanceLine(const util::Point &p, const std::pair< util::Point, util::Point > &line)
Compute distance between point and line.
double computeMeshSize(const std::vector< util::Point > &nodes)
Computes minimum distance between any two nodes.
void ellipsoidRotationMatrix(const Ellipsoid &e, double R[9])
Row-major 3×3 rotation from ellipsoid axis–angle (identity if ).
void computeNonlocalNeighborhood(const std::vector< util::Point > &nodes, double horizon, std::vector< std::vector< size_t > > &nodeNeighs)
Partitions the nodes based on node neighborlist supplied. Function first creates a graph with nodes a...
double inscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of biggest circle/sphere completely within the object.
double distanceBetweenLines(const std::pair< util::Point, util::Point > &line_1, const std::pair< util::Point, util::Point > &line_2)
Compute distance between lines.
double computeInscribedRadius(const std::pair< util::Point, util::Point > &box)
Computes maximum radius of circle/sphere within a given box.
std::pair< util::Point, util::Point > computeBBox(const std::vector< util::Point > &nodes)
Computes bounding box for vector nodes.
bool isPointInsideCuboid(util::Point x, util::Point x_lbb, util::Point x_rtf)
Checks if point is inside a cuboid.
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:15
double angle(util::Point a, util::Point b)
Computes angle between two vectors.
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20
std::vector< double > rotateCW2D(const std::vector< double > &x, const double &theta)
Rotates a vector in xy-plane in clockwise direction.
A structure to represent 3d vectors.
Definition point.h:30
double d_y
the y coordinate
Definition point.h:36
double d_z
the z coordinate
Definition point.h:39
double length() const
Computes the Euclidean length of the vector.
Definition point.h:124
double lengthSq() const
Computes the Euclidean length of the vector.
Definition point.h:130
double d_x
the x coordinate
Definition point.h:33