PeriDyno 1.0.0
Loading...
Searching...
No Matches
Primitive3D.h
Go to the documentation of this file.
1#pragma once
12
13#include "Vector.h"
14#include "Matrix.h"
15#include "Quat.h"
16
17// Temporary code, to be removed in the
18namespace px
19{
25
26 struct Sphere3D
27 {
28 float radius;
30 };
31
32 struct Box
33 {
35 {
36 center = dyno::Vec3f(0.0f, 0.0f, 0.0f);
37 halfLength = dyno::Vec3f(1.0f, 1.0f, 1.0f);
38 rot = dyno::Quat1f(1.0f, 0.0f, 0.0f, 0.0f);
39 }
40
43
45 };
46
47 struct alignas(16) Sphere
48 {
50 glm::vec3 center;
51 float radius;
52 };
53
54 struct alignas(16) Capsule
55 {
59 float radius;
60 };
61
67}
68
69namespace dyno
70{
75 template <typename Real> class TPoint3D;
76
81 template <typename Real> class TLine3D;
82 template <typename Real> class TRay3D;
83 template <typename Real> class TSegment3D;
84
89 template <typename Real> class TPlane3D;
90 template <typename Real> class TTriangle3D;
91 template <typename Real> class TRectangle3D;
92 template <typename Real> class TDisk3D;
93
98 template <typename Real> class TSphere3D;
99 template <typename Real> class TCapsule3D;
100 template <typename Real> class TTet3D;
101 template <typename Real> class TAlignedBox3D;
102 template <typename Real> class TOrientedBox3D;
103 template <typename Real> class TCylinder3D;
104 template <typename Real> class TCone3D;
105 template <typename Real> class TGrid3D;
106
107 template<typename Real>
109 {
110 public:
113
114 public:
115 DYN_FUNC TPoint3D();
116 DYN_FUNC TPoint3D(const Real& c0, const Real& c1, const Real& c2);
117 DYN_FUNC TPoint3D(const TPoint3D& pt);
118
119 DYN_FUNC TPoint3D& operator = (const Coord3D& p);
120
121 explicit DYN_FUNC TPoint3D(const Real& val);
122 explicit DYN_FUNC TPoint3D(const Coord3D& pos);
123
124
131 DYN_FUNC TPoint3D<Real> project(const TLine3D<Real>& line) const;
132 DYN_FUNC TPoint3D<Real> project(const TRay3D<Real>& ray) const;
133 DYN_FUNC TPoint3D<Real> project(const TSegment3D<Real>& segment) const;
140 DYN_FUNC TPoint3D<Real> project(const TPlane3D<Real>& plane) const;
141 DYN_FUNC TPoint3D<Real> project(const TTriangle3D<Real>& triangle) const;
142 DYN_FUNC TPoint3D<Real> project(const TRectangle3D<Real>& rectangle) const;
143 DYN_FUNC TPoint3D<Real> project(const TDisk3D<Real>& disk) const;
150 DYN_FUNC TPoint3D<Real> project(const TSphere3D<Real>& sphere) const;
151 DYN_FUNC TPoint3D<Real> project(const TCapsule3D<Real>& capsule) const;
152 DYN_FUNC TPoint3D<Real> project(const TTet3D<Real>& tet) const;
153 DYN_FUNC TPoint3D<Real> project(const TAlignedBox3D<Real>& abox) const;
154 DYN_FUNC TPoint3D<Real> project(const TOrientedBox3D<Real>& obb) const;
155
156 DYN_FUNC TPoint3D<Real> project(const TSphere3D<Real>& sphere, Bool& bInside) const;
157 DYN_FUNC TPoint3D<Real> project(const TCapsule3D<Real>& capsule, Bool& bInside) const;
158 DYN_FUNC TPoint3D<Real> project(const TTet3D<Real>& tet, Bool& bInside) const;
159 DYN_FUNC TPoint3D<Real> project(const TTet3D<Real>& tet, Bool& bInside, int* idx) const;
160 DYN_FUNC TPoint3D<Real> project(const TAlignedBox3D<Real>& abox, Bool& bInside) const;
161 DYN_FUNC TPoint3D<Real> project(const TOrientedBox3D<Real>& obb, Bool& bInside) const;
162
163
164
165 DYN_FUNC Real distance(const TPoint3D<Real>& pt) const;
166 DYN_FUNC Real distance(const TLine3D<Real>& line) const;
167 DYN_FUNC Real distance(const TRay3D<Real>& ray) const;
168 DYN_FUNC Real distance(const TSegment3D<Real>& segment) const;
175 DYN_FUNC Real distance(const TPlane3D<Real>& plane) const;
176 DYN_FUNC Real distance(const TTriangle3D<Real>& triangle) const;
177 DYN_FUNC Real distance(const TRectangle3D<Real>& rectangle) const;
178 DYN_FUNC Real distance(const TDisk3D<Real>& disk) const;
179
186 DYN_FUNC Real distance(const TSphere3D<Real>& sphere) const;
187 DYN_FUNC Real distance(const TCapsule3D<Real>& capsule) const;
188 DYN_FUNC Real distance(const TTet3D<Real>& tet) const;
189 DYN_FUNC Real distance(const TAlignedBox3D<Real>& abox) const;
190 DYN_FUNC Real distance(const TOrientedBox3D<Real>& obb) const;
191
192
193
194 DYN_FUNC Real distanceSquared(const TPoint3D<Real>& pt) const;
195 DYN_FUNC Real distanceSquared(const TLine3D<Real>& line) const;
196 DYN_FUNC Real distanceSquared(const TRay3D<Real>& ray) const;
197 DYN_FUNC Real distanceSquared(const TSegment3D<Real>& segment) const;
204 DYN_FUNC Real distanceSquared(const TPlane3D<Real>& plane) const;
205 DYN_FUNC Real distanceSquared(const TTriangle3D<Real>& triangle) const;
206 DYN_FUNC Real distanceSquared(const TRectangle3D<Real>& rectangle) const;
207 DYN_FUNC Real distanceSquared(const TDisk3D<Real>& disk) const;
214 DYN_FUNC Real distanceSquared(const TSphere3D<Real>& sphere) const;
215 DYN_FUNC Real distanceSquared(const TCapsule3D<Real>& capsule) const;
216 DYN_FUNC Real distanceSquared(const TTet3D<Real>& tet) const;
217 DYN_FUNC Real distanceSquared(const TAlignedBox3D<Real>& abox) const;
218 DYN_FUNC Real distanceSquared(const TOrientedBox3D<Real>& obb) const;
219
220
227 DYN_FUNC bool inside(const TLine3D<Real>& line) const;
228 DYN_FUNC bool inside(const TRay3D<Real>& ray) const;
229 DYN_FUNC bool inside(const TSegment3D<Real>& segment) const;
236 DYN_FUNC bool inside(const TPlane3D<Real>& plane) const;
237 DYN_FUNC bool inside(const TTriangle3D<Real>& triangle) const;
238 DYN_FUNC bool inside(const TRectangle3D<Real>& rectangle) const;
239 DYN_FUNC bool inside(const TDisk3D<Real>& disk) const;
246 DYN_FUNC bool inside(const TSphere3D<Real>& sphere) const;
247 DYN_FUNC bool inside(const TCapsule3D<Real>& capsule) const;
248 DYN_FUNC bool inside(const TTet3D<Real>& tet) const;
249 DYN_FUNC bool inside(const TAlignedBox3D<Real>& box) const;
250 DYN_FUNC bool inside(const TOrientedBox3D<Real>& obb) const;
251
252 DYN_FUNC const TSegment3D<Real> operator-(const TPoint3D<Real>& pt) const;
253
255 };
256
257 template<typename Real>
259 {
260 public:
263
264 public:
265 DYN_FUNC TLine3D();
272 DYN_FUNC TLine3D(const Coord3D& pos, const Coord3D& dir);
273 DYN_FUNC TLine3D(const TLine3D<Real>& line);
274
275 DYN_FUNC TSegment3D<Real> proximity(const TLine3D<Real>& line) const;
276 DYN_FUNC TSegment3D<Real> proximity(const TRay3D<Real>& ray) const;
277 DYN_FUNC TSegment3D<Real> proximity(const TSegment3D<Real>& segment) const;
278
279 DYN_FUNC TSegment3D<Real> proximity(const TTriangle3D<Real>& triangle) const;
280 DYN_FUNC TSegment3D<Real> proximity(const TRectangle3D<Real>& rectangle) const;
281
282 DYN_FUNC TSegment3D<Real> proximity(const TSphere3D<Real>& sphere) const;
285
286
287 DYN_FUNC Real distance(const TPoint3D<Real>& pt) const;
288 DYN_FUNC Real distance(const TLine3D<Real>& line) const;
289 DYN_FUNC Real distance(const TRay3D<Real>& ray) const;
290 DYN_FUNC Real distance(const TSegment3D<Real>& segment) const;
291
292 DYN_FUNC Real distance(const TAlignedBox3D<Real>& box) const;
293 DYN_FUNC Real distance(const TOrientedBox3D<Real>& obb) const;
294
295 // DYN_FUNC Line3D(const Coord3D& pos, const Coord3D& dir);
296 // DYN_FUNC Line3D(const Line3D& line);
297
298
299 DYN_FUNC Real distanceSquared(const TPoint3D<Real>& pt) const;
300 DYN_FUNC Real distanceSquared(const TLine3D<Real>& line) const;
301 DYN_FUNC Real distanceSquared(const TRay3D<Real>& ray) const;
302 DYN_FUNC Real distanceSquared(const TSegment3D<Real>& segment) const;
309 DYN_FUNC Real distanceSquared(const TAlignedBox3D<Real>& box) const;
310 DYN_FUNC Real distanceSquared(const TOrientedBox3D<Real>& obb) const;
311
317 DYN_FUNC int intersect(const TPlane3D<Real>& plane, TPoint3D<Real>& interPt) const;
318 DYN_FUNC int intersect(const TTriangle3D<Real>& triangle, TPoint3D<Real>& interPt) const;
319
320 DYN_FUNC int intersect(const TSphere3D<Real>& sphere, TSegment3D<Real>& interSeg) const;
321 DYN_FUNC int intersect(const TTet3D<Real>& tet, TSegment3D<Real>& interSeg) const;
322 DYN_FUNC int intersect(const TAlignedBox3D<Real>& abox, TSegment3D<Real>& interSeg) const;
323 DYN_FUNC int intersect(const TOrientedBox3D<Real>& obb, TSegment3D<Real>& interSeg) const;
324
325
326 DYN_FUNC Real parameter(const Coord3D& pos) const;
327
328 DYN_FUNC bool isValid() const;
329
331
332 //direction will be normalized during construction
334 };
335
336 template<typename Real>
337 class TRay3D
338 {
339 public:
342
343 public:
344 DYN_FUNC TRay3D();
345
346 struct Param
347 {
349 };
350
358 DYN_FUNC TRay3D(const Coord3D& pos, const Coord3D& dir);
359 DYN_FUNC TRay3D(const TRay3D<Real>& ray);
360
361 DYN_FUNC TSegment3D<Real> proximity(const TRay3D<Real>& ray) const;
362 DYN_FUNC TSegment3D<Real> proximity(const TSegment3D<Real>& segment) const;
363
364 DYN_FUNC TSegment3D<Real> proximity(const TTriangle3D<Real>& triangle) const;
365 DYN_FUNC TSegment3D<Real> proximity(const TRectangle3D<Real>& rectangle) const;
366
369
370 DYN_FUNC Real distance(const TPoint3D<Real>& pt) const;
371 DYN_FUNC Real distance(const TSegment3D<Real>& segment) const;
372 DYN_FUNC Real distance(const TTriangle3D<Real>& triangle) const;
373
374 DYN_FUNC Real distanceSquared(const TPoint3D<Real>& pt) const;
375 DYN_FUNC Real distanceSquared(const TSegment3D<Real>& segment) const;
376 DYN_FUNC Real distanceSquared(const TTriangle3D<Real>& triangle) const;
377
378 DYN_FUNC int intersect(const TPlane3D<Real>& plane, TPoint3D<Real>& interPt) const;
379 DYN_FUNC int intersect(const TTriangle3D<Real>& triangle, TPoint3D<Real>& interPt) const;
380
381 DYN_FUNC int intersect(const TSphere3D<Real>& sphere, TSegment3D<Real>& interSeg) const;
382
383 DYN_FUNC int intersect(const TAlignedBox3D<Real>& abox, TSegment3D<Real>& interSeg) const;
384 DYN_FUNC int intersect(const TOrientedBox3D<Real>& obb, TSegment3D<Real>& interSeg) const;
385
386 DYN_FUNC Real parameter(const Coord3D& pos) const;
387
388 DYN_FUNC bool isValid() const;
389
391
392 //guarantee direction is a unit vector
394 };
395
396 template<typename Real>
398 {
399 public:
402
403 public:
404 DYN_FUNC TSegment3D();
405 DYN_FUNC TSegment3D(const Coord3D& p0, const Coord3D& p1);
406 DYN_FUNC TSegment3D(const TSegment3D<Real>& segment);
407
408 DYN_FUNC TSegment3D<Real> proximity(const TSegment3D<Real>& segment) const;
409
410 DYN_FUNC TSegment3D<Real> proximity(const TPlane3D<Real>& plane) const;
411 DYN_FUNC TSegment3D<Real> proximity(const TTriangle3D<Real>& triangle) const;
412 DYN_FUNC TSegment3D<Real> proximity(const TRectangle3D<Real>& rectangle) const;
413
416 DYN_FUNC TSegment3D<Real> proximity(const TTet3D<Real>& tet) const;
417
418 DYN_FUNC Real distance(const TSegment3D<Real>& segment) const;
419
420 DYN_FUNC Real distance(const TTriangle3D<Real>& triangle) const;
421
422 DYN_FUNC Real distanceSquared(const TSegment3D<Real>& segment) const;
423
424 DYN_FUNC Real distanceSquared(const TTriangle3D<Real>& triangle) const;
425
426 DYN_FUNC bool intersect(const TPlane3D<Real>& plane, TPoint3D<Real>& interPt) const;
427 DYN_FUNC bool intersect(const TTriangle3D<Real>& triangle, TPoint3D<Real>& interPt) const;
428
429 DYN_FUNC int intersect(const TSphere3D<Real>& sphere, TSegment3D<Real>& interSeg) const;
430 DYN_FUNC int intersect(const TAlignedBox3D<Real>& abox, TSegment3D<Real>& interSeg) const;
431 DYN_FUNC int intersect(const TOrientedBox3D<Real>& obb, TSegment3D<Real>& interSeg) const;
432
433 DYN_FUNC Real length() const;
434 DYN_FUNC Real lengthSquared() const;
435
436 DYN_FUNC Real parameter(const Coord3D& pos) const;
437
438 inline DYN_FUNC Coord3D& startPoint() { return v0; }
439 inline DYN_FUNC Coord3D& endPoint() { return v1; }
440
441 inline DYN_FUNC Coord3D startPoint() const { return v0; }
442 inline DYN_FUNC Coord3D endPoint() const { return v1; }
443
444 inline DYN_FUNC Coord3D direction() const { return v1 - v0; }
445
446 inline DYN_FUNC TSegment3D<Real> operator-(void) const;
447
448 DYN_FUNC bool isValid() const;
449
452 };
453
454 template<typename Real>
456 {
457 public:
460
461 public:
462 DYN_FUNC TPlane3D();
463 DYN_FUNC TPlane3D(const Coord3D& pos, const Coord3D n);
464 DYN_FUNC TPlane3D(const TPlane3D& plane);
465
466 DYN_FUNC bool isValid() const;
467
469
474 };
475
476
477 template<typename Real>
479 {
480 public:
483
484 public:
485 DYN_FUNC TTriangle3D();
486 DYN_FUNC TTriangle3D(const Coord3D& p0, const Coord3D& p1, const Coord3D& p2);
487 DYN_FUNC TTriangle3D(const TTriangle3D& triangle);
488
489 struct Param
490 {
494 };
495
496 DYN_FUNC Real area() const;
497 DYN_FUNC Coord3D normal() const;
498
499 DYN_FUNC bool computeBarycentrics(const Coord3D& p, Param& bary) const;
500 DYN_FUNC Coord3D computeLocation(const Param& bary) const;
501
502 DYN_FUNC Real maximumEdgeLength() const;
503
504 DYN_FUNC bool isValid() const;
505
507
508 DYN_FUNC Real distanceSquared(const TTriangle3D<Real>& triangle) const;
509
510 DYN_FUNC Real distance(const TTriangle3D<Real>& triangle) const;
511
513 };
514
515 template<typename Real>
517 {
518 public:
521
522 public:
523 DYN_FUNC TRectangle3D();
524 DYN_FUNC TRectangle3D(const Coord3D& c, const Coord3D& a0, const Coord3D& a1, const Coord2D& ext);
525 DYN_FUNC TRectangle3D(const TRectangle3D<Real>& rectangle);
526
527 struct Param
528 {
531 };
532
533 DYN_FUNC TPoint3D<Real> vertex(const int i) const;
534 DYN_FUNC TSegment3D<Real> edge(const int i) const;
535
536 DYN_FUNC Real area() const;
537 DYN_FUNC Coord3D normal() const;
538
539 DYN_FUNC bool computeParams(const Coord3D& p, Param& par) const;
540
541 DYN_FUNC bool isValid() const;
542
550 };
551
552 template<typename Real>
554 {
555 public:
558
559 public:
560 DYN_FUNC TDisk3D();
561 DYN_FUNC TDisk3D(const Coord3D& c, const Coord3D& n, const Real& r);
562 DYN_FUNC TDisk3D(const TDisk3D<Real>& circle);
563
564 DYN_FUNC Real area();
565
566 DYN_FUNC bool isValid();
567
571 };
572
573 template<typename Real>
575 {
576 public:
579
580 public:
581 DYN_FUNC TSphere3D();
582 DYN_FUNC TSphere3D(const Coord3D& c, const Real& r);
583 DYN_FUNC TSphere3D(const Coord3D& c, const Quat<Real>& rot, const Real& r);
584 DYN_FUNC TSphere3D(const TSphere3D<Real>& sphere);
585
586 DYN_FUNC Real volume();
587
588 DYN_FUNC bool isValid();
589
591
595 };
596
597 template<typename Real>
599 {
600 public:
602
603 public:
604 DYN_FUNC TCylinder3D();
605 DYN_FUNC TCylinder3D(const Coord3D& c, const Real& h, const Real &r, const Quat<Real>& rot = Quat<Real>(), const Coord3D& s = Coord3D(1));
606 DYN_FUNC TCylinder3D(const TCylinder3D<Real>& cylinder);
607 DYN_FUNC Real volume() const { return Real(M_PI) * radius * radius * height * scale[0] * scale[1] * scale[2]; }
608
612
615 };
616
617 template<typename Real>
619 {
620 public:
622
623 public:
624 DYN_FUNC TCone3D();
625 DYN_FUNC TCone3D(const Coord3D& c, const Real& h, const Real& r, const Quat<Real>& rot = Quat<Real>(), const Coord3D& s = Coord3D(1));
626 DYN_FUNC TCone3D(const TCone3D<Real>& cone);
627 DYN_FUNC Real volume() const { return Real(M_PI) * radius * radius * height / Real(3); }
628
629 //Center of the bottom circle
633
636 };
637
638 // The centerline is set to align with the Y-axis in default
639 template<typename Real>
641 {
642 public:
645
646 public:
647 DYN_FUNC TCapsule3D();
648 DYN_FUNC TCapsule3D(const Coord3D& c, const Quat<Real>& q, const Real& r, const Real& hl);
649 DYN_FUNC TCapsule3D(const Coord3D& v0, const Coord3D& v1, const Real& r);
650 DYN_FUNC TCapsule3D(const TCapsule3D<Real>& capsule);
651
652 DYN_FUNC Real volume() const;
653
654 DYN_FUNC bool isValid() const;
655 DYN_FUNC TAlignedBox3D<Real> aabb() const;
656
657 // return the two ends
658 DYN_FUNC inline Coord3D startPoint() const { return center - rotation.rotate(halfLength * Coord3D(0, 1, 0)); }
659 DYN_FUNC inline Coord3D endPoint() const { return center + rotation.rotate(halfLength * Coord3D(0, 1, 0)); }
660
661 DYN_FUNC inline TSegment3D<Real> centerline() const { return TSegment3D<Real>(startPoint(), endPoint()); }
662
667 };
668
675 template<typename Real>
676 class TTet3D
677 {
678 public:
682
683 public:
684 DYN_FUNC TTet3D();
685 DYN_FUNC TTet3D(const Coord3D& v0, const Coord3D& v1, const Coord3D& v2, const Coord3D& v3);
686 DYN_FUNC TTet3D(const TTet3D<Real>& tet);
687
688 DYN_FUNC TTriangle3D<Real> face(const int index) const;
689 DYN_FUNC TSegment3D<Real> edge(const int index) const;
690
691 DYN_FUNC Real solidAngle(const int index) const;
692
693 DYN_FUNC Real volume() const;
694
695 DYN_FUNC bool isValid() const;
696
697 //DYN_FUNC bool intersect(const TTet3D<Real>& tet, Coord3D& interNorm, Real& interDist, Coord3D& p1, Coord3D& p2, int need_distance = 1) const;
698 DYN_FUNC bool intersect(const TTet3D<Real>& tet, Coord3D& interNorm, Real& interDist, Coord3D& p1, Coord3D& p2, int need_distance = 1) const;
699 DYN_FUNC bool intersect(const TTriangle3D<Real>& tri, Coord3D& interNorm, Real& interDist, Coord3D& p1, Coord3D& p2, int need_distance = 1) const;
700
701 DYN_FUNC void expand(Real r);
703
704 // http://rodolphe-vaillant.fr/entry/127/find-a-tetrahedron-circumcenter
705 DYN_FUNC TPoint3D<Real> circumcenter() const;
706 DYN_FUNC TPoint3D<Real> barycenter() const;
707
708 DYN_FUNC bool contain(Coord3D p);
709
711
713 };
714
715 template<typename Real>
717 {
718 public:
722
723 public:
724 DYN_FUNC TAlignedBox3D();
725 DYN_FUNC TAlignedBox3D(const Coord3D& p0, const Coord3D& p1);
726 DYN_FUNC TAlignedBox3D(const TAlignedBox3D<Real>& box);
727
728 DYN_FUNC bool intersect(const TAlignedBox3D<Real>& abox, TAlignedBox3D<Real>& interBox) const;
729 DYN_FUNC bool checkOverlap(const TAlignedBox3D<Real>& abox) const;
730
731 DYN_FUNC TAlignedBox3D<Real> merge(const TAlignedBox3D<Real>& aabb) const;
732
733 DYN_FUNC bool meshInsert(const TTriangle3D<Real>& tri) const;
734 DYN_FUNC bool isValid();
735
737
738 DYN_FUNC inline Real length(unsigned int i) const { return v1[i] - v0[i]; }
739
742 };
743
744 template<typename Real>
746 {
747 public:
751
752 public:
753 DYN_FUNC TOrientedBox3D();
754
765 DYN_FUNC TOrientedBox3D(const Coord3D c, const Coord3D u_t, const Coord3D v_t, const Coord3D w_t, const Coord3D ext);
766
767 DYN_FUNC TOrientedBox3D(const Coord3D c, const Quat<Real> rot, const Coord3D ext);
768
770
771 DYN_FUNC TPoint3D<Real> vertex(const int i) const;
772 DYN_FUNC TSegment3D<Real> edge(const int i) const;
773 DYN_FUNC TRectangle3D<Real> face(const int i) const;
774
775 DYN_FUNC Real volume();
776
777 DYN_FUNC bool isValid();
778
780
782
783 //DYN_FUNC bool point_intersect(const TOrientedBox3D<Real>& OBB, Coord3D& interNorm, Real& interDist, Coord3D& p1, Coord3D& p2) const;
784 DYN_FUNC bool point_intersect(const TOrientedBox3D<Real>& OBB, Coord3D& interNorm, Real& interDist, Coord3D& p1, Coord3D& p2) const;
785 DYN_FUNC bool point_intersect(const TTet3D<Real>& TET, Coord3D& interNorm, Real& interDist, Coord3D& p1, Coord3D& p2) const;
786 DYN_FUNC bool point_intersect(const TTriangle3D<Real>& TRI, Coord3D& interNorm, Real& interDist, Coord3D& p1, Coord3D& p2) const;
787
788
789 //DYN_FUNC bool triangle_intersect(const TTriangle3D<Real>& Tri) const;
795
801
806 };
807
808 template class TPoint3D<float>;
809 template class TLine3D<float>;
810 template class TRay3D<float>;
811 template class TSegment3D<float>;
812 template class TPlane3D<float>;
813 template class TTriangle3D<float>;
814 template class TRectangle3D<float>;
815 template class TDisk3D<float>;
816 template class TSphere3D<float>;
817 template class TCapsule3D<float>;
818 template class TTet3D<float>;
819 template class TAlignedBox3D<float>;
820 template class TOrientedBox3D<float>;
821 template class TCylinder3D<float>;
822 template class TCone3D<float>;
823
824 template class TPoint3D<double>;
825 template class TLine3D<double>;
826 template class TRay3D<double>;
827 template class TSegment3D<double>;
828 template class TPlane3D<double>;
829 template class TTriangle3D<double>;
830 template class TRectangle3D<double>;
831 template class TDisk3D<double>;
832 template class TSphere3D<double>;
833 template class TCapsule3D<double>;
834 template class TTet3D<double>;
835 template class TAlignedBox3D<double>;
836 template class TOrientedBox3D<double>;
837 template class TCylinder3D<double>;
838 template class TCone3D<double>;
839
840#ifdef PRECISION_FLOAT
841 //convenient typedefs
842 typedef TPoint3D<float> Point3D;
843 typedef TLine3D<float> Line3D;
844 typedef TRay3D<float> Ray3D;
846 typedef TPlane3D<float> Plane3D;
849 typedef TDisk3D<float> Disk3D;
852 typedef TTet3D<float> Tet3D;
856 typedef TCone3D<float> Cone3D;
857#else
858 //convenient typedefs
874#endif
875}
876
877#include "Primitive3D.inl"
Implementation of quaternion.
double Real
Definition Typedef.inl:23
#define M_PI
Definition Typedef.inl:36
DYN_FUNC TAlignedBox3D(const Coord3D &p0, const Coord3D &p1)
SquareMatrix< Real, 3 > Matrix3D
DYN_FUNC Real length(unsigned int i) const
Vector< Real, 2 > Coord2D
Vector< Real, 3 > Coord3D
DYN_FUNC bool checkOverlap(const TAlignedBox3D< Real > &abox) const
DYN_FUNC bool intersect(const TAlignedBox3D< Real > &abox, TAlignedBox3D< Real > &interBox) const
DYN_FUNC bool meshInsert(const TTriangle3D< Real > &tri) const
DYN_FUNC TAlignedBox3D(const TAlignedBox3D< Real > &box)
DYN_FUNC TOrientedBox3D< Real > rotate(const Matrix3D &mat)
DYN_FUNC bool isValid()
DYN_FUNC TAlignedBox3D< Real > merge(const TAlignedBox3D< Real > &aabb) const
DYN_FUNC TCapsule3D()
DYN_FUNC TCapsule3D(const TCapsule3D< Real > &capsule)
DYN_FUNC Real volume() const
DYN_FUNC TSegment3D< Real > centerline() const
Vector< Real, 3 > Coord3D
Vector< Real, 2 > Coord2D
DYN_FUNC TCapsule3D(const Coord3D &v0, const Coord3D &v1, const Real &r)
DYN_FUNC bool isValid() const
DYN_FUNC Coord3D endPoint() const
DYN_FUNC TAlignedBox3D< Real > aabb() const
DYN_FUNC Coord3D startPoint() const
DYN_FUNC TCapsule3D(const Coord3D &c, const Quat< Real > &q, const Real &r, const Real &hl)
DYN_FUNC TCone3D()
DYN_FUNC TCone3D(const TCone3D< Real > &cone)
Quat< double > rotation
DYN_FUNC TCone3D(const Coord3D &c, const Real &h, const Real &r, const Quat< Real > &rot=Quat< Real >(), const Coord3D &s=Coord3D(1))
Vector< Real, 3 > Coord3D
DYN_FUNC Real volume() const
DYN_FUNC TCylinder3D(const TCylinder3D< Real > &cylinder)
DYN_FUNC TCylinder3D(const Coord3D &c, const Real &h, const Real &r, const Quat< Real > &rot=Quat< Real >(), const Coord3D &s=Coord3D(1))
Vector< Real, 3 > Coord3D
DYN_FUNC Real volume() const
DYN_FUNC TDisk3D()
Vector< Real, 2 > Coord2D
DYN_FUNC Real area()
Vector< Real, 3 > Coord3D
DYN_FUNC TDisk3D(const TDisk3D< Real > &circle)
DYN_FUNC TDisk3D(const Coord3D &c, const Coord3D &n, const Real &r)
DYN_FUNC bool isValid()
1D geometric primitives in three-dimensional space
Vector< Real, 2 > Coord2D
DYN_FUNC Real distanceSquared(const TOrientedBox3D< Real > &obb) const
DYN_FUNC TSegment3D< Real > proximity(const TAlignedBox3D< Real > &box) const
DYN_FUNC Real distance(const TAlignedBox3D< Real > &box) const
DYN_FUNC TSegment3D< Real > proximity(const TSegment3D< Real > &segment) const
DYN_FUNC TSegment3D< Real > proximity(const TSphere3D< Real > &sphere) const
DYN_FUNC TLine3D(const TLine3D< Real > &line)
DYN_FUNC Real distance(const TSegment3D< Real > &segment) const
DYN_FUNC int intersect(const TAlignedBox3D< Real > &abox, TSegment3D< Real > &interSeg) const
DYN_FUNC int intersect(const TTet3D< Real > &tet, TSegment3D< Real > &interSeg) const
DYN_FUNC Real distanceSquared(const TLine3D< Real > &line) const
DYN_FUNC Real distanceSquared(const TSegment3D< Real > &segment) const
DYN_FUNC TSegment3D< Real > proximity(const TLine3D< Real > &line) const
DYN_FUNC int intersect(const TOrientedBox3D< Real > &obb, TSegment3D< Real > &interSeg) const
DYN_FUNC Real parameter(const Coord3D &pos) const
DYN_FUNC Real distanceSquared(const TAlignedBox3D< Real > &box) const
compute signed distance to 3D geometric primitives
DYN_FUNC TSegment3D< Real > proximity(const TOrientedBox3D< Real > &obb) const
DYN_FUNC TSegment3D< Real > proximity(const TTriangle3D< Real > &triangle) const
DYN_FUNC int intersect(const TPlane3D< Real > &plane, TPoint3D< Real > &interPt) const
intersection tests
DYN_FUNC int intersect(const TTriangle3D< Real > &triangle, TPoint3D< Real > &interPt) const
DYN_FUNC Real distance(const TOrientedBox3D< Real > &obb) const
DYN_FUNC TLine3D()
DYN_FUNC bool isValid() const
DYN_FUNC TLine3D(const Coord3D &pos, const Coord3D &dir)
DYN_FUNC Real distanceSquared(const TPoint3D< Real > &pt) const
DYN_FUNC TSegment3D< Real > proximity(const TRectangle3D< Real > &rectangle) const
DYN_FUNC Real distanceSquared(const TRay3D< Real > &ray) const
DYN_FUNC int intersect(const TSphere3D< Real > &sphere, TSegment3D< Real > &interSeg) const
DYN_FUNC TSegment3D< Real > proximity(const TRay3D< Real > &ray) const
Vector< Real, 3 > Coord3D
DYN_FUNC Real distance(const TLine3D< Real > &line) const
DYN_FUNC Real distance(const TPoint3D< Real > &pt) const
DYN_FUNC Real distance(const TRay3D< Real > &ray) const
DYN_FUNC Real volume()
Vector< Real, 2 > Coord2D
DYN_FUNC TOrientedBox3D(const Coord3D c, const Coord3D u_t, const Coord3D v_t, const Coord3D w_t, const Coord3D ext)
construct an oriented bounding box, gurantee u_t, v_t and w_t are unit vectors and form right-handed ...
DYN_FUNC TPoint3D< Real > vertex(const int i) const
DYN_FUNC TOrientedBox3D(const Coord3D c, const Quat< Real > rot, const Coord3D ext)
DYN_FUNC TSegment3D< Real > edge(const int i) const
DYN_FUNC TOrientedBox3D(const TOrientedBox3D< Real > &obb)
Vector< Real, 3 > Coord3D
DYN_FUNC TRectangle3D< Real > face(const int i) const
DYN_FUNC bool point_intersect(const TTriangle3D< Real > &TRI, Coord3D &interNorm, Real &interDist, Coord3D &p1, Coord3D &p2) const
DYN_FUNC bool isValid()
SquareMatrix< Real, 3 > Matrix3D
DYN_FUNC bool point_intersect(const TOrientedBox3D< Real > &OBB, Coord3D &interNorm, Real &interDist, Coord3D &p1, Coord3D &p2) const
DYN_FUNC TOrientedBox3D< Real > rotate(const Matrix3D &mat)
DYN_FUNC TAlignedBox3D< Real > aabb()
DYN_FUNC bool point_intersect(const TTet3D< Real > &TET, Coord3D &interNorm, Real &interDist, Coord3D &p1, Coord3D &p2) const
2D geometric primitives in three-dimensional space
DYN_FUNC TPlane3D()
DYN_FUNC bool isValid() const
Vector< Real, 3 > Coord3D
DYN_FUNC TPlane3D(const TPlane3D &plane)
Vector< Real, 2 > Coord2D
DYN_FUNC TPlane3D(const Coord3D &pos, const Coord3D n)
0D geometric primitive in three-dimensional space
DYN_FUNC TPoint3D< Real > project(const TTet3D< Real > &tet, Bool &bInside) const
DYN_FUNC Real distance(const TRay3D< Real > &ray) const
DYN_FUNC Real distance(const TPlane3D< Real > &plane) const
compute the signed distance to 2D geometric primitives
DYN_FUNC Real distance(const TOrientedBox3D< Real > &obb) const
DYN_FUNC TPoint3D< Real > project(const TRectangle3D< Real > &rectangle) const
DYN_FUNC TPoint3D< Real > project(const TAlignedBox3D< Real > &abox) const
DYN_FUNC Real distanceSquared(const TRay3D< Real > &ray) const
DYN_FUNC bool inside(const TAlignedBox3D< Real > &box) const
DYN_FUNC TPoint3D< Real > project(const TCapsule3D< Real > &capsule, Bool &bInside) const
DYN_FUNC Real distanceSquared(const TDisk3D< Real > &disk) const
DYN_FUNC bool inside(const TRay3D< Real > &ray) const
DYN_FUNC TPoint3D< Real > project(const TDisk3D< Real > &disk) const
DYN_FUNC bool inside(const TDisk3D< Real > &disk) const
DYN_FUNC Real distance(const TSegment3D< Real > &segment) const
DYN_FUNC Real distanceSquared(const TCapsule3D< Real > &capsule) const
DYN_FUNC Real distance(const TAlignedBox3D< Real > &abox) const
DYN_FUNC Real distance(const TCapsule3D< Real > &capsule) const
DYN_FUNC TPoint3D(const Real &val)
DYN_FUNC bool inside(const TTet3D< Real > &tet) const
DYN_FUNC TPoint3D< Real > project(const TSegment3D< Real > &segment) const
DYN_FUNC Real distance(const TSphere3D< Real > &sphere) const
compute signed distance to 3D geometric primitives
DYN_FUNC bool inside(const TSphere3D< Real > &sphere) const
check whether a point strictly lies inside (excluding boundary) a 3D geometric primitive
DYN_FUNC bool inside(const TOrientedBox3D< Real > &obb) const
DYN_FUNC TPoint3D< Real > project(const TTriangle3D< Real > &triangle) const
DYN_FUNC TPoint3D< Real > project(const TTet3D< Real > &tet) const
DYN_FUNC TPoint3D()
DYN_FUNC Real distanceSquared(const TAlignedBox3D< Real > &abox) const
DYN_FUNC TPoint3D< Real > project(const TOrientedBox3D< Real > &obb, Bool &bInside) const
DYN_FUNC TPoint3D(const TPoint3D &pt)
DYN_FUNC Real distance(const TDisk3D< Real > &disk) const
DYN_FUNC TPoint3D< Real > project(const TSphere3D< Real > &sphere) const
project a point onto polyhedra components – tetrahedra, spheres and oriented bounding boxes
DYN_FUNC Real distanceSquared(const TLine3D< Real > &line) const
DYN_FUNC Real distanceSquared(const TPoint3D< Real > &pt) const
DYN_FUNC Real distanceSquared(const TOrientedBox3D< Real > &obb) const
DYN_FUNC TPoint3D(const Coord3D &pos)
DYN_FUNC TPoint3D & operator=(const Coord3D &p)
DYN_FUNC TPoint3D< Real > project(const TPlane3D< Real > &plane) const
project a point onto planar components – planes, triangles and disks
DYN_FUNC bool inside(const TTriangle3D< Real > &triangle) const
DYN_FUNC Real distanceSquared(const TTriangle3D< Real > &triangle) const
DYN_FUNC Real distance(const TTriangle3D< Real > &triangle) const
DYN_FUNC Real distanceSquared(const TSphere3D< Real > &sphere) const
return squared distance from a point to 3D geometric primitives
Vector< Real, 2 > Coord2D
DYN_FUNC Real distanceSquared(const TPlane3D< Real > &plane) const
return squared distance from a point to 3D geometric primitives
DYN_FUNC Real distanceSquared(const TTet3D< Real > &tet) const
DYN_FUNC TPoint3D< Real > project(const TTet3D< Real > &tet, Bool &bInside, int *idx) const
DYN_FUNC Real distance(const TLine3D< Real > &line) const
DYN_FUNC bool inside(const TCapsule3D< Real > &capsule) const
DYN_FUNC Real distanceSquared(const TSegment3D< Real > &segment) const
DYN_FUNC TPoint3D< Real > project(const TSphere3D< Real > &sphere, Bool &bInside) const
DYN_FUNC TPoint3D< Real > project(const TLine3D< Real > &line) const
project a point onto linear components – lines, rays and segments
DYN_FUNC TPoint3D< Real > project(const TCapsule3D< Real > &capsule) const
DYN_FUNC bool inside(const TPlane3D< Real > &plane) const
check whether a point strictly lies inside (excluding boundary) a 2D geometric primitive
DYN_FUNC bool inside(const TRectangle3D< Real > &rectangle) const
DYN_FUNC const TSegment3D< Real > operator-(const TPoint3D< Real > &pt) const
DYN_FUNC TPoint3D< Real > project(const TAlignedBox3D< Real > &abox, Bool &bInside) const
DYN_FUNC Real distance(const TTet3D< Real > &tet) const
DYN_FUNC bool inside(const TLine3D< Real > &line) const
check whether a point strictly lies inside (excluding boundary) a 1D geometric primitive
DYN_FUNC Real distanceSquared(const TRectangle3D< Real > &rectangle) const
DYN_FUNC Real distance(const TPoint3D< Real > &pt) const
DYN_FUNC TPoint3D(const Real &c0, const Real &c1, const Real &c2)
DYN_FUNC bool inside(const TSegment3D< Real > &segment) const
Vector< Real, 3 > Coord3D
DYN_FUNC TPoint3D< Real > project(const TOrientedBox3D< Real > &obb) const
DYN_FUNC Real distance(const TRectangle3D< Real > &rectangle) const
DYN_FUNC TPoint3D< Real > project(const TRay3D< Real > &ray) const
DYN_FUNC Real distanceSquared(const TPoint3D< Real > &pt) const
DYN_FUNC int intersect(const TSphere3D< Real > &sphere, TSegment3D< Real > &interSeg) const
DYN_FUNC int intersect(const TOrientedBox3D< Real > &obb, TSegment3D< Real > &interSeg) const
DYN_FUNC Real parameter(const Coord3D &pos) const
DYN_FUNC Real distanceSquared(const TTriangle3D< Real > &triangle) const
DYN_FUNC bool isValid() const
DYN_FUNC TSegment3D< Real > proximity(const TSegment3D< Real > &segment) const
Vector< Real, 2 > Coord2D
DYN_FUNC TSegment3D< Real > proximity(const TOrientedBox3D< Real > &obb) const
DYN_FUNC int intersect(const TPlane3D< Real > &plane, TPoint3D< Real > &interPt) const
DYN_FUNC TSegment3D< Real > proximity(const TTriangle3D< Real > &triangle) const
DYN_FUNC TSegment3D< Real > proximity(const TAlignedBox3D< Real > &box) const
DYN_FUNC int intersect(const TAlignedBox3D< Real > &abox, TSegment3D< Real > &interSeg) const
Vector< Real, 3 > Coord3D
DYN_FUNC TSegment3D< Real > proximity(const TRay3D< Real > &ray) const
DYN_FUNC Real distance(const TTriangle3D< Real > &triangle) const
DYN_FUNC TRay3D(const Coord3D &pos, const Coord3D &dir)
DYN_FUNC int intersect(const TTriangle3D< Real > &triangle, TPoint3D< Real > &interPt) const
DYN_FUNC Real distanceSquared(const TSegment3D< Real > &segment) const
DYN_FUNC Real distance(const TPoint3D< Real > &pt) const
DYN_FUNC Real distance(const TSegment3D< Real > &segment) const
DYN_FUNC TSegment3D< Real > proximity(const TRectangle3D< Real > &rectangle) const
DYN_FUNC TRay3D()
DYN_FUNC TRay3D(const TRay3D< Real > &ray)
Vector< Real, 2 > Coord2D
DYN_FUNC TPoint3D< Real > vertex(const int i) const
DYN_FUNC bool computeParams(const Coord3D &p, Param &par) const
Vector< Real, 3 > Coord3D
DYN_FUNC TRectangle3D(const TRectangle3D< Real > &rectangle)
DYN_FUNC TSegment3D< Real > edge(const int i) const
DYN_FUNC TRectangle3D(const Coord3D &c, const Coord3D &a0, const Coord3D &a1, const Coord2D &ext)
DYN_FUNC Coord3D normal() const
DYN_FUNC Real area() const
DYN_FUNC bool isValid() const
DYN_FUNC Real distance(const TSegment3D< Real > &segment) const
DYN_FUNC Coord3D & endPoint()
DYN_FUNC TSegment3D< Real > operator-(void) const
DYN_FUNC Real parameter(const Coord3D &pos) const
DYN_FUNC TSegment3D< Real > proximity(const TRectangle3D< Real > &rectangle) const
DYN_FUNC TSegment3D(const Coord3D &p0, const Coord3D &p1)
DYN_FUNC Real lengthSquared() const
DYN_FUNC int intersect(const TSphere3D< Real > &sphere, TSegment3D< Real > &interSeg) const
DYN_FUNC bool intersect(const TTriangle3D< Real > &triangle, TPoint3D< Real > &interPt) const
DYN_FUNC Coord3D direction() const
DYN_FUNC int intersect(const TAlignedBox3D< Real > &abox, TSegment3D< Real > &interSeg) const
DYN_FUNC TSegment3D< Real > proximity(const TTriangle3D< Real > &triangle) const
DYN_FUNC int intersect(const TOrientedBox3D< Real > &obb, TSegment3D< Real > &interSeg) const
Vector< Real, 2 > Coord2D
DYN_FUNC Real distance(const TTriangle3D< Real > &triangle) const
DYN_FUNC TSegment3D< Real > proximity(const TOrientedBox3D< Real > &obb) const
DYN_FUNC TSegment3D< Real > proximity(const TPlane3D< Real > &plane) const
DYN_FUNC Coord3D startPoint() const
DYN_FUNC TSegment3D< Real > proximity(const TSegment3D< Real > &segment) const
DYN_FUNC TSegment3D< Real > proximity(const TTet3D< Real > &tet) const
DYN_FUNC Coord3D endPoint() const
DYN_FUNC TSegment3D(const TSegment3D< Real > &segment)
DYN_FUNC Real distanceSquared(const TTriangle3D< Real > &triangle) const
DYN_FUNC bool isValid() const
DYN_FUNC Real length() const
Vector< Real, 3 > Coord3D
DYN_FUNC TSegment3D< Real > proximity(const TAlignedBox3D< Real > &box) const
DYN_FUNC TSegment3D()
DYN_FUNC bool intersect(const TPlane3D< Real > &plane, TPoint3D< Real > &interPt) const
DYN_FUNC Coord3D & startPoint()
DYN_FUNC Real distanceSquared(const TSegment3D< Real > &segment) const
3D geometric primitives in three-dimensional space
DYN_FUNC Real volume()
DYN_FUNC bool isValid()
DYN_FUNC TSphere3D(const Coord3D &c, const Real &r)
Vector< Real, 3 > Coord3D
DYN_FUNC TAlignedBox3D< Real > aabb()
DYN_FUNC TSphere3D(const TSphere3D< Real > &sphere)
Vector< Real, 2 > Coord2D
DYN_FUNC TSphere3D()
DYN_FUNC TSphere3D(const Coord3D &c, const Quat< Real > &rot, const Real &r)
vertices are ordered so that the normal vectors for the triangular faces point outwards 3 / | \ 0 - 2...
DYN_FUNC TPoint3D< Real > circumcenter() const
DYN_FUNC bool contain(Coord3D p)
DYN_FUNC TPoint3D< Real > barycenter() const
Vector< Real, 3 > Coord3D
DYN_FUNC TTet3D(const TTet3D< Real > &tet)
SquareMatrix< Real, 3 > Matrix3D
DYN_FUNC bool isValid() const
DYN_FUNC TSegment3D< Real > edge(const int index) const
DYN_FUNC bool intersect(const TTet3D< Real > &tet, Coord3D &interNorm, Real &interDist, Coord3D &p1, Coord3D &p2, int need_distance=1) const
DYN_FUNC TAlignedBox3D< Real > aabb()
DYN_FUNC TTet3D()
DYN_FUNC TTet3D(const Coord3D &v0, const Coord3D &v1, const Coord3D &v2, const Coord3D &v3)
Vector< Real, 2 > Coord2D
DYN_FUNC Vector< Real, 4 > computeBarycentricCoordinates(const Coord3D &p)
DYN_FUNC void expand(Real r)
DYN_FUNC bool intersect(const TTriangle3D< Real > &tri, Coord3D &interNorm, Real &interDist, Coord3D &p1, Coord3D &p2, int need_distance=1) const
DYN_FUNC TTriangle3D< Real > face(const int index) const
DYN_FUNC Real solidAngle(const int index) const
DYN_FUNC Real volume() const
Vector< Real, 2 > Coord2D
DYN_FUNC TTriangle3D(const Coord3D &p0, const Coord3D &p1, const Coord3D &p2)
DYN_FUNC Real distance(const TTriangle3D< Real > &triangle) const
DYN_FUNC TAlignedBox3D< Real > aabb()
DYN_FUNC Coord3D computeLocation(const Param &bary) const
Vector< Real, 3 > Coord3D
DYN_FUNC bool isValid() const
DYN_FUNC Real maximumEdgeLength() const
DYN_FUNC bool computeBarycentrics(const Coord3D &p, Param &bary) const
DYN_FUNC TTriangle3D(const TTriangle3D &triangle)
DYN_FUNC Real area() const
DYN_FUNC Real distanceSquared(const TTriangle3D< Real > &triangle) const
DYN_FUNC Coord3D normal() const
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
TAlignedBox3D< double > AlignedBox3D
TCylinder3D< double > Cylinder3D
TLine3D< double > Line3D
Quat< float > Quat1f
Definition Quat.h:136
TRectangle3D< double > Rectangle3D
TTriangle3D< double > Triangle3D
TRay3D< double > Ray3D
TOrientedBox3D< double > OrientedBox3D
TCapsule3D< double > Capsule3D
TPoint3D< double > Point3D
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
TCone3D< double > Cone3D
TTet3D< double > Tet3D
TSphere3D< double > Sphere3D
TPlane3D< double > Plane3D
TSegment3D< double > Segment3D
TDisk3D< double > Disk3D
dyno::Vec3f halfLength
Definition Primitive3D.h:42
dyno::Vec3f center
Definition Primitive3D.h:41
dyno::Quat1f rot
Definition Primitive3D.h:44
dyno::Quat1f rot
Definition Primitive3D.h:56
dyno::Vec3f center
Definition Primitive3D.h:57
float halfLength
Definition Primitive3D.h:58
dyno::Vec3f origin
Definition Primitive3D.h:22
dyno::Vec3f normal
Definition Primitive3D.h:23
dyno::Vec3f origin
Definition Primitive3D.h:64
dyno::Vec3f direction
Definition Primitive3D.h:65
dyno::Vec3f center
Definition Primitive3D.h:29
glm::vec3 center
Definition Primitive3D.h:50
dyno::Quat1f rot
Definition Primitive3D.h:49
float radius
Definition Primitive3D.h:51