Commit 8c561a1e authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Add a get_overlap() function to estimate overlap of two spheres

parent 66aa4791
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -668,4 +668,20 @@ int *check_overlaps(
  ScattererConfiguration *sconf, GeometryConfiguration *gconf, const double tolerance=0.0
  ScattererConfiguration *sconf, GeometryConfiguration *gconf, const double tolerance=0.0
);
);


  /*! \brief Get the overlap among two spheres.
   *
   * This function computes the thickness of the compenetration between
   * two spheres, in order to compare it with the current tolerance settings.
   *
   * \param sconf: `ScattererConfiguration *` Pointer to a ScattererConfiguration instance.
   * \param gconf: `GeometryConfiguration *` Pointer to a GeometryConfiguration instance.
   * \param index_0: `const int` Index of the first sphere.
   * \param index_1: `const int` Index of the second sphere.
   * \return overlap: `double` The thickness of the overlapping layer in meters.
   */
double get_overlap(
  ScattererConfiguration *sconf, GeometryConfiguration *gconf,
  const int index_0, const int index_1
);

#endif // INCLUDE_CONFIGURATION_H_
#endif // INCLUDE_CONFIGURATION_H_
+20 −0
Original line number Original line Diff line number Diff line
@@ -1595,3 +1595,23 @@ int *check_overlaps(
  delete[] index_matrix;
  delete[] index_matrix;
  return vec_overlaps;
  return vec_overlaps;
}
}

double get_overlap(
  ScattererConfiguration *sconf, GeometryConfiguration *gconf,
  const int index_0, const int index_1
) {
  const double x0 = gconf->get_sph_x(index_0);
  const double y0 = gconf->get_sph_y(index_0);
  const double z0 = gconf->get_sph_z(index_0);
  const double x1 = gconf->get_sph_x(index_1);
  const double y1 = gconf->get_sph_y(index_1);
  const double z1 = gconf->get_sph_z(index_1);
  const double r0 = sconf->get_radius(index_0);
  const double r1 = sconf->get_radius(index_1);
  const double r_sum = (r0 + r1);
  const double dist2 = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)
    + (z1 - z0) * (z1 - z0);
  const double dist = sqrt(dist2);
  double result = (dist > r_sum) ? 0.0 : r_sum - dist;
  return result;
}