circle.h
Upload User: gzelex
Upload Date: 2007-01-07
Package Size: 707k
Code Size: 5k
Development Platform:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  circle.h
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #ifndef LEDA_CIRCLE_H
  12. #define LEDA_CIRCLE_H
  13. #include <LEDA/point.h>
  14. #include <LEDA/segment.h>
  15. #include <LEDA/line.h>
  16. //------------------------------------------------------------------------------
  17. // circles
  18. //------------------------------------------------------------------------------
  19. class circle_rep : public handle_rep {
  20. friend class circle;
  21.   double  radius;
  22.   point   center; 
  23.   
  24. public:
  25.   circle_rep() {}
  26.   circle_rep(const point& p, double r)  { center = p; radius = r; }
  27.  ~circle_rep() {}
  28. };
  29. /*{Manpage {circle} {} {Circles} }*/ 
  30. class circle   : public handle_base 
  31. {
  32. /*{Mdefinition
  33. An instance $C$ of the data type $circle$ is a circle in the two-dimensional
  34. plane, i.e., the set of points having a certain distance $r$ from a given
  35. point $p$. $r$ is called the radius and $p$ is called the center of $C$.
  36. The circle with center $(0,0)$ and radius $0$ is called the empty circle.}*/
  37. circle_rep* ptr() const { return (circle_rep*)PTR; }
  38. public:
  39. /*{Mcreation C }*/ 
  40. circle(const point& c, double r);
  41. /*{Mcreate introduces a variable $C$ of type $circle$. $C$ is initialized to 
  42.             the circle with center $c$ and radius $r$.}*/
  43. circle(double x, double y, double r);
  44. /*{Mcreate introduces a variable $C$ of type $circle$. $C$ is initialized to 
  45.             the circle with center $(x,y)$ and radius $r$.}*/
  46. circle(const point& a, const point& b, const point& c);
  47. /*{Mcreate introduces a variable $C$ of type $circle$. $C$ is initialized to 
  48.             the circle through points $a$, $b$, and $c$. precond $a$, $b$,
  49.             and $c$ are not collinear. }*/
  50. circle();
  51. /*{Mcreate introduces a variable $C$ of type $circle$. $C$ is initialized to 
  52.             the empty circle.}*/
  53.  circle(const circle& c) : handle_base(c) {}
  54. ~circle() {}
  55.  circle& operator=(const circle& C) { handle_base::operator=(C); return *this; }
  56. /*{Moperations 2.2 4.7 }*/
  57. point center()  const { return ptr()->center; } 
  58. /*{Mop  returns the center of var.}*/
  59. double radius() const { return ptr()->radius; }
  60. /*{Mop  returns the radius of var.}*/
  61. list<point> intersection(const circle& D) const;
  62. /*{Mop    returns $C cap D$ as a list of points.}*/
  63. list<point> intersection(const line& l) const;
  64. /*{Mop  returns $C cap l$ as a list of points.}*/
  65. list<point> intersection(const segment& s) const;
  66. /*{Mop   returns $C cap s$ as a list of points.}*/
  67. segment left_tangent(const point& p) const;
  68. /*{Mop   returns the line segment starting in $p$ tangent 
  69.   to var and left of segment $[p,C.center()]$.}*/
  70. segment right_tangent(const point& p) const;
  71. /*{Mop   returns the line segment starting in $p$ tangent 
  72.   to var and right of segment $[p,C.center()]$.}*/
  73. double  distance(const point& p) const;
  74. /*{Mop   returns the distance between var and $p$ 
  75.   (negative if $p$ inside var).}*/
  76. double  distance(const line& l) const;
  77. /*{Mop    returns the distance between var and $l$  
  78.    (negative if $l$ intersects var).}*/
  79. double  distance(const circle& D) const;
  80. /*{Mop    returns the distance between var and $D$ 
  81.    (negative if $D$ intersects var).}*/
  82. bool    inside(const point& p) const;
  83. /*{Mop   returns true if $p$ lies inside of var, 
  84.   false otherwise.}*/
  85. bool    outside(const point& p) const { return !inside(p); };
  86. /*{Mop     returns !var.inside($p$).}*/
  87. circle  translate(double a, double d) const;
  88. /*{Mopl    returns the circle created by a translation of 
  89.     $C$ in direction $a$ by distance $d$.}*/
  90. circle  translate(const vector& v) const; 
  91. /*{Mop    returns $C+v$, i.e., the circle created by 
  92.    translating $C$ by vector $v$.\
  93.    precond
  94.    $v$.dim() = 2.}*/
  95. circle  operator+(const vector& v) const { return translate(v); }
  96. circle  rotate(const point& q, double a) const;
  97. /*{Mopl    returns the circle created by a rotation of $C$ 
  98.     about point $q$ by angle $a$.}*/
  99. circle  rotate(double a) const;
  100. /*{Mop    returns the circle created by a rotation of $C$ 
  101.     about the origin by angle $a$.}*/
  102. bool operator==(const circle& D) const;
  103. /*{Mbinop    Test for equality.}*/
  104. bool operator!=(const circle& D) const { return !operator==(D); };
  105. /*{Mbinop    Test for inequality.}*/
  106. friend ostream& operator<<(ostream& out, const circle& c);
  107. friend istream& operator>>(istream& in, circle& c);  
  108. };
  109. inline void Print(const circle& c, ostream& out) { out << c; } 
  110. inline void Read(circle& c,  istream& in)        { in >> c; }
  111. #endif