48 double dABAB = AB.
Dot(AB);
49 double dACAC = AC.
Dot(AC);
50 double dABAC = AB.
Dot(AC);
52 double d = dABAB * dACAC - dABAC * dABAC;
58 double lenAB = AB.
Length();
59 double lenAC = AC.
Length();
60 double lenBC = BC.
Length();
62 if ( (lenAB > lenAC) && (lenAB > lenBC) ){
66 else if( lenAC > lenBC ){
77 s = 0.5 * ( dABAB * dACAC - dACAC * dABAC ) / d;
78 t = 0.5 * ( dACAC * dABAB - dABAB * dABAC ) / d;
81 if ( (s > 0) && (t > 0) && ((1-s-t) > 0) ){
192 std::vector<geoalgo::Point_t> valid_points = {A};
193 bool duplicate =
false;
194 for (
auto const& pt : valid_points){
195 if (pt.SqDist(B) < 0.0001)
198 if (duplicate ==
false)
199 valid_points.push_back(B);
201 for (
auto const& pt : valid_points){
202 if (pt.SqDist(C) < 0.0001)
205 if (duplicate ==
false)
206 valid_points.push_back(C);
208 for (
auto const& pt : valid_points){
209 if (pt.SqDist(D) < 0.0001)
212 if (duplicate ==
false)
213 valid_points.push_back(D);
216 if (valid_points.size() < 4){
217 (*this) =
Sphere(valid_points);
226 double dABAB = AB.
Dot(AB);
227 double dACAC = AC.
Dot(AC);
228 double dADAD = AD.
Dot(AD);
229 double dABAC = AB.
Dot(AC);
230 double dABAD = AB.
Dot(AD);
231 double dACAD = AC.
Dot(AD);
233 double d = 4*dABAC*dABAD*dACAD;
239 throw GeoAlgoException(
"GeoSphere Exception: I think it means 3 points collinear. Find out which and call 3 point constructor - TO DO");
242 double s = (dABAC*dACAD*dADAD + dABAD*dACAC*dACAD - dABAB*dACAD*dACAD)/d;
243 double t = (dABAB*dACAD*dABAD + dABAD*dABAC*dADAD - dABAD*dABAD*dACAC)/d;
244 double u = (dABAB*dABAC*dACAD + dABAC*dABAD*dACAC - dABAC*dABAC*dADAD)/d;
247 if ( (s > 0) && (t > 0) && (u > 0) && ((1-s-t-u) > 0) ){
248 _center = A + AB*s + AC*t + AD*u;
253 double maxdist = A.
Dist(B);
256 if (A.
Dist(C) > maxdist){
261 if (A.
Dist(D) > maxdist){
266 if (B.
Dist(C) > maxdist){
271 if (B.
Dist(D) > maxdist){
276 if (C.
Dist(D) > maxdist){
332 case 2: (*this) =
Sphere(pts[0],pts[1]);
334 case 3: (*this) =
Sphere(pts[0],pts[1],pts[2]);
336 case 4: (*this) =
Sphere(pts[0],pts[1],pts[2],pts[3]);
339 throw GeoAlgoException(
"Cannot call Sphere constructor with more than 4 points. Something went wront");
365 if(p.size()!=3)
throw GeoAlgoException(
"Only 3D points allowed for sphere");
370 {
if(r<0)
throw GeoAlgoException(
"Only positive value allowed for radius"); }
bool Contain(const Point_t &p) const
Judge if a point is contained within a sphere.
Class def header for a class GeoAlgoException.
void compat(const Vector &obj) const
Dimensional check for a compatibility.
double Dist(const Vector &obj) const
Compute the distance to another vector.
double Length() const
Compute the length of the vector.
double Dot(const Vector &obj) const
Class def header for a class HalfLine.
double Radius() const
Radius getter.
const Point_t & Center() const
Center getter.
Point_t _center
Center of Sphere.
void compat(const Point_t &p, const double r=0) const
3D point compatibility check
double _radius
Radius of Sphere.
double _Dist_(const Vector &obj) const
Compute the distance to another vector w/o dimension check.
QTextStream & endl(QTextStream &s)