PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
geomObjects.h
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#ifndef GEOM_GEOMOBJECTS_H
12#define GEOM_GEOMOBJECTS_H
13
14#include <iostream>
15#include <utility>
16#include <memory>
17#include <map>
18
19#include "util/function.h"
20#include "util/io.h"
21#include "util/point.h" // definition of Point
23
24namespace geom {
25
27 const std::map<std::string, size_t> geom_type_to_dim = {
28 {"circle", 2},
29 {"ellipse", 2},
30 {"square", 2},
31 {"rectangle", 2},
32 {"hexagon", 2},
33 {"triangle", 2},
34 {"drum2d", 2},
35 {"sphere", 3},
36 {"ellipsoid", 3},
37 {"cube", 3},
38 {"cuboid", 3},
39 {"cylinder", 3},
40 {"open_rect_channel_2d", 2},
41 {"open_cuboid_channel_3d", 3},
42 {"plane", 3},
43 {"line", 1}
44 };
45
47 inline size_t getGeomTypeToDim(std::string type) {
48 return geom_type_to_dim.at(type);
49 };
50
55 inline util::Point mapSimilarity(const util::Point &x, const util::Point &pivotDefault,
56 const util::Point &t, double scale, double angle, const util::Point &axis,
57 const util::Point *rotationPoint) {
58 const util::Point &p = (rotationPoint != nullptr) ? *rotationPoint : pivotDefault;
59 return p + util::rotate(x - p, angle, axis) * scale + t;
60 }
61
66
67util::Point d_xc; // centroid of box
68std::pair<util::Point, util::Point> d_box; // two corner points
69double d_r; // radius of circle inscribing box
70std::vector<size_t> d_nodes; // id of nodes in this box
71
72BoxPartition() : d_xc(util::Point()),
74 d_r(0.) {}
75
76bool isNear(const BoxPartition &box, const double &tol) const {
77 auto dx = d_xc - box.d_xc;
78 return dx.length() < d_r + box.d_r + tol;
79}
80
81bool isNear(const util::Point &x, const double &tol) const {
82
83 if (util::isLess(x.d_x, d_box.first.d_x - tol) or
84 util::isLess(x.d_y, d_box.first.d_y - tol) or
85 util::isLess(x.d_z, d_box.first.d_z - tol) or
86 util::isGreater(x.d_x, d_box.second.d_x + tol) or
87 util::isGreater(x.d_y, d_box.second.d_y + tol) or
88 util::isGreater(x.d_z, d_box.second.d_z + tol))
89 return false;
90
91 return true;
92}
93
94void addNode(const size_t &i) {
95 for (const auto &j: d_nodes)
96 if (j == i)
97 return;
98
99 d_nodes.push_back(i);
100}
101};
102
103
118
123
124public:
126 const std::string d_name;
127
129 const std::string d_description;
130
132 std::vector<std::string> d_tags;
133
134 public:
140 explicit GeomObject(std::string name = "",
141 std::string description = "")
142 : d_name(name), d_description(description) {
143 };
144
149 virtual double volume() const { return 0.; };
150
155 virtual util::Point center() const { return {}; };
156
161 virtual std::pair<util::Point, util::Point> box() const {
162 return {util::Point(), util::Point()};
163 };
164
170 virtual std::pair<util::Point, util::Point>
171 box(const double &tol) const {
172 return {util::Point(), util::Point()};
173 };
174
180 virtual double inscribedRadius() const { return 0.; };
181
187 virtual double boundingRadius() const { return 0.; };
188
198 virtual bool isInside(const util::Point &x) const { return false; };
199
205 virtual bool
206 isOutside(const util::Point &x) const { return false; };
207
214 virtual bool isNear(const util::Point &x, const double &tol) const {
215 return false;
216 };
217
225 virtual bool isNearBoundary(const util::Point &x, const double &tol,
226 const bool &within) const {
227 return false;
228 };
229
235 virtual bool
236 doesIntersect(const util::Point &x) const { return false; };
237
249 virtual bool
250 isInside(const std::pair<util::Point, util::Point> &box) const {
251 return false;
252 };
253
259 virtual bool
260 isOutside(const std::pair<util::Point, util::Point> &box) const {
261 return false;
262 };
263
270 virtual bool isNear(const std::pair<util::Point, util::Point> &box,
271 const double &tol) const {
272 return false;
273 };
274
280 virtual bool
282 const std::pair<util::Point, util::Point> &box) const {
283 return false;
284 };
285
295 virtual std::string printStr(int nt, int lvl) const {
296 auto tabS = util::io::getTabS(nt);
297 std::ostringstream oss;
298
299 oss << tabS << "------- GeomObject --------" << std::endl
300 << std::endl;
301 oss << tabS << "Base geometrical object" << std::endl;
302 oss << tabS << "Base implementation of GeomObject." << std::endl;
303 oss << tabS << "Name of GeomObject = " << d_name << std::endl;
304 oss << tabS << "Description of GeomObject = " << d_description
305 << std::endl;
306
307 return oss.str();
308 };
309
316 virtual void print(int nt, int lvl) const {
317 std::cout << printStr(nt, lvl);
318 };
319
321 virtual void print() const { print(0, 0); };
322
335 virtual void transform(const util::Point &translation, const double &scale,
336 const double &angle, const util::Point &axis,
337 const util::Point *rotationPoint = nullptr) {
338 // Base implementation does nothing
339 }
340
345 virtual bool wallContactQuery(const util::Point &x,
346 WallContactHit &hit) const {
347 (void)x;
348 hit = WallContactHit();
349 return false;
350 }
351 };
352
356 class NullGeomObject : public GeomObject {
357 public:
361 NullGeomObject(std::string description = "") : GeomObject("null", description) {
362 };
363
369 : GeomObject(other.d_name, other.d_description) {
370 d_tags = other.d_tags;
371 }
372
379 if (this != &other) {
380 // Copy base class members
381 d_tags = other.d_tags;
382 }
383 return *this;
384 }
385
386 void transform(const util::Point &translation, const double &scale,
387 const double &angle, const util::Point &axis,
388 const util::Point *rotationPoint) override {
389 (void)translation;
390 (void)scale;
391 (void)angle;
392 (void)axis;
393 (void)rotationPoint;
394 }
395
399 virtual std::string printStr(int nt, int lvl) const override {
400 auto tabS = util::io::getTabS(nt);
401 std::ostringstream oss;
402
403 oss << tabS << "------- NullGeomObject --------" << std::endl
404 << std::endl;
405 oss << tabS << "Name of GeomObject = " << d_name << std::endl;
406
407 return oss.str();
408 };
409
413 void print(int nt, int lvl) const override {
414 std::cout << printStr(nt, lvl);
415 };
416
420 void print() const override { print(0, 0); };
421 };
422
428 class Plane : public GeomObject {
429 public:
432
434 : GeomObject("plane", ""),
435 d_n(util::Point(0., 1., 0.)),
436 d_p(util::Point()) {}
437
438 Plane(util::Point n, util::Point p, std::string description = "")
439 : GeomObject("plane", std::move(description)), d_n(n), d_p(p) {
440 const double ln = d_n.length();
441 if (ln > 1.e-16)
442 d_n = d_n / ln;
443 }
444
445 Plane(const Plane &other)
446 : GeomObject(other.d_name, other.d_description),
447 d_n(other.d_n),
448 d_p(other.d_p) {
449 d_tags = other.d_tags;
450 }
451
452 Plane &operator=(const Plane &other) {
453 if (this != &other) {
454 d_tags = other.d_tags;
455 d_n = other.d_n;
456 d_p = other.d_p;
457 }
458 return *this;
459 }
460
461 void transform(const util::Point &translation, const double &scale,
462 const double &angle, const util::Point &axis,
463 const util::Point *rotationPoint) override {
464 (void)scale;
465 const util::Point pivot =
466 (rotationPoint != nullptr) ? *rotationPoint : d_p;
467 d_p = mapSimilarity(d_p, pivot, translation, 1., angle, axis, rotationPoint);
468 d_n = util::rotate(d_n, angle, axis);
469 const double ln = d_n.length();
470 if (ln > 1.e-16)
471 d_n = d_n / ln;
472 }
473
474 double volume() const override { return 0.; }
475 util::Point center() const override { return d_p; }
476 std::pair<util::Point, util::Point> box() const override {
477 return {d_p, d_p};
478 }
479 std::pair<util::Point, util::Point> box(const double &tol) const override {
480 return {d_p - util::Point(tol, tol, tol), d_p + util::Point(tol, tol, tol)};
481 }
482 double inscribedRadius() const override { return 0.; }
483 double boundingRadius() const override { return 0.; }
484
485 bool isInside(const util::Point &x) const override {
486 return (x - d_p) * d_n < 0.;
487 }
488 bool isOutside(const util::Point &x) const override {
489 return !isInside(x);
490 }
491 bool isNear(const util::Point &x, const double &tol) const override {
492 return std::abs((x - d_p) * d_n) <= tol;
493 }
494 bool isNearBoundary(const util::Point &x, const double &tol,
495 const bool & /*within*/) const override {
496 return isNear(x, tol);
497 }
498 bool doesIntersect(const util::Point &x) const override {
499 return isNear(x, 1.e-12);
500 }
501
502 bool wallContactQuery(const util::Point &x,
503 WallContactHit &hit) const override;
504
505 std::string printStr(int nt, int lvl) const override {
506 auto tabS = util::io::getTabS(nt);
507 std::ostringstream oss;
508 oss << tabS << "------- Plane --------\n\n";
509 oss << tabS << "Normal = " << d_n.printStr(0, lvl) << "\n";
510 oss << tabS << "Point = " << d_p.printStr(0, lvl) << "\n";
511 return oss.str();
512 }
513 void print(int nt, int lvl) const override {
514 std::cout << printStr(nt, lvl);
515 }
516 void print() const override { print(0, 0); }
517 };
518
522 class Line : public GeomObject {
523 public:
525 std::vector<util::Point> d_vertices;
526
529
531 double d_L;
532
534 double d_r;
535
536 public:
541 : GeomObject("line", ""),
542 d_r(0.),
543 d_L(0.),
544 d_x(util::Point()),
546 };
547
555 Line(util::Point x1, util::Point x2, std::string description = "")
556 : GeomObject("line", description),
557 d_L((x1 - x2).length()),
558 d_r(0.5 * (x1 - x2).length()),
559 d_x(0.5 * (x1 + x2)),
560 d_vertices({x1, x2}) {
561 };
562
570 Line(double L, util::Point x = util::Point(),
571 std::string description = "")
572 : GeomObject("line", description),
573 d_L(L),
574 d_r(0.5 * L),
575 d_x(x),
576 d_vertices({
577 x + util::Point(-0.5 * L, 0., 0.),
578 x + util::Point(0.5 * L, 0., 0.)
579 }) {
580 };
581
586 Line(const Line &other)
587 : GeomObject(other.d_name, other.d_description),
588 d_r(other.d_r),
589 d_L(other.d_L),
590 d_x(other.d_x),
591 d_vertices(other.d_vertices) {
592 d_tags = other.d_tags;
593 }
594
600 Line& operator=(const Line& other) {
601 if (this != &other) {
602 // Copy base class members
603 d_tags = other.d_tags;
604
605 // Copy member variables
606 d_r = other.d_r;
607 d_L = other.d_L;
608 d_x = other.d_x;
609 d_vertices = other.d_vertices;
610 }
611 return *this;
612 }
613
614 void transform(const util::Point &translation, const double &scale,
615 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
616 // Scale the length
617 d_L *= scale;
618 d_r *= scale;
619
620 const util::Point c0 = d_x;
621 // Rotate and translate vertices
622 for (auto &v : d_vertices) {
623 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
624 }
625 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
626 }
627
632 bool wallContactQuery(const util::Point &x,
633 WallContactHit &hit) const override;
634
638 double volume() const override;
639
643 util::Point center() const override;
644
648 std::pair<util::Point, util::Point> box() const override;
649
653 std::pair<util::Point, util::Point>
654 box(const double &tol) const override;
655
659 double inscribedRadius() const override;
660
664 double boundingRadius() const override;
665
674 bool isInside(const util::Point &x) const override;
675
679 bool isOutside(const util::Point &x) const override;
680
684 bool isNear(const util::Point &x, const double &tol) const override;
685
690 bool isNearBoundary(const util::Point &x, const double &tol,
691 const bool &within) const override;
692
696 bool doesIntersect(const util::Point &x) const override;
697
710 bool
711 isInside(
712 const std::pair<util::Point, util::Point> &box) const override;
713
718 bool
719 isOutside(
720 const std::pair<util::Point, util::Point> &box) const override;
721
726 bool isNear(const std::pair<util::Point, util::Point> &box,
727 const double &tol) const override;
728
733 bool doesIntersect(
734 const std::pair<util::Point, util::Point> &box) const override;
735
741 std::string printStr(int nt, int lvl) const override;
742
746 void print(int nt, int lvl) const override {
747 std::cout << printStr(nt, lvl);
748 };
749
753 void print() const override { print(0, 0); };
754 };
755
759 class Triangle : public GeomObject {
760 public:
762 std::vector<util::Point> d_vertices;
763
766
768 double d_r;
769
785
786 public:
791 : GeomObject("triangle", ""),
792 d_r(0.),
793 d_a(util::Point(1., 0., 0.)),
794 d_x(util::Point()),
795 d_vertices(std::vector<util::Point>(3, util::Point())) {
796 };
797
806 Triangle(double r, util::Point x = util::Point(0., 0., 0.),
807 util::Point a = util::Point(1., 0., 0.),
808 std::string description = "uniform")
809 : GeomObject("triangle", description),
810 d_r(r),
811 d_a(a),
812 d_x(x),
813 d_vertices(std::vector<util::Point>(3, util::Point())) {
814 // generate vertices
815 auto rotate_axis = util::Point(0., 0., 1.); // z-axis
816 for (int i = 0; i < 3; i++) {
818 d_a, i * 2. * M_PI / 3., rotate_axis);
819 }
820 };
821
827 std::string description = "vertices")
828 : GeomObject("triangle", description),
829 d_r(0.),
830 d_a(util::Point(1., 0., 0.)),
831 d_x(util::Point()),
832 d_vertices({v0, v1, v2}) {
833 d_x = (v0 + v1 + v2) / 3.0;
834 d_r = (v0 - d_x).length();
835 {
836 const double r1 = (v1 - d_x).length();
837 const double r2 = (v2 - d_x).length();
838 if (r1 > d_r)
839 d_r = r1;
840 if (r2 > d_r)
841 d_r = r2;
842 }
843 d_a = v0 - d_x;
844 if (d_a.length() > 0.)
845 d_a = d_a / d_a.length();
846 };
847
852 Triangle(const Triangle &other)
853 : GeomObject(other.d_name, other.d_description),
854 d_r(other.d_r),
855 d_a(other.d_a),
856 d_x(other.d_x),
857 d_vertices(other.d_vertices) {
858 d_tags = other.d_tags;
859 }
860
866 Triangle& operator=(const Triangle& other) {
867 if (this != &other) {
868 // Copy base class members
869 d_tags = other.d_tags;
870
871 // Copy member variables
872 d_r = other.d_r;
873 d_a = other.d_a;
874 d_x = other.d_x;
875 d_vertices = other.d_vertices;
876 }
877 return *this;
878 }
879
880 void transform(const util::Point &translation, const double &scale,
881 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
882 // Scale the radius
883 d_r *= scale;
884
885 const util::Point c0 = d_x;
886 for (auto &v : d_vertices) {
887 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
888 }
889 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
890 d_a = util::rotate(d_a, angle, axis);
891 }
892
896 double volume() const override;
897
901 util::Point center() const override;
902
906 std::pair<util::Point, util::Point> box() const override;
907
911 std::pair<util::Point, util::Point>
912 box(const double &tol) const override;
913
917 double inscribedRadius() const override;
918
922 double boundingRadius() const override;
923
932 bool isInside(const util::Point &x) const override;
933
937 bool isOutside(const util::Point &x) const override;
938
942 bool isNear(const util::Point &x, const double &tol) const override;
943
948 bool isNearBoundary(const util::Point &x, const double &tol,
949 const bool &within) const override;
950
954 bool doesIntersect(const util::Point &x) const override;
955
968 bool
969 isInside(
970 const std::pair<util::Point, util::Point> &box) const override;
971
976 bool
977 isOutside(
978 const std::pair<util::Point, util::Point> &box) const override;
979
984 bool isNear(const std::pair<util::Point, util::Point> &box,
985 const double &tol) const override;
986
991 bool doesIntersect(
992 const std::pair<util::Point, util::Point> &box) const override;
993
999 std::string printStr(int nt, int lvl) const override;
1000
1004 void print(int nt, int lvl) const override {
1005 std::cout << printStr(nt, lvl);
1006 };
1007
1011 void print() const override { print(0, 0); };
1012 };
1013
1017 class Square : public GeomObject {
1018
1019 public:
1021 std::vector<util::Point> d_vertices;
1022
1025
1027 double d_L;
1028
1030 double d_r;
1031
1032 public:
1037 : GeomObject("square", ""),
1038 d_L(0.),
1039 d_r(0.),
1040 d_x(util::Point()),
1041 d_vertices({
1044 }) {
1045 };
1046
1055 std::string description = "")
1056 : GeomObject("square", description),
1057 d_L(L),
1058 d_r(L / std::sqrt(2)),
1059 d_x(x),
1060 d_vertices({
1061 x + util::Point(-0.5 * L, -0.5 * L, 0.),
1062 x + util::Point(0.5 * L, -0.5 * L, 0.),
1063 x + util::Point(0.5 * L, 0.5 * L, 0.),
1064 x + util::Point(-0.5 * L, 0.5 * L, 0.)
1065 }) {
1066 };
1067
1075 Square(util::Point x1, util::Point x2, std::string description = "")
1076 : GeomObject("square", description),
1077 d_L((x1 - x2).length() * (1. / std::sqrt(2))),
1078 d_r((x1 - x2).length() / 2.),
1079 d_x(0.5 * (x1 + x2)) {
1080 d_vertices.push_back(x1);
1081 d_vertices.push_back(util::Point(x1.d_x + d_L, x1.d_y, x1.d_z));
1082 d_vertices.push_back(x2);
1083 d_vertices.push_back(util::Point(x2.d_x - d_L, x2.d_y, x2.d_z));
1084 };
1085
1090 Square(const Square &other)
1091 : GeomObject(other.d_name, other.d_description),
1092 d_L(other.d_L),
1093 d_r(other.d_r),
1094 d_x(other.d_x),
1095 d_vertices(other.d_vertices) {
1096 d_tags = other.d_tags;
1097 }
1098
1104 Square& operator=(const Square& other) {
1105 if (this != &other) {
1106 // Copy base class members
1107 d_tags = other.d_tags;
1108
1109 // Copy member variables
1110 d_L = other.d_L;
1111 d_r = other.d_r;
1112 d_x = other.d_x;
1113 d_vertices = other.d_vertices;
1114 }
1115 return *this;
1116 }
1117
1118 void transform(const util::Point &translation, const double &scale,
1119 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
1120 // Scale the dimensions
1121 d_L *= scale;
1122 d_r *= scale;
1123
1124 const util::Point c0 = d_x;
1125 for (auto &v : d_vertices) {
1126 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
1127 }
1128 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
1129 }
1130
1134 double volume() const override;
1135
1139 util::Point center() const override;
1140
1144 std::pair<util::Point, util::Point> box() const override;
1145
1149 std::pair<util::Point, util::Point>
1150 box(const double &tol) const override;
1151
1155 double inscribedRadius() const override;
1156
1160 double boundingRadius() const override;
1161
1170 bool isInside(const util::Point &x) const override;
1171
1175 bool isOutside(const util::Point &x) const override;
1176
1180 bool isNear(const util::Point &x, const double &tol) const override;
1181
1186 bool isNearBoundary(const util::Point &x, const double &tol,
1187 const bool &within) const override;
1188
1192 bool doesIntersect(const util::Point &x) const override;
1193
1205 bool
1206 isInside(
1207 const std::pair<util::Point, util::Point> &box) const override;
1208
1213 bool
1214 isOutside(
1215 const std::pair<util::Point, util::Point> &box) const override;
1216
1221 bool isNear(const std::pair<util::Point, util::Point> &box,
1222 const double &tol) const override;
1223
1228 bool doesIntersect(
1229 const std::pair<util::Point, util::Point> &box) const override;
1230
1236 std::string printStr(int nt, int lvl) const override;
1237
1241 void print(int nt, int lvl) const override {
1242 std::cout << printStr(nt, lvl);
1243 };
1244
1248 void print() const override { print(0, 0); };
1249 };
1250
1254 class Rectangle : public GeomObject {
1255 public:
1257 std::vector<util::Point> d_vertices;
1258
1261
1263 double d_Lx;
1264
1266 double d_Ly;
1267
1269 double d_r;
1270
1271 public:
1276 : GeomObject("rectangle", ""),
1277 d_Lx(0.),
1278 d_Ly(0.),
1279 d_r(0.),
1280 d_x(util::Point()),
1281 d_vertices({
1284 }) {
1285 };
1286
1295 Rectangle(double Lx, double Ly, util::Point x = util::Point(),
1296 std::string description = "")
1297 : GeomObject("rectangle", description),
1298 d_Lx(Lx),
1299 d_Ly(Ly),
1300 d_r(0.5 * std::sqrt(std::pow(Lx, 2) + std::pow(Ly, 2))),
1301 d_x(x) {
1302 d_vertices.push_back(
1303 x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, 0.));
1304 d_vertices.push_back(
1305 x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, 0.));
1306 d_vertices.push_back(x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, 0.));
1307 d_vertices.push_back(
1308 x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, 0.));
1309 };
1310
1315 Rectangle(const Rectangle &other)
1316 : GeomObject(other.d_name, other.d_description),
1317 d_Lx(other.d_Lx),
1318 d_Ly(other.d_Ly),
1319 d_r(other.d_r),
1320 d_x(other.d_x),
1321 d_vertices(other.d_vertices) {
1322 d_tags = other.d_tags;
1323 }
1324
1333 std::string description = "")
1334 : GeomObject("rectangle", description),
1335 d_Lx(x2.d_x - x1.d_x),
1336 d_Ly(x2.d_y - x1.d_y),
1337 d_r(0.5 *
1338 std::sqrt(std::pow(d_Lx, 2) + std::pow(d_Ly, 2))),
1339 d_x(0.5 * (x1 + x2)) {
1340 d_vertices.push_back(x1);
1341 d_vertices.push_back(util::Point(x1.d_x + d_Lx, x1.d_y, x1.d_z));
1342 d_vertices.push_back(x2);
1343 d_vertices.push_back(util::Point(x2.d_x - d_Lx, x2.d_y, x2.d_z));
1344 };
1345
1352 if (this != &other) {
1353 // Copy base class members
1354 d_tags = other.d_tags;
1355
1356 // Copy member variables
1357 d_Lx = other.d_Lx;
1358 d_Ly = other.d_Ly;
1359 d_r = other.d_r;
1360 d_x = other.d_x;
1361 d_vertices = other.d_vertices;
1362 }
1363 return *this;
1364 }
1365
1366
1367
1368 void transform(const util::Point &translation, const double &scale,
1369 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
1370 // Scale the dimensions
1371 d_Lx *= scale;
1372 d_Ly *= scale;
1373 d_r *= scale;
1374
1375 const util::Point c0 = d_x;
1376 for (auto &v : d_vertices) {
1377 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
1378 }
1379 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
1380 }
1381
1383 bool wallContactQuery(const util::Point &x,
1384 WallContactHit &hit) const override;
1385
1389 double volume() const override;
1390
1394 util::Point center() const override;
1395
1399 std::pair<util::Point, util::Point> box() const override;
1400
1404 std::pair<util::Point, util::Point>
1405 box(const double &tol) const override;
1406
1410 double inscribedRadius() const override;
1411
1415 double boundingRadius() const override;
1416
1425 bool isInside(const util::Point &x) const override;
1426
1430 bool isOutside(const util::Point &x) const override;
1431
1435 bool isNear(const util::Point &x, const double &tol) const override;
1436
1441 bool isNearBoundary(const util::Point &x, const double &tol,
1442 const bool &within) const override;
1443
1447 bool doesIntersect(const util::Point &x) const override;
1448
1460 bool
1461 isInside(
1462 const std::pair<util::Point, util::Point> &box) const override;
1463
1468 bool
1469 isOutside(
1470 const std::pair<util::Point, util::Point> &box) const override;
1471
1476 bool isNear(const std::pair<util::Point, util::Point> &box,
1477 const double &tol) const override;
1478
1483 bool doesIntersect(
1484 const std::pair<util::Point, util::Point> &box) const override;
1485
1491 std::string printStr(int nt, int lvl) const override;
1492
1496 void print(int nt, int lvl) const override {
1497 std::cout << printStr(nt, lvl);
1498 };
1499
1503 void print() const override { print(0, 0); };
1504 };
1505
1509 class Hexagon : public GeomObject {
1510 public:
1512 std::vector<util::Point> d_vertices;
1513
1516
1518 double d_r;
1519
1534
1535 public:
1540 : GeomObject("hexagon", ""),
1541 d_r(0.),
1542 d_a(util::Point(1., 0., 0.)),
1543 d_x(util::Point()),
1544 d_vertices(std::vector<util::Point>(6, util::Point())) {
1545 };
1546
1555 Hexagon(double r, util::Point x = util::Point(0., 0., 0.),
1556 util::Point a = util::Point(1., 0., 0.),
1557 std::string description = "")
1558 : GeomObject("hexagon", ""),
1559 d_r(r),
1560 d_a(a),
1561 d_x(x),
1562 d_vertices(std::vector<util::Point>(6, util::Point())) {
1563 // generate vertices
1564 auto rotate_axis = util::Point(0., 0., 1.); // z-axis
1565 for (int i = 0; i < 6; i++) {
1566 d_vertices[i] = d_x + d_r * util::rotate(
1567 d_a, i * M_PI / 3., rotate_axis);
1568 }
1569 };
1570
1575 Hexagon(const Hexagon &other)
1576 : GeomObject(other.d_name, other.d_description),
1577 d_r(other.d_r),
1578 d_a(other.d_a),
1579 d_x(other.d_x),
1580 d_vertices(other.d_vertices) {
1581 d_tags = other.d_tags;
1582 }
1583
1589 Hexagon& operator=(const Hexagon& other) {
1590 if (this != &other) {
1591 // Copy base class members
1592 d_tags = other.d_tags;
1593
1594 // Copy member variables
1595 d_r = other.d_r;
1596 d_a = other.d_a;
1597 d_x = other.d_x;
1598 d_vertices = other.d_vertices;
1599 }
1600 return *this;
1601 }
1602
1603 void transform(const util::Point &translation, const double &scale,
1604 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
1605 // Scale the radius
1606 d_r *= scale;
1607
1608 const util::Point c0 = d_x;
1609 for (auto &v : d_vertices) {
1610 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
1611 }
1612 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
1613 d_a = util::rotate(d_a, angle, axis);
1614 }
1615
1619 double volume() const override;
1620
1624 util::Point center() const override;
1625
1629 std::pair<util::Point, util::Point> box() const override;
1630
1634 std::pair<util::Point, util::Point>
1635 box(const double &tol) const override;
1636
1640 double inscribedRadius() const override;
1641
1645 double boundingRadius() const override;
1646
1655 bool isInside(const util::Point &x) const override;
1656
1660 bool isOutside(const util::Point &x) const override;
1661
1665 bool isNear(const util::Point &x, const double &tol) const override;
1666
1671 bool isNearBoundary(const util::Point &x, const double &tol,
1672 const bool &within) const override;
1673
1677 bool doesIntersect(const util::Point &x) const override;
1678
1692 bool
1693 isInside(
1694 const std::pair<util::Point, util::Point> &box) const override;
1695
1700 bool
1701 isOutside(
1702 const std::pair<util::Point, util::Point> &box) const override;
1703
1708 bool isNear(const std::pair<util::Point, util::Point> &box,
1709 const double &tol) const override;
1710
1715 bool doesIntersect(
1716 const std::pair<util::Point, util::Point> &box) const override;
1717
1723 std::string printStr(int nt, int lvl) const override;
1724
1728 void print(int nt, int lvl) const override {
1729 std::cout << printStr(nt, lvl);
1730 };
1731
1735 void print() const override { print(0, 0); };
1736 };
1737
1757 class Drum2D : public GeomObject {
1758 public:
1760 std::vector<util::Point> d_vertices;
1761
1764
1766 double d_w;
1767
1769 double d_r;
1770
1786
1787 public:
1792 : GeomObject("drum2d", ""),
1793 d_r(0.),
1794 d_w(0.),
1795 d_a(util::Point(1., 0., 0.)),
1796 d_x(util::Point()),
1797 d_vertices(std::vector<util::Point>(6, util::Point())) {
1798 };
1799
1810 Drum2D(double r, double w, util::Point x = util::Point(0., 0., 0.),
1811 util::Point a = util::Point(1., 0., 0.),
1812 std::string description = "")
1813 : GeomObject("drum2d", description),
1814 d_r(r),
1815 d_w(w),
1816 d_a(a),
1817 d_x(x),
1818 d_vertices(std::vector<util::Point>(6, util::Point())) {
1819 // generate vertices in the plane perpendicular to rotate_axis (z for axis a in xy)
1820 const util::Point rotate_axis(0., 0., 1.);
1821
1822 d_vertices[0] = d_x + d_w * d_a;
1823 d_vertices[3] = d_x - d_w * d_a;
1824
1825 d_vertices[1] = d_x + d_r * util::rotate(d_a, M_PI / 3., rotate_axis);
1826 /* Option 2 used (v1 - k*z_hat), which is not in the drum plane for a in xy and
1827 * breaks coplanarity (e.g. z != 0 on some corners) -> degenerate nodal volumes. */
1828 d_vertices[2] = d_x + d_r * util::rotate(d_a, 2. * M_PI / 3., rotate_axis);
1829
1830 d_vertices[4] = d_x + d_r * util::rotate(-1. * d_a, M_PI / 3., rotate_axis);
1831 d_vertices[5] = d_x + d_r * util::rotate(-1. * d_a, 2. * M_PI / 3., rotate_axis);
1832 };
1833
1839 Drum2D& operator=(const Drum2D& other) {
1840 if (this != &other) {
1841 // Copy base class members
1842 d_tags = other.d_tags;
1843
1844 // Copy member variables
1845 d_r = other.d_r;
1846 d_w = other.d_w;
1847 d_a = other.d_a;
1848 d_x = other.d_x;
1849 d_vertices = other.d_vertices;
1850 }
1851 return *this;
1852 }
1853
1854 void transform(const util::Point &translation, const double &scale,
1855 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
1856 // Scale the dimensions
1857 d_r *= scale;
1858 d_w *= scale;
1859
1860 const util::Point c0 = d_x;
1861 for (auto &v : d_vertices) {
1862 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
1863 }
1864 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
1865 d_a = util::rotate(d_a, angle, axis);
1866 }
1867
1871 double volume() const override;
1872
1876 util::Point center() const override;
1877
1881 std::pair<util::Point, util::Point> box() const override;
1882
1886 std::pair<util::Point, util::Point>
1887 box(const double &tol) const override;
1888
1892 double inscribedRadius() const override;
1893
1897 double boundingRadius() const override;
1898
1907 bool isInside(const util::Point &x) const override;
1908
1912 bool isOutside(const util::Point &x) const override;
1913
1917 bool isNear(const util::Point &x, const double &tol) const override;
1918
1923 bool isNearBoundary(const util::Point &x, const double &tol,
1924 const bool &within) const override;
1925
1929 bool doesIntersect(const util::Point &x) const override;
1930
1942 bool
1943 isInside(
1944 const std::pair<util::Point, util::Point> &box) const override;
1945
1950 bool
1951 isOutside(
1952 const std::pair<util::Point, util::Point> &box) const override;
1953
1958 bool isNear(const std::pair<util::Point, util::Point> &box,
1959 const double &tol) const override;
1960
1965 bool doesIntersect(
1966 const std::pair<util::Point, util::Point> &box) const override;
1967
1973 std::string printStr(int nt, int lvl) const override;
1974
1978 void print(int nt, int lvl) const override {
1979 std::cout << printStr(nt, lvl);
1980 };
1981
1985 void print() const override { print(0, 0); };
1986 };
1987
1991 class Cube : public GeomObject {
1992 public:
1994 std::vector<util::Point> d_vertices;
1995
1998
2000 double d_L;
2001
2003 double d_r;
2004
2005 public:
2010 : GeomObject("cube", ""),
2011 d_L(0.),
2012 d_r(0.),
2013 d_x(util::Point()),
2014 d_vertices(std::vector<util::Point>(8, util::Point())) {
2015 };
2016
2025 std::string description = "")
2026 : GeomObject("cube", description),
2027 d_L(L),
2028 d_r(0.5 * std::sqrt(3.) * L),
2029 d_x(x),
2030 d_vertices(std::vector<util::Point>(8, util::Point())) {
2031 // numbering assuming x - left-right, y - back-front, z - bottom-top
2032 // counterclockwise in bottom plane (i.e.,
2033 // 0 - left-back-bottom, 1 - right-back-bottom,
2034 // 2 - right-front-bottom, 3 - left-front-bottom
2035 // similarly, in top plane
2036 d_vertices[0] =
2037 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
2038 d_vertices[1] =
2039 d_x + util::Point(0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
2040 d_vertices[2] =
2041 d_x + util::Point(0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
2042 d_vertices[3] =
2043 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
2044
2045 d_vertices[4] =
2046 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
2047 d_vertices[5] =
2048 d_x + util::Point(0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
2049 d_vertices[6] =
2050 d_x + util::Point(0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
2051 d_vertices[7] =
2052 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
2053 };
2054
2059 Cube(const Cube &other)
2060 : GeomObject(other.d_name, other.d_description),
2061 d_L(other.d_L),
2062 d_r(other.d_r),
2063 d_x(other.d_x),
2064 d_vertices(other.d_vertices) {
2065 d_tags = other.d_tags;
2066 }
2067
2075 Cube(util::Point x1, util::Point x2, std::string description = "")
2076 : GeomObject("cube", description),
2077 d_L((x2 - x1).length() / std::sqrt(3.)),
2078 d_r(0.5 * (x2 - x1).length()),
2079 d_x(0.5 * (x1 + x2)),
2080 d_vertices(std::vector<util::Point>(8, util::Point())) {
2081 // numbering assuming x - left-right, y - back-front, z - bottom-top
2082 // counterclockwise in bottom plane (i.e.,
2083 // 0 - left-back-bottom, 1 - right-back-bottom,
2084 // 2 - right-front-bottom, 3 - left-front-bottom
2085 // similarly, in top plane
2086 d_vertices[0] =
2087 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
2088 d_vertices[1] =
2089 d_x + util::Point(0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
2090 d_vertices[2] =
2091 d_x + util::Point(0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
2092 d_vertices[3] =
2093 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
2094
2095 d_vertices[4] =
2096 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
2097 d_vertices[5] =
2098 d_x + util::Point(0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
2099 d_vertices[6] =
2100 d_x + util::Point(0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
2101 d_vertices[7] =
2102 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
2103 };
2104
2110 Cube& operator=(const Cube& other) {
2111 if (this != &other) {
2112 // Copy base class members
2113 d_tags = other.d_tags;
2114
2115 // Copy member variables
2116 d_L = other.d_L;
2117 d_r = other.d_r;
2118 d_x = other.d_x;
2119 d_vertices = other.d_vertices;
2120 }
2121 return *this;
2122 }
2123
2124
2125 void transform(const util::Point &translation, const double &scale,
2126 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
2127 // Scale the dimensions
2128 d_L *= scale;
2129 d_r *= scale;
2130
2131 const util::Point c0 = d_x;
2132 for (auto &v : d_vertices) {
2133 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
2134 }
2135 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
2136 }
2137
2141 double volume() const override;
2142
2146 util::Point center() const override;
2147
2151 std::pair<util::Point, util::Point> box() const override;
2152
2156 std::pair<util::Point, util::Point>
2157 box(const double &tol) const override;
2158
2162 double inscribedRadius() const override;
2163
2167 double boundingRadius() const override;
2168
2177 bool isInside(const util::Point &x) const override;
2178
2182 bool isOutside(const util::Point &x) const override;
2183
2187 bool isNear(const util::Point &x, const double &tol) const override;
2188
2193 bool isNearBoundary(const util::Point &x, const double &tol,
2194 const bool &within) const override;
2195
2199 bool doesIntersect(const util::Point &x) const override;
2200
2212 bool
2213 isInside(
2214 const std::pair<util::Point, util::Point> &box) const override;
2215
2220 bool
2221 isOutside(
2222 const std::pair<util::Point, util::Point> &box) const override;
2223
2228 bool isNear(const std::pair<util::Point, util::Point> &box,
2229 const double &tol) const override;
2230
2235 bool doesIntersect(
2236 const std::pair<util::Point, util::Point> &box) const override;
2237
2243 std::string printStr(int nt, int lvl) const override;
2244
2248 void print(int nt, int lvl) const override {
2249 std::cout << printStr(nt, lvl);
2250 };
2251
2255 void print() const override { print(0, 0); };
2256 };
2257
2261 class Cuboid : public GeomObject {
2262 public:
2264 std::vector<util::Point> d_vertices;
2265
2268
2270 double d_Lx;
2271
2273 double d_Ly;
2274
2276 double d_Lz;
2277
2279 double d_r;
2280
2281 public:
2286 : GeomObject("cuboid", ""),
2287 d_Lx(0.),
2288 d_Ly(0.),
2289 d_Lz(0.),
2290 d_r(0.),
2291 d_x(util::Point()),
2292 d_vertices(std::vector<util::Point>(8, util::Point())) {
2293 };
2294
2304 Cuboid(double Lx, double Ly, double Lz,
2306 std::string description = "")
2307 : GeomObject("cuboid", description),
2308 d_Lx(Lx),
2309 d_Ly(Ly),
2310 d_Lz(Lz),
2311 d_r(std::sqrt(std::pow(Lx, 2) + std::pow(Ly, 2) +
2312 std::pow(Lz, 2))),
2313 d_x(x),
2314 d_vertices(std::vector<util::Point>(8, util::Point())) {
2315 // numbering assuming x - left-right, y - back-front, z - bottom-top
2316 // counterclockwise in bottom plane (i.e.,
2317 // 0 - left-back-bottom, 1 - right-back-bottom,
2318 // 2 - right-front-bottom, 3 - left-front-bottom
2319 // similarly, in top plane
2320 d_vertices[0] =
2321 d_x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, -0.5 * d_Lz);
2322 d_vertices[1] =
2323 d_x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, -0.5 * d_Lz);
2324 d_vertices[2] =
2325 d_x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, -0.5 * d_Lz);
2326 d_vertices[3] =
2327 d_x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, -0.5 * d_Lz);
2328
2329 d_vertices[4] =
2330 d_x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, 0.5 * d_Lz);
2331 d_vertices[5] =
2332 d_x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, 0.5 * d_Lz);
2333 d_vertices[6] =
2334 d_x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, 0.5 * d_Lz);
2335 d_vertices[7] =
2336 d_x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, 0.5 * d_Lz);
2337 };
2338
2343 Cuboid(const Cuboid &other)
2344 : GeomObject(other.d_name, other.d_description),
2345 d_Lx(other.d_Lx),
2346 d_Ly(other.d_Ly),
2347 d_Lz(other.d_Lz),
2348 d_r(other.d_r),
2349 d_x(other.d_x),
2350 d_vertices(other.d_vertices) {
2351 d_tags = other.d_tags;
2352 }
2353
2361 Cuboid(util::Point x1, util::Point x2, std::string description = "")
2362 : GeomObject("cuboid", description),
2363 d_Lx(x2.d_x - x1.d_x),
2364 d_Ly(x2.d_y - x1.d_y),
2365 d_Lz(x2.d_z - x1.d_z),
2366 d_r(std::sqrt(
2367 std::pow(x2.d_x - x1.d_x, 2)
2368 + std::pow(x2.d_y - x1.d_y, 2)
2369 + std::pow(x2.d_z - x1.d_z, 2)
2370 )
2371 ),
2372 d_x(0.5 * (x1 + x2)),
2373 d_vertices(std::vector<util::Point>(8, util::Point())) {
2374 // numbering assuming x - left-right, y - back-front, z - bottom-top
2375 // counterclockwise in bottom plane (i.e.,
2376 // 0 - left-back-bottom, 1 - right-back-bottom,
2377 // 2 - right-front-bottom, 3 - left-front-bottom
2378 // similarly, in top plane
2379 d_vertices[0] =
2380 d_x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, -0.5 * d_Lz);
2381 d_vertices[1] =
2382 d_x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, -0.5 * d_Lz);
2383 d_vertices[2] =
2384 d_x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, -0.5 * d_Lz);
2385 d_vertices[3] =
2386 d_x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, -0.5 * d_Lz);
2387
2388 d_vertices[4] =
2389 d_x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, 0.5 * d_Lz);
2390 d_vertices[5] =
2391 d_x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, 0.5 * d_Lz);
2392 d_vertices[6] =
2393 d_x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, 0.5 * d_Lz);
2394 d_vertices[7] =
2395 d_x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, 0.5 * d_Lz);
2396 };
2397
2403 Cuboid& operator=(const Cuboid& other) {
2404 if (this != &other) {
2405 // Copy base class members
2406 d_tags = other.d_tags;
2407
2408 // Copy member variables
2409 d_Lx = other.d_Lx;
2410 d_Ly = other.d_Ly;
2411 d_Lz = other.d_Lz;
2412 d_r = other.d_r;
2413 d_x = other.d_x;
2414 d_vertices = other.d_vertices;
2415 }
2416 return *this;
2417 }
2418
2419 void transform(const util::Point &translation, const double &scale,
2420 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
2421 // Scale the dimensions
2422 d_Lx *= scale;
2423 d_Ly *= scale;
2424 d_Lz *= scale;
2425 d_r *= scale;
2426
2427 const util::Point c0 = d_x;
2428 for (auto &v : d_vertices) {
2429 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
2430 }
2431 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
2432 }
2433
2437 double volume() const override;
2438
2442 util::Point center() const override;
2443
2447 std::pair<util::Point, util::Point> box() const override;
2448
2452 std::pair<util::Point, util::Point>
2453 box(const double &tol) const override;
2454
2458 double inscribedRadius() const override;
2459
2463 double boundingRadius() const override;
2464
2473 bool isInside(const util::Point &x) const override;
2474
2478 bool isOutside(const util::Point &x) const override;
2479
2483 bool isNear(const util::Point &x, const double &tol) const override;
2484
2489 bool isNearBoundary(const util::Point &x, const double &tol,
2490 const bool &within) const override;
2491
2495 bool doesIntersect(const util::Point &x) const override;
2496
2508 bool
2509 isInside(
2510 const std::pair<util::Point, util::Point> &box) const override;
2511
2516 bool
2517 isOutside(
2518 const std::pair<util::Point, util::Point> &box) const override;
2519
2524 bool isNear(const std::pair<util::Point, util::Point> &box,
2525 const double &tol) const override;
2526
2531 bool doesIntersect(
2532 const std::pair<util::Point, util::Point> &box) const override;
2533
2539 std::string printStr(int nt, int lvl) const override;
2540
2544 void print(int nt, int lvl) const override {
2545 std::cout << printStr(nt, lvl);
2546 };
2547
2551 void print() const override { print(0, 0); };
2552 };
2553
2557 class Circle : public GeomObject {
2558 public:
2561
2563 double d_r;
2564
2565 public:
2570 : GeomObject("circle", ""),
2571 d_x(util::Point()),
2572 d_r(0.) {
2573 };
2574
2583 std::string description = "")
2584 : GeomObject("circle", description),
2585 d_x(x),
2586 d_r(r) {
2587 };
2588
2593 Circle(const Circle &other)
2594 : GeomObject(other.d_name, other.d_description),
2595 d_x(other.d_x),
2596 d_r(other.d_r) {
2597 d_tags = other.d_tags;
2598 }
2599
2605 Circle& operator=(const Circle& other) {
2606 if (this != &other) {
2607 // Copy base class members
2608 d_tags = other.d_tags;
2609
2610 // Copy member variables
2611 d_x = other.d_x;
2612 d_r = other.d_r;
2613 }
2614 return *this;
2615 }
2616
2617 void transform(const util::Point &translation, const double &scale,
2618 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
2619 const util::Point c0 = d_x;
2620 d_r *= scale;
2621 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
2622 }
2623
2627 double volume() const override;
2628
2632 util::Point center() const override;
2633
2637 std::pair<util::Point, util::Point> box() const override;
2638
2642 std::pair<util::Point, util::Point>
2643 box(const double &tol) const override;
2644
2648 double inscribedRadius() const override;
2649
2653 double boundingRadius() const override;
2654
2663 bool isInside(const util::Point &x) const override;
2664
2668 bool isOutside(const util::Point &x) const override;
2669
2673 bool isNear(const util::Point &x, const double &tol) const override;
2674
2679 bool isNearBoundary(const util::Point &x, const double &tol,
2680 const bool &within) const override;
2681
2685 bool doesIntersect(const util::Point &x) const override;
2686
2698 bool
2699 isInside(
2700 const std::pair<util::Point, util::Point> &box) const override;
2701
2706 bool
2707 isOutside(
2708 const std::pair<util::Point, util::Point> &box) const override;
2709
2714 bool isNear(const std::pair<util::Point, util::Point> &box,
2715 const double &tol) const override;
2716
2721 bool doesIntersect(
2722 const std::pair<util::Point, util::Point> &box) const override;
2723
2729 std::string printStr(int nt, int lvl) const override;
2730
2734 void print(int nt, int lvl) const override {
2735 std::cout << printStr(nt, lvl);
2736 };
2737
2741 void print() const override { print(0, 0); };
2742 };
2743
2747 class Ellipse : public GeomObject {
2748 public:
2751
2753 double d_a;
2754
2756 double d_b;
2757
2759 double d_theta;
2760
2761 public:
2763 : GeomObject("ellipse", ""),
2764 d_x(util::Point()),
2765 d_a(0.),
2766 d_b(0.),
2767 d_theta(0.) {};
2768
2775 Ellipse(double a, double b, double theta, util::Point x = util::Point(),
2776 std::string description = "")
2777 : GeomObject("ellipse", description),
2778 d_x(x),
2779 d_a(a),
2780 d_b(b),
2781 d_theta(theta) {};
2782
2783 Ellipse(const Ellipse &other)
2784 : GeomObject(other.d_name, other.d_description),
2785 d_x(other.d_x),
2786 d_a(other.d_a),
2787 d_b(other.d_b),
2788 d_theta(other.d_theta) {
2789 d_tags = other.d_tags;
2790 }
2791
2792 Ellipse &operator=(const Ellipse &other) {
2793 if (this != &other) {
2794 d_tags = other.d_tags;
2795 d_x = other.d_x;
2796 d_a = other.d_a;
2797 d_b = other.d_b;
2798 d_theta = other.d_theta;
2799 }
2800 return *this;
2801 }
2802
2803 void transform(const util::Point &translation, const double &scale, const double &angle,
2804 const util::Point &axis, const util::Point *rotationPoint) override {
2805 const util::Point c0 = d_x;
2806 // Assumption: axis of rotation is the z-axis; d_theta is in-plane on top of world map
2807 d_a *= scale;
2808 d_b *= scale;
2809 d_theta += angle;
2810 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
2811 }
2812
2813 double volume() const override;
2814 util::Point center() const override;
2815 std::pair<util::Point, util::Point> box() const override;
2816 std::pair<util::Point, util::Point> box(const double &tol) const override;
2817 double inscribedRadius() const override;
2818 double boundingRadius() const override;
2819
2820 bool isInside(const util::Point &x) const override;
2821 bool isOutside(const util::Point &x) const override;
2822 bool isNear(const util::Point &x, const double &tol) const override;
2823 bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override;
2824 bool doesIntersect(const util::Point &x) const override;
2825
2826 bool isInside(const std::pair<util::Point, util::Point> &box) const override;
2827 bool isOutside(const std::pair<util::Point, util::Point> &box) const override;
2828 bool isNear(const std::pair<util::Point, util::Point> &box, const double &tol) const override;
2829 bool doesIntersect(const std::pair<util::Point, util::Point> &box) const override;
2830
2831 std::string printStr(int nt, int lvl) const override;
2832 void print(int nt, int lvl) const override { std::cout << printStr(nt, lvl); };
2833 void print() const override { print(0, 0); };
2834 };
2835
2839 class Sphere : public GeomObject {
2840 public:
2843
2845 double d_r;
2846
2847 public:
2852 : GeomObject("sphere", ""),
2853 d_x(util::Point()),
2854 d_r(0.) {
2855 };
2856
2865 std::string description = "")
2866 : GeomObject("sphere", description),
2867 d_x(x),
2868 d_r(r) {
2869 };
2870
2875 Sphere(const Sphere &other)
2876 : GeomObject(other.d_name, other.d_description),
2877 d_x(other.d_x),
2878 d_r(other.d_r) {
2879 d_tags = other.d_tags;
2880 }
2881
2887 Sphere& operator=(const Sphere& other) {
2888 if (this != &other) {
2889 // Copy base class members
2890 d_tags = other.d_tags;
2891
2892 // Copy member variables
2893 d_x = other.d_x;
2894 d_r = other.d_r;
2895 }
2896 return *this;
2897 }
2898
2899 void transform(const util::Point &translation, const double &scale,
2900 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
2901 const util::Point c0 = d_x;
2902 d_r *= scale;
2903 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
2904 }
2905
2909 double volume() const override;
2910
2914 util::Point center() const override;
2915
2919 std::pair<util::Point, util::Point> box() const override;
2920
2924 std::pair<util::Point, util::Point>
2925 box(const double &tol) const override;
2926
2930 double inscribedRadius() const override;
2931
2935 double boundingRadius() const override;
2936
2945 bool isInside(const util::Point &x) const override;
2946
2950 bool isOutside(const util::Point &x) const override;
2951
2955 bool isNear(const util::Point &x, const double &tol) const override;
2956
2961 bool isNearBoundary(const util::Point &x, const double &tol,
2962 const bool &within) const override;
2963
2967 bool doesIntersect(const util::Point &x) const override;
2968
2980 bool
2981 isInside(
2982 const std::pair<util::Point, util::Point> &box) const override;
2983
2988 bool
2989 isOutside(
2990 const std::pair<util::Point, util::Point> &box) const override;
2991
2996 bool isNear(const std::pair<util::Point, util::Point> &box,
2997 const double &tol) const override;
2998
3003 bool doesIntersect(
3004 const std::pair<util::Point, util::Point> &box) const override;
3005
3011 std::string printStr(int nt, int lvl) const override;
3012
3016 void print(int nt, int lvl) const override {
3017 std::cout << printStr(nt, lvl);
3018 };
3019
3023 void print() const override { print(0, 0); };
3024 };
3025
3031 class Ellipsoid : public GeomObject {
3032 public:
3034 double d_a;
3035 double d_b;
3036 double d_c;
3040 double d_theta;
3041
3042 public:
3044 : GeomObject("ellipsoid", ""),
3045 d_x(util::Point()),
3046 d_a(0.),
3047 d_b(0.),
3048 d_c(0.),
3049 d_axis(0., 0., 1.),
3050 d_theta(0.) {};
3051
3057 Ellipsoid(double a, double b, double c, util::Point x = util::Point(),
3058 std::string description = "")
3059 : GeomObject("ellipsoid", description),
3060 d_x(x),
3061 d_a(a),
3062 d_b(b),
3063 d_c(c),
3064 d_axis(0., 0., 1.),
3065 d_theta(0.) {};
3066
3071 Ellipsoid(double a, double b, double c, double theta, util::Point x, util::Point axis,
3072 std::string description = "")
3073 : GeomObject("ellipsoid", description),
3074 d_x(x),
3075 d_a(a),
3076 d_b(b),
3077 d_c(c),
3078 d_axis(axis),
3079 d_theta(theta) {
3080
3081 if (std::abs(theta) > 1.0e-12 and axis.length() > 1.0e-12) {
3082 d_axis = axis / axis.length();
3083 }
3084 }
3085
3086 Ellipsoid(const Ellipsoid &other)
3087 : GeomObject(other.d_name, other.d_description),
3088 d_x(other.d_x),
3089 d_a(other.d_a),
3090 d_b(other.d_b),
3091 d_c(other.d_c),
3092 d_axis(other.d_axis),
3093 d_theta(other.d_theta) {
3094 d_tags = other.d_tags;
3095 }
3096
3098 if (this != &other) {
3099 d_tags = other.d_tags;
3100 d_x = other.d_x;
3101 d_a = other.d_a;
3102 d_b = other.d_b;
3103 d_c = other.d_c;
3104 d_axis = other.d_axis;
3105 d_theta = other.d_theta;
3106 }
3107 return *this;
3108 }
3109
3110 void transform(const util::Point &translation, const double &scale, const double &angle,
3111 const util::Point &axis, const util::Point *rotationPoint) override;
3112
3113 double volume() const override;
3114 util::Point center() const override;
3115 std::pair<util::Point, util::Point> box() const override;
3116 std::pair<util::Point, util::Point> box(const double &tol) const override;
3117 double inscribedRadius() const override;
3118 double boundingRadius() const override;
3119
3120 bool isInside(const util::Point &x) const override;
3121 bool isOutside(const util::Point &x) const override;
3122 bool isNear(const util::Point &x, const double &tol) const override;
3123 bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override;
3124 bool doesIntersect(const util::Point &x) const override;
3125
3126 bool isInside(const std::pair<util::Point, util::Point> &box) const override;
3127 bool isOutside(const std::pair<util::Point, util::Point> &box) const override;
3128 bool isNear(const std::pair<util::Point, util::Point> &box, const double &tol) const override;
3129 bool doesIntersect(const std::pair<util::Point, util::Point> &box) const override;
3130
3131 std::string printStr(int nt, int lvl) const override;
3132 void print(int nt, int lvl) const override { std::cout << printStr(nt, lvl); };
3133 void print() const override { print(0, 0); };
3134 };
3135
3139 class Cylinder : public GeomObject {
3140 public:
3143
3146
3149
3151 double d_r;
3152
3154 double d_l;
3155
3156 public:
3161 : GeomObject("cylinder", ""),
3162 d_xBegin(util::Point()),
3163 d_xa(util::Point(1., 1., 1.)),
3164 d_r(0.),
3165 d_l(0.),
3166 d_x(util::Point()) {
3167 };
3168
3178 Cylinder(double r, double l, util::Point x_begin, util::Point xa,
3179 std::string description = "")
3180 : GeomObject("cylinder", description),
3181 d_xBegin(x_begin),
3182 d_xa(xa / xa.length()),
3183 d_r(r),
3184 d_l(l),
3185 d_x(x_begin + 0.5 * l * (xa / xa.length())) {
3186 };
3187
3197 Cylinder(double r, util::Point x_begin, util::Point xa,
3198 std::string description = "")
3199 : GeomObject("cylinder", description),
3200 d_xBegin(x_begin),
3201 d_xa(xa / xa.length()),
3202 d_r(r),
3203 d_l(xa.length()),
3204 d_x(x_begin + 0.5 * xa) {};
3205
3210 Cylinder(const Cylinder &other)
3211 : GeomObject(other.d_name, other.d_description),
3212 d_xBegin(other.d_xBegin),
3213 d_xa(other.d_xa),
3214 d_r(other.d_r),
3215 d_l(other.d_l),
3216 d_x(other.d_x) {
3217 d_tags = other.d_tags;
3218 }
3219
3225 Cylinder& operator=(const Cylinder& other) {
3226 if (this != &other) {
3227 // Copy base class members
3228 d_tags = other.d_tags;
3229
3230 // Copy member variables
3231 d_xBegin = other.d_xBegin;
3232 d_xa = other.d_xa;
3233 d_r = other.d_r;
3234 d_l = other.d_l;
3235 d_x = other.d_x;
3236 }
3237 return *this;
3238 }
3239
3240 void transform(const util::Point &translation, const double &scale,
3241 const double &angle, const util::Point &axis, const util::Point *rotationPoint) override {
3242 // Scale the dimensions
3243 d_r *= scale;
3244 d_l *= scale;
3245
3246 const util::Point c0 = d_x;
3247 d_xBegin = mapSimilarity(d_xBegin, c0, translation, scale, angle, axis, rotationPoint);
3248 d_xa = util::rotate(d_xa, angle, axis);
3249 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
3250 }
3251
3255 double volume() const override;
3256
3260 util::Point center() const override;
3261
3265 std::pair<util::Point, util::Point> box() const override;
3266
3270 std::pair<util::Point, util::Point>
3271 box(const double &tol) const override;
3272
3276 double inscribedRadius() const override;
3277
3281 double boundingRadius() const override;
3282
3291 bool isInside(const util::Point &x) const override;
3292
3296 bool isOutside(const util::Point &x) const override;
3297
3301 bool isNear(const util::Point &x, const double &tol) const override;
3302
3307 bool isNearBoundary(const util::Point &x, const double &tol,
3308 const bool &within) const override;
3309
3313 bool doesIntersect(const util::Point &x) const override;
3314
3326 bool
3327 isInside(
3328 const std::pair<util::Point, util::Point> &box) const override;
3329
3334 bool
3335 isOutside(
3336 const std::pair<util::Point, util::Point> &box) const override;
3337
3342 bool isNear(const std::pair<util::Point, util::Point> &box,
3343 const double &tol) const override;
3344
3349 bool doesIntersect(
3350 const std::pair<util::Point, util::Point> &box) const override;
3351
3357 std::string printStr(int nt, int lvl) const override;
3358
3362 void print(int nt, int lvl) const override {
3363 std::cout << printStr(nt, lvl);
3364 };
3365
3369 void print() const override { print(0, 0); };
3370 };
3371} // namespace geom
3372
3373#endif // GEOM_GEOMOBJECTS_H
Defines circle.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
void print(int nt, int lvl) const override
Prints the information about the object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
util::Point center() const override
Computes the center of object.
double d_r
Radius.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
util::Point d_x
Center.
Circle(const Circle &other)
Copy constructor.
Circle & operator=(const Circle &other)
Assignment operator.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
void print() const override
Prints the information about the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Circle()
Constructor.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
Circle(double r, util::Point x=util::Point(), std::string description="")
Constructor.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
Defines cube.
util::Point center() const override
Computes the center of object.
void print(int nt, int lvl) const override
Prints the information about the object.
util::Point d_x
Center.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
Cube(const Cube &other)
Copy constructor.
Cube()
Constructor.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
double d_r
Radius of bounding circle.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Cube & operator=(const Cube &other)
Assignment operator.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
Cube(util::Point x1, util::Point x2, std::string description="")
Constructor.
Cube(double L, util::Point x=util::Point(), std::string description="")
Constructor.
std::vector< util::Point > d_vertices
Vertices.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
void print() const override
Prints the information about the object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
double d_L
Edge length of cube.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
Defines cuboid.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
double d_Ly
Edge length of cuboid in y-direction.
Cuboid(double Lx, double Ly, double Lz, util::Point x=util::Point(), std::string description="")
Constructor.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
Cuboid()
Constructor.
std::vector< util::Point > d_vertices
Vertices.
util::Point center() const override
Computes the center of object.
double d_Lx
Edge length of cuboid in x-direction.
Cuboid(const Cuboid &other)
Copy constructor.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
void print(int nt, int lvl) const override
Prints the information about the object.
util::Point d_x
Center.
Cuboid & operator=(const Cuboid &other)
Assignment operator.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
double d_r
Radius of bounding circle.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
Cuboid(util::Point x1, util::Point x2, std::string description="")
Constructor.
double d_Lz
Edge length of cuboid in z-direction.
void print() const override
Prints the information about the object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
Defines cylinder.
void print(int nt, int lvl) const override
Prints the information about the object.
Cylinder()
Constructor.
void print() const override
Prints the information about the object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
Cylinder(const Cylinder &other)
Copy constructor.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
util::Point d_xBegin
Center point of cross-section at the beginning.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
util::Point d_xa
Axis of cylinder (unit vector)
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Cylinder & operator=(const Cylinder &other)
Assignment operator.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
double d_l
Length.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
Cylinder(double r, double l, util::Point x_begin, util::Point xa, std::string description="")
Constructor.
Cylinder(double r, util::Point x_begin, util::Point xa, std::string description="")
Constructor.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
util::Point d_x
Center.
util::Point center() const override
Computes the center of object.
double d_r
Radius.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
Defines Drum2D.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
util::Point center() const override
Computes the center of object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
void print(int nt, int lvl) const override
Prints the information about the object.
void print() const override
Prints the information about the object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
Drum2D(double r, double w, util::Point x=util::Point(0., 0., 0.), util::Point a=util::Point(1., 0., 0.), std::string description="")
Constructor.
util::Point d_a
Axis: defined as the vector pointing from center to the first vertex v3 v2.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
Drum2D & operator=(const Drum2D &other)
Assignment operator.
std::vector< util::Point > d_vertices
Vertices.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
double d_r
Distance between center and the farthest vertex.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
double d_w
Half width of neck.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Drum2D()
Constructor.
util::Point d_x
Center.
Filled ellipse in the plane z = center.d_z, semi-axes in the xy plane.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
double d_a
Semi-axis along local x before rotation (in-plane)
void print(int nt, int lvl) const override
Prints the information about the object.
util::Point center() const override
Computes the center of object.
util::Point d_x
Center.
double d_b
Semi-axis along local y before rotation (in-plane)
void print() const override
Prints the information about the object.
double d_theta
Counter-clockwise rotation about +z through the center (radians)
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
Ellipse(const Ellipse &other)
Ellipse & operator=(const Ellipse &other)
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
Ellipse(double a, double b, double theta, util::Point x=util::Point(), std::string description="")
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
Checks if point is within given distance of this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
Ellipsoid: center , semi-axes in a body frame rotated from world by axis–angle (Rodrigues)....
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
double d_theta
Rotation angle (radians) about d_axis.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
util::Point center() const override
Computes the center of object.
Ellipsoid(double a, double b, double c, util::Point x=util::Point(), std::string description="")
Ellipsoid & operator=(const Ellipsoid &other)
Ellipsoid(double a, double b, double c, double theta, util::Point x, util::Point axis, std::string description="")
General orientation: same semi-axes, rotation about unit axis (normalized internally; zero axis with...
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
util::Point d_x
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
util::Point d_axis
Unit rotation axis (axis–angle); default (0,0,1) when .
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
Checks if point is within given distance of this object.
void print(int nt, int lvl) const override
Prints the information about the object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
void print() const override
Prints the information about the object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
Ellipsoid(const Ellipsoid &other)
Defines abstract geometrical domain.
virtual std::pair< util::Point, util::Point > box() const
Computes the bounding box of object.
virtual bool isOutside(const std::pair< util::Point, util::Point > &box) const
Checks if box is outside of the object.
virtual bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const
Checks if point is within given distance of this object.
virtual bool doesIntersect(const std::pair< util::Point, util::Point > &box) const
Checks if box intersects this object.
virtual bool isOutside(const util::Point &x) const
Checks if point is outside of this object.
virtual void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint=nullptr)
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
virtual bool isNear(const util::Point &x, const double &tol) const
Checks if point is within given distance of this object.
std::vector< std::string > d_tags
Tags/attributes about the object.
virtual void print(int nt, int lvl) const
Prints the information about the object.
virtual bool isInside(const std::pair< util::Point, util::Point > &box) const
Checks if box is completely inside.
virtual std::pair< util::Point, util::Point > box(const double &tol) const
Computes the bounding box of object.
virtual std::string printStr(int nt, int lvl) const
Returns the string containing printable information about the object.
virtual bool isInside(const util::Point &x) const
Checks if point is inside this object.
virtual bool doesIntersect(const util::Point &x) const
Checks if point lies exactly on the boundary.
virtual double volume() const
Computes the volume (area in 2d, length in 1d) of object.
virtual util::Point center() const
Computes the center of object.
virtual bool wallContactQuery(const util::Point &x, WallContactHit &hit) const
Closest-point / signed-gap query for analytical wall contact. Default: unsupported (returns false,...
virtual bool isNear(const std::pair< util::Point, util::Point > &box, const double &tol) const
Checks if box is within given distance of this object.
GeomObject(std::string name="", std::string description="")
Constructor.
const std::string d_name
name of object
virtual double boundingRadius() const
Computes the radius of smallest circle/sphere such that object can be fit into it.
virtual double inscribedRadius() const
Computes the radius of biggest circle/sphere completely within the object.
const std::string d_description
Further description of object.
virtual void print() const
Prints the information about the object.
Defines Hexagon.
void print(int nt, int lvl) const override
Prints the information about the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
util::Point d_x
Center.
Hexagon(double r, util::Point x=util::Point(0., 0., 0.), util::Point a=util::Point(1., 0., 0.), std::string description="")
Constructor.
Hexagon(const Hexagon &other)
Copy constructor.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
void print() const override
Prints the information about the object.
Hexagon()
Constructor.
Hexagon & operator=(const Hexagon &other)
Assignment operator.
util::Point center() const override
Computes the center of object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
util::Point d_a
Axis: defined as the vector pointing from center to the first vertex.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
double d_r
Distance between center and the farthest vertex of hexagon.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
std::vector< util::Point > d_vertices
Vertices.
Defines Line.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
std::vector< util::Point > d_vertices
Vertices.
Line(double L, util::Point x=util::Point(), std::string description="")
Constructor.
Line & operator=(const Line &other)
Assignment operator.
double d_r
Radius of bounding circle.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool wallContactQuery(const util::Point &x, WallContactHit &hit) const override
util::Point center() const override
Computes the center of object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
Line(const Line &other)
Copy constructor.
Line()
Constructor.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
void print(int nt, int lvl) const override
Prints the information about the object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double d_L
Length of line.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
void print() const override
Prints the information about the object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Line(util::Point x1, util::Point x2, std::string description="")
Constructor.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
util::Point d_x
Center.
Defines null (empty) geom object.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
NullGeomObject(const NullGeomObject &other)
Copy constructor.
void print() const override
Prints the information about the object.
virtual std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
NullGeomObject(std::string description="")
Constructor.
void print(int nt, int lvl) const override
Prints the information about the object.
NullGeomObject & operator=(const NullGeomObject &other)
Assignment operator.
Infinite plane: free space is the half-space in the normal direction.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &) const override
Checks if point is within given distance of this object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
Plane(util::Point n, util::Point p, std::string description="")
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
util::Point d_p
a point on the plane
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
util::Point center() const override
Computes the center of object.
Plane(const Plane &other)
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
Plane & operator=(const Plane &other)
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
std::pair< util::Point, util::Point > box(const double &tol) const override
Computes the bounding box of object.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
void print() const override
Prints the information about the object.
util::Point d_n
outward (free-space) normal, stored unit-length when possible
void print(int nt, int lvl) const override
Prints the information about the object.
bool wallContactQuery(const util::Point &x, WallContactHit &hit) const override
Closest-point / signed-gap query for analytical wall contact. Default: unsupported (returns false,...
Defines Rectangle.
std::vector< util::Point > d_vertices
Vertices.
Rectangle(const Rectangle &other)
Copy constructor.
Rectangle(util::Point x1, util::Point x2, std::string description="")
Constructor.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
Rectangle(double Lx, double Ly, util::Point x=util::Point(), std::string description="")
Constructor.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
double d_r
Radius of bounding circle.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
void print(int nt, int lvl) const override
Prints the information about the object.
bool wallContactQuery(const util::Point &x, WallContactHit &hit) const override
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
void print() const override
Prints the information about the object.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
Rectangle & operator=(const Rectangle &other)
Assignment operator.
double d_Lx
Edge length of a rectangle in x-direction.
double d_Ly
Edge length of a rectangle in y-direction.
util::Point center() const override
Computes the center of object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
Rectangle()
Constructor.
util::Point d_x
Center.
Defines sphere.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
Sphere()
Constructor.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
void print(int nt, int lvl) const override
Prints the information about the object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
double d_r
Radius.
util::Point d_x
Center.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
void print() const override
Prints the information about the object.
util::Point center() const override
Computes the center of object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
Sphere(const Sphere &other)
Copy constructor.
Sphere(double r, util::Point x=util::Point(), std::string description="")
Constructor.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
Sphere & operator=(const Sphere &other)
Assignment operator.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
Defines Square.
util::Point center() const override
Computes the center of object.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Square()
Constructor.
Square & operator=(const Square &other)
Assignment operator.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
Square(util::Point x1, util::Point x2, std::string description="")
Constructor.
Square(double L, util::Point x=util::Point(), std::string description="")
Constructor.
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
std::vector< util::Point > d_vertices
Vertices.
void print(int nt, int lvl) const override
Prints the information about the object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
util::Point d_x
Center.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
double d_L
Edge length of a square.
double d_r
Radius of bounding circle.
void print() const override
Prints the information about the object.
Square(const Square &other)
Copy constructor.
Defines Triangle.
void print() const override
Prints the information about the object.
Triangle(double r, util::Point x=util::Point(0., 0., 0.), util::Point a=util::Point(1., 0., 0.), std::string description="uniform")
Constructor.
Triangle(util::Point v0, util::Point v1, util::Point v2, std::string description="vertices")
Constructor from three vertices (arbitrary triangle, e.g. a V-notch). Params in decks: x1,...
util::Point d_x
Center.
util::Point d_a
Axis: defined as the vector pointing from center to the first vertex v2 +.
void print(int nt, int lvl) const override
Prints the information about the object.
std::vector< util::Point > d_vertices
Vertices.
util::Point center() const override
Computes the center of object.
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.
void transform(const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
Similarity about pivot (default: old center d_x), then rigid displacement = translation: ....
bool isOutside(const util::Point &x) const override
Checks if point is outside of this object.
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
bool doesIntersect(const util::Point &x) const override
Checks if point lies exactly on the boundary.
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Triangle()
Constructor.
double boundingRadius() const override
Computes the radius of smallest circle/sphere such that object can be fit into it.
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
Triangle & operator=(const Triangle &other)
Assignment operator.
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.
double d_r
Distance between center and the farthest vertex of triangle.
Triangle(const Triangle &other)
Copy constructor.
util::Point mapSimilarity(const util::Point &x, const util::Point &pivotDefault, const util::Point &t, double scale, double angle, const util::Point &axis, const util::Point *rotationPoint)
Definition geomObjects.h:55
const std::map< std::string, size_t > geom_type_to_dim
Geometry type to dimension map.
Definition geomObjects.h:27
size_t getGeomTypeToDim(std::string type)
Returns list of acceptable geometries for PeriDEM simulation.
Definition geomObjects.h:47
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:82
Collection of methods useful in simulation.
Definition constants.h:14
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:17
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:22
util::Point rotate(const util::Point &p, const double &theta, const util::Point &axis)
Returns the vector after rotating by desired angle.
Defines simple rectangle domain.
Definition geomObjects.h:65
bool isNear(const BoxPartition &box, const double &tol) const
Definition geomObjects.h:76
bool isNear(const util::Point &x, const double &tol) const
Definition geomObjects.h:81
std::pair< util::Point, util::Point > d_box
Definition geomObjects.h:68
util::Point d_xc
Definition geomObjects.h:67
void addNode(const size_t &i)
Definition geomObjects.h:94
std::vector< size_t > d_nodes
Definition geomObjects.h:70
Result of a wall-contact query against a geom (analytical walls).
util::Point outward_n
A structure to represent 3d vectors.
Definition point.h:30
double d_y
the y coordinate
Definition point.h:36
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94
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 d_x
the x coordinate
Definition point.h:33