16 std::vector<Point_t> result;
20 static std::vector<Point_t> min_plane_n;
21 static std::vector<Point_t> max_plane_n;
22 if(!min_plane_n.size()) {
23 min_plane_n.reserve(3);
24 min_plane_n.push_back(
Vector_t(-1,0,0));
25 min_plane_n.push_back(
Vector_t(0,-1,0));
26 min_plane_n.push_back(
Vector_t(0,0,-1));
27 max_plane_n.reserve(3);
28 max_plane_n.push_back(
Vector_t(1,0,0));
29 max_plane_n.push_back(
Vector_t(0,1,0));
30 max_plane_n.push_back(
Vector_t(0,0,1));
33 auto const& min_pt = box.
Min();
34 auto const& max_pt = box.
Max();
36 auto const& start = line.
Start();
40 for(
size_t i=0; i<min_pt.size(); ++i) {
42 (start[i] <= min_pt[i] || max_pt[i] <= start[i]) )
46 for(
size_t i=0; i<3; ++i) {
47 auto const& normal = min_plane_n[i];
48 double s = (-1.) * ( normal * (start - min_pt) ) / (normal *
dir);
50 auto xs = start +
dir *
s;
53 for(
size_t sur_axis=0; sur_axis<3; ++sur_axis) {
54 if(sur_axis==i)
continue;
55 if(xs[sur_axis] < min_pt[sur_axis] || max_pt[sur_axis] < xs[sur_axis]) {
60 if(on_surface && xs != xs1) {
62 if(!(xs1.
IsValid()))
for(
size_t j=0; j<3; ++j) xs1[j]=xs[j];
65 for(
size_t j=0; j<3; ++j) xs2[j]=xs[j];
74 result.push_back(xs1);
75 result.push_back(xs2);
79 for(
size_t i=0; i<3; ++i) {
80 auto const& normal = max_plane_n[i];
81 double s = (-1.) * ( normal * (start - max_pt) ) / (normal *
dir);
83 auto xs = start +
dir *
s;
85 for(
size_t sur_axis=0; sur_axis<3; ++sur_axis) {
86 if(sur_axis==i)
continue;
87 if(xs[sur_axis] < min_pt[sur_axis] || max_pt[sur_axis] < xs[sur_axis]) {
92 if(on_surface && xs != xs1) {
93 if(!(xs1.
IsValid()))
for(
size_t j=0; j<3; ++j) xs1[j]=xs[j];
95 for(
size_t j=0; j<3; ++j) xs2[j]=xs[j];
100 if(!xs1.
IsValid())
return result;
104 result.push_back(xs1);
105 result.push_back(xs2);
108 result.push_back(xs1);
116 auto const& st = line.
Start();
117 auto const& ed = line.
End();
120 hline.
Start(st[0],st[1],st[2]);
121 hline.
Dir(ed[0]-st[0],ed[1]-st[1],ed[2]-st[2]);
125 if(!hline_result.size())
return hline_result;
128 std::vector<Point_t> result;
129 auto length = st._SqDist_(ed);
130 for(
auto const& pt : hline_result)
131 if(st._SqDist_(pt) < length) result.push_back(pt);
140 std::vector<Point_t> result;
141 if(trj.size() < 2)
return result;
146 for(
size_t i=0; i<trj.size()-1; ++i) {
148 auto const& st = trj[i];
149 auto const& ed = trj[i+1];
150 hline.
Start(st[0],st[1],st[2]);
151 hline.
Dir(ed[0]-st[0],ed[1]-st[1],ed[2]-st[2]);
155 if(!hline_result.size())
continue;
158 auto length = st._SqDist_(ed);
159 for(
auto const& pt : hline_result)
160 if(st._SqDist_(pt) < length) result.push_back(pt);
227 double s = (b*f-c*
e)/d;
228 double t = (a*f-b*c)/d;
278 double s = (b*f-c*
e)/d;
279 double t = (a*f-b*c)/d;
311 auto const d1 = hline.
Dir();
312 auto const d2 = seg.
End()-seg.
Start();
330 if ( sDist <= eDist ) {
343 double s = (b*f-c*
e)/d;
359 double t = (a*f-b*c)/d;
361 if ( (t < 1)
and (t > 0) ){
377 auto const ab = line_e - line_s;
378 auto const ac = pt - line_s;
379 auto const bc = pt - line_e;
381 if(
e <= 0. )
return ac.SqLength();
382 auto f = ab.SqLength();
383 if(
e >= f )
return bc.SqLength();
384 return (ac.SqLength() -
e *
e / f);
391 auto const& ab = line.
Dir();
393 auto t = ((pt - line.
Start()) * ab);
395 if( t <= 0. )
return line.
Start();
399 if( t>= denom )
return line.
End();
401 else return (line.
Start() + ab * (t/denom));
408 auto const& ab = line.
Dir();
409 auto const ac = pt - line.
Start();
410 auto const bc = ac - ab;
413 if(
e <= 0. )
return (ac * ac);
414 auto f = ab.SqLength();
415 return (ac.SqLength() -
e *
e / f);
422 auto const& ab = line.
Dir();
423 auto t = (pt - line.
Start()) * ab;
424 if( t <= 0. )
return line.
Start();
427 return (line.
Start() + ab * (t/denom));
434 auto const ab = line.
Pt2()-line.
Pt1();
435 auto const ac = pt - line.
Pt1();
436 auto const bc = ac - ab;
439 auto f = ab.SqLength();
440 return (ac.SqLength() -
e *
e / f);
446 auto const& ab = line.
Pt2()-line.
Pt1();
447 auto t = (pt - line.
Pt1()) * ab;
449 return (line.
Pt1() + ab * (t/denom));
461 auto const& pt_min = box.
Min();
462 auto const& pt_max = box.
Max();
464 double dist_to_yz = pt[0] - pt_min[0];
465 if( dist_to_yz > (pt_max[0] - pt[0]) ) dist_to_yz = pt_max[0] - pt[0];
468 double dist_to_zx = pt[1] - pt_min[1];
469 if( dist_to_zx > (pt_max[1] - pt[1]) ) dist_to_zx = pt_max[1] - pt[1];
472 double dist_to_xy = pt[2] - pt_min[2];
473 if( dist_to_xy > (pt_max[2] - pt[2]) ) dist_to_xy = pt_max[2] - pt[2];
476 dist = ( dist_to_yz < dist_to_zx ? dist_to_yz : dist_to_zx );
477 dist = ( dist < dist_to_xy ? dist : dist_to_xy );
486 for(
size_t i=0; i<pt.size(); ++i) {
488 auto const& v_pt = pt[i];
489 auto const& v_max = box.
Max()[i];
490 auto const& v_min = box.
Min()[i];
492 if(v_pt < v_min) dist += (v_min - v_pt) * (v_min - v_pt);
493 if(v_pt > v_max) dist += (v_pt - v_max) * (v_pt - v_max);
506 for(
size_t i=0; i<pt.size(); ++i) {
507 auto const& v_pt = pt[i];
508 auto const& v_min = box.
Min()[i];
509 auto const& v_max = box.
Max()[i];
511 if( v_pt < v_min ) res[i] = v_min;
512 if( v_pt > v_max ) res[i] = v_max;
535 for (
size_t l=0; l < trj.size()-1; l++){
536 double distTmp =
_SqDist_(pt,trj[l],trj[l+1]);
537 if (distTmp < distMin) { distMin = distTmp; }
555 for (
size_t t=0; t < trj.size(); t++){
559 double tmpDist =
SqDist(pt, trj[t]);
560 if (tmpDist < minDist){
588 for (
size_t l=0; l < trj.size()-1; l++){
589 double distTmp =
_SqDist_(pt,trj[l],trj[l+1]);
590 if (distTmp < distMin) { distMin = distTmp; idx = l; }
611 for (
size_t t=0; t < trj.size(); t++){
618 double tmpDist =
SqDist(pt, trj[t]);
619 if (tmpDist < minDist){
650 for (
size_t l=0; l < trj.size()-1; l++){
652 double distTmp =
_SqDist_(segTmp, seg, c1min, c2min);
653 if ( distTmp < distMin ){
671 if ( !trj1.size() or !trj2.size() )
683 for (
size_t l1=0; l1 < trj1.size()-1; l1++){
684 for (
size_t l2=0; l2 < trj2.size()-1; l2++){
687 double distTmp =
_SqDist_(segTmp1, segTmp2, c1min, c2min);
688 if ( distTmp < distMin ){
718 for (
size_t l=0; l < trj.size()-1; l++){
720 double distTmp =
_SqDist_(hline, segTmp, c1min, c2min);
721 if ( distTmp < distMin ){
745 for (
size_t t=0; t < trj.size(); t++){
752 double tmpDist =
SqDist(seg, trj[t], c1min, c2min);
755 if (tmpDist < minDist){
774 auto const& s1 = seg1.
Start();
775 auto const& s2 = seg2.
Start();
776 auto const&
e1 = seg1.
End();
777 auto const& e2 = seg2.
End();
783 double a = d1.SqLength();
784 double e = d2.SqLength();
788 if ( (a <= 0)
and (e <= 0) ){
812 double denom = (a*
e)-(b*b);
815 t1 =
_Clamp_((b*f-c*e)/denom, 0., 1.);
847 if (n < min) {
return min; }
848 if (n > max) {
return max; }
887 origin = (pt1+pt2)/2.;
901 return vec1.
Dot(dir1) + vec2.
Dot(dir2);
943 origin = (pt1+pt2)/2.;
957 return vec1.Dot(lin1.
Dir()) + vec2.Dot(lin2.
Dir());
988 HalfLine_t lin1(trj1.front(),trj1.back()-trj1.front());
990 HalfLine_t lin2(trj2.front(),trj2.back()-trj2.front());
998 HalfLine_t lin1(trj.front(),trj.back()-trj.front());
1008 HalfLine_t lin2(trj.front(),trj.back()-trj.front());
1019 std::vector<Point_t> copyPts = {pts[0]};
1020 for(
size_t p1=0;
p1 < pts.size();
p1++){
1023 for (
size_t p2 =0; p2 < copyPts.size(); p2++)
1024 if (pts[
p1] == copyPts[p2]) { found =
true;
break; }
1026 copyPts.push_back(pts[
p1]);
1030 if (copyPts.size() < 5)
1033 size_t npoints = copyPts.size();
1034 std::vector<Point_t> points4 = {copyPts[npoints-1],copyPts[npoints-2],copyPts[npoints-3],copyPts[npoints-4]};
1056 if (remaining.size() == 0)
1061 auto const& lastPoint = remaining.back();
1064 if ( thisSphere.
Contain(lastPoint) ){
1065 remaining.pop_back();
1070 double dist = lastPoint.Dist(thisSphere.
Center());
1083 if (shift < 0) { shift *= -1; }
1088 Sphere_t newsphere(newCenter,newRadius);
1091 remaining.pop_back();
1098 std::vector<Point_t> sosPts)
const
1104 int index = numPts-1;
1108 if ( smallestSphere.
Contain(pts[index]) )
1109 return smallestSphere;
1111 sosPts.push_back(pts[index]);
bool Contain(const Point_t &p) const
Judge if a point is contained within a sphere.
Point_t ClosestPt(const Line_t &line, const Point_t &pt) const
double _SqDist_(const Line_t &l1, const Line_t &l2, Point_t &L1, Point_t &L2) const
Line & Line distance w/o dimensionality check.
const Point_t & Start() const
Start getter.
double _Clamp_(const double n, const double min, const double max) const
Clamp function: checks if value out of bounds.
void compat(const Point_t &obj) const
Dimensionality check function w/ Trajectory.
double SqDist(const Line_t &line, const Point_t &pt) const
Representation of a simple 3D line segment Defines a finite 3D straight line by having the start and ...
Representation of a 3D rectangular box which sides are aligned w/ coordinate axis. A representation of an Axis-Aligned-Boundary-Box, a simple & popular representation of 3D boundary box for collision detection. The concept was taken from the reference, Real-Time-Collision-Detection (RTCD), and in particular Ch. 4.2 (page 77): .
double _SqDist_(const Vector &obj) const
Compute the squared-distance to another vector w/o dimension check.
const Point_t & Pt2() const
Direction getter.
const Vector_t Dir() const
Direction getter.
const Point_t & Min() const
Minimum point getter.
void Normalize()
Normalize itself.
double SqLength() const
Compute the squared length of the vector.
double Length() const
Compute the length of the vector.
LineSegment LineSegment_t
double Dot(const Vector &obj) const
bool Contain(const Point_t &pt) const
Test if a point is contained within the box.
static const double kMAX_DOUBLE
bool IsValid() const
Check if point is valid.
const Point_t & Pt1() const
Start getter.
const Point_t & End() const
End getter.
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
Representation of a 3D infinite line. Defines an infinite 3D line by having 2 points which completely...
double Radius() const
Radius getter.
Sphere_t _WelzlSphere_(const std::vector< Point_t > &pts, int numPts, std::vector< Point_t > sosPts) const
const Vector_t & Dir() const
Direction getter.
const Point_t & Center() const
Center getter.
const Point_t & Start() const
Start getter.
Sphere_t _boundingSphere_(const std::vector< Point_t > &pts) const
Representation of a 3D semi-infinite line. Defines a semi-infinite 3D line by having a start point (P...
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
Sphere_t _RemainingPoints_(std::vector< Point_t > &remaining, const Sphere_t &thisSphere) const
then echo File list $list not found else cat $list while read file do echo $file sed s
const Point_t & Max() const
Maximum point getter.
Vector Vector_t
Point has same feature as Vector.
LineSegment_t BoxOverlap(const AABox_t &box, const HalfLine_t &line) const
LineSegment sub-segment of HalfLine inside an AABox.
static const double kINVALID_DOUBLE
std::vector< Point_t > Intersection(const AABox_t &box, const HalfLine_t &line, bool back=false) const
Intersection between a HalfLine and an AABox.
physics associatedGroupsWithLeft p1
double _commonOrigin_(const Line_t &lin1, const Line_t &lin2, Point_t &origin) const
Common origin: Line & Line. Keep track of origin.
constexpr Point origin()
Returns a origin position with a point of the specified type.
Point_t _ClosestPt_(const Point_t &pt, const LineSegment_t &line) const