Circle.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* This software is distributed under the Lesser General Public License */
  2. //
  3. // Circle.cpp
  4. //
  5. // This file implements the class GT_Circle.
  6. //
  7. //------------------------------------------
  8. //
  9. // $Source: /home/br/CVS/graphlet/src/gt_base/Circle.cpp,v $
  10. // $Author: himsolt $
  11. // $Revision: 1.2 $
  12. // $Date: 1999/03/05 20:43:13 $
  13. // $Locker: $
  14. // $State: Exp $
  15. //
  16. //------------------------------------------
  17. //
  18. // (C) University of Passau 1995-1999, graphlet project
  19. //
  20. #include "Graphlet.h"
  21. #include "Circle.h"
  22. #include <cmath>
  23. bool
  24. GT_Circle::intersection (GT_Segment s) {
  25. double dist = s.distance (middle);
  26. double m_to_p1 = middle.distance (s.source());
  27. double m_to_p2 = middle.distance (s.target());
  28. if (radius < dist) {
  29. return false;
  30. } else if (m_to_p1 < radius && m_to_p2 < radius) {
  31. return false;
  32. }
  33. return true;
  34. }
  35. double
  36. GT_Circle::distance_between_intersecting_points (GT_Segment s) {
  37. double dist = s.distance (middle);
  38. double m_to_p1 = middle.distance (s.source());
  39. double m_to_p2 = middle.distance (s.target());
  40. if (radius < dist) {
  41. return -1; // no intersection
  42. } else if (m_to_p1 < radius && m_to_p2 < radius) {
  43. return -1; // no intersection
  44. }
  45. return 2 * sqrt (pow (dist, 2) + pow (radius, 2));
  46. }