55 double dABAB = AB.
Dot(AB);
56 double dACAC = AC.
Dot(AC);
57 double dABAC = AB.
Dot(AC);
59 double d = dABAB * dACAC - dABAC * dABAC;
64 std::cout <<
"d is 0!" << std::endl;
65 double lenAB = AB.
Length();
66 double lenAC = AC.
Length();
67 double lenBC = BC.
Length();
69 if ((lenAB > lenAC) && (lenAB > lenBC)) {
73 else if (lenAC > lenBC) {
84 s = 0.5 * (dABAB * dACAC - dACAC * dABAC) / d;
85 t = 0.5 * (dACAC * dABAB - dABAB * dABAC) / d;
88 if ((s > 0) && (t > 0) && ((1 - s - t) > 0)) {
89 _center = A + (B - A) * s + (C - A) * t;
199 std::vector<geoalgo::Point_t> valid_points = {A};
200 bool duplicate =
false;
201 for (
auto const&
pt : valid_points) {
202 if (
pt.SqDist(B) < 0.0001) duplicate =
true;
204 if (duplicate ==
false) valid_points.push_back(B);
206 for (
auto const&
pt : valid_points) {
207 if (
pt.SqDist(C) < 0.0001) duplicate =
true;
209 if (duplicate ==
false) valid_points.push_back(C);
211 for (
auto const&
pt : valid_points) {
212 if (
pt.SqDist(D) < 0.0001) duplicate =
true;
214 if (duplicate ==
false) valid_points.push_back(D);
217 if (valid_points.size() < 4) {
218 (*this) =
Sphere(valid_points);
227 double dABAB = AB.
Dot(AB);
228 double dACAC = AC.
Dot(AC);
229 double dADAD = AD.
Dot(AD);
230 double dABAC = AB.
Dot(AC);
231 double dABAD = AB.
Dot(AD);
232 double dACAD = AC.
Dot(AD);
234 double d = 4 * dABAC * dABAD * dACAD;
240 throw GeoAlgoException(
"GeoSphere Exception: I think it means 3 points collinear. Find out " 241 "which and call 3 point constructor - TO DO");
244 double s = (dABAC * dACAD * dADAD + dABAD * dACAC * dACAD - dABAB * dACAD * dACAD) / d;
245 double t = (dABAB * dACAD * dABAD + dABAD * dABAC * dADAD - dABAD * dABAD * dACAC) / d;
246 double u = (dABAB * dABAC * dACAD + dABAC * dABAD * dACAC - dABAC * dABAC * dADAD) / d;
249 if ((s > 0) && (t > 0) && (u > 0) && ((1 - s - t - u) > 0)) {
250 _center = A + AB * s + AC * t + AD * u;
255 double maxdist = A.
Dist(B);
258 if (A.
Dist(C) > maxdist) {
263 if (A.
Dist(D) > maxdist) {
268 if (B.
Dist(C) > maxdist) {
273 if (B.
Dist(D) > maxdist) {
278 if (C.
Dist(D) > maxdist) {
324 switch (pts.size()) {
326 case 1:
_center = pts.front();
break;
327 case 2: (*this) =
Sphere(pts[0], pts[1]);
break;
328 case 3: (*this) =
Sphere(pts[0], pts[1], pts[2]);
break;
329 case 4: (*this) =
Sphere(pts[0], pts[1], pts[2], pts[3]);
break;
332 "Cannot call Sphere constructor with more than 4 points. Something went wront");
373 if (p.size() != 3)
throw GeoAlgoException(
"Only 3D points allowed for sphere");
379 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.