/usr/include/CGAL/Hyperbola_2.h is in libcgal-dev 4.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | // Copyright (c) 2003,2004 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Menelaos Karavelas <mkaravel@iacm.forth.gr>
#ifndef CGAL_HYPERBOLA_2_H
#define CGAL_HYPERBOLA_2_H
#include <CGAL/enum.h>
#include <CGAL/determinant.h>
#include <CGAL/Apollonius_site_2.h>
#include <CGAL/Kernel_traits.h>
namespace CGAL {
template < class Gt >
class Hyperbola_2
{
public:
typedef Gt Geom_traits;
typedef typename Gt::Site_2 Site_2;
typedef typename Gt::Segment_2 Segment_2;
typedef typename Gt::Point_2 Point_2;
typedef typename Gt::FT FT;
#if 0
typedef typename Kernel_traits<Point>::Kernel Kernel;
typedef CGAL::Apollonius_site_2<Kernel> Site_2;
typedef typename Kernel::Segment_2 Segment_2;
typedef Point Point_2;
typedef typename Kernel::FT FT;
#endif
// typedef typename R::RT FT;
// typedef double FT;
// typedef CGAL::Point_2< Cartesian<double> > Point_2;
// typedef CGAL::Segment_2< Cartesian< double > > Segment_2;
protected:
FT STEP;
Point_2 f1, f2;
FT r;
Point_2 o;
inline
Point_2 lchain(const FT &t) const
{
std::vector< Point_2 > p = compute_points(t);
if ( right(p[0]) ) return p[1];
return p[0];
}
inline
Point_2 rchain(const FT &t) const
{
std::vector< Point_2 > p = compute_points(t);
if ( right(p[0]) ) return p[0];
return p[1];
}
inline
FT norm2(const Point_2& p) const
{
return (CGAL::square(p.x()) + CGAL::square(p.y()));
}
inline
FT distance2(const Point_2& p1, const Point_2& p2) const
{
FT dx = p1.x()-p2.x();
FT dy = p1.y()-p2.y();
return (CGAL::square(dx) + CGAL::square(dy));
}
inline
FT distance(const Point_2& p1, const Point_2& p2) const
{
return CGAL::sqrt( distance2(p1, p2) );
}
void compute_origin()
{
FT dx = f2.x() - f1.x();
FT dy = f2.y() - f1.y();
FT a = CGAL::sqrt(CGAL::square(dx) + CGAL::square(dy));
FT t = (FT(1) + r / a) / FT(2);
o = Point_2(dx * t + f1.x(), dy * t + f1.y());
}
std::vector< Point_2 > compute_points(const FT &d) const {
FT d1 = distance(o, f1) + d;
FT d2 = distance(o, f2) + d;
d1 *= d1;
d2 *= d2;
Point_2 df = Point_2(f2.x() - f1.x(), f2.y()-f1.y());
std::vector< Point_2 > p;
if ( CGAL::is_negative(d) ) return p;
if ( CGAL::is_zero(df.x()) ) {
FT y = (d1 - d2 + norm2(f2) - norm2(f1)) / (FT(2) * df.y());
FT D = d1 - CGAL::square(y - f1.y());
D = CGAL::abs(D);
FT x1 = CGAL::sqrt(D) + f1.x();
FT x2 = -CGAL::sqrt(D) + f1.x();
p.push_back(Point_2(x1, y));
p.push_back(Point_2(x2, y));
return p;
}
FT gamma = (d1 - d2 + norm2(f2) - norm2(f1)) / (FT(2) * df.x());
FT gamma1 = gamma - f1.x();
FT beta = df.y() / df.x();
FT a = FT(1) + CGAL::square(beta);
FT b = -FT(2) * (gamma1 * beta + f1.y());
FT c = CGAL::square(f1.y()) + CGAL::square(gamma1) - d1;
FT D = CGAL::square(b) - FT(4) * a * c;
D = CGAL::abs(D);
FT y1 = (-b + CGAL::sqrt(D)) / (FT(2) * a);
FT y2 = (-b - CGAL::sqrt(D)) / (FT(2) * a);
FT x1 = gamma - beta * y1;
FT x2 = gamma - beta * y2;
p.push_back(Point_2(x1, y1));
p.push_back(Point_2(x2, y2));
return p;
}
bool right(const Point_2& p) const
{
return
CGAL::is_negative( determinant<FT>(f1.x(), f1.y(), 1,
f2.x(), f2.y(), 1,
p.x(), p.y(), 1) );
}
inline
Point_2 midpoint(const Point_2& p1, const Point_2& p2) const
{
FT t1 = t(p1);
FT t2 = t(p2);
FT midt = (t1+t2)/2;
return f(midt);
}
inline
Point_2 f(FT t) const
{
if ( CGAL::is_negative(t) ) return rchain(-t);
return lchain(t);
}
inline
FT t(const Point_2 &p) const
{
FT tt = distance(f1, p) - distance(f1, o);
if ( right(p) ) return -tt;
return tt;
}
public:
Hyperbola_2() { STEP = FT(2); }
Hyperbola_2(const Site_2 &ff1, const Site_2 &ff2)
{
STEP = FT(2);
this->r = ff1.weight() - ff2.weight();
this->f1 = ff1.point();
this->f2 = ff2.point();
compute_origin();
}
Oriented_side
side_of_hyperbola(const Point_2 &p) const
{
double dist = distance(p, f1) - distance(p, f2) - r;
if ( dist < 0 ) return ON_NEGATIVE_SIDE;
if ( dist > 0 ) return ON_POSITIVE_SIDE;
return ON_ORIENTED_BOUNDARY;
}
template<class QTWIDGET>
void generate_points_qt(const QTWIDGET& W,
std::vector<Point_2>& pleft,
std::vector<Point_2>& pright) const
{
std::vector< Point_2 > p;
pleft.push_back(o);
pright.push_back(o);
double width = W.x_max() - W.x_min();
double height = W.y_max() - W.y_min();
FT STEP;
if ( width < height ) {
STEP = width / 500.0;
} else {
STEP = height / 500.0;
}
// double mind = distance(o, f1) - r1;
for (int i = 1; i <= 100; i++) {
p = compute_points(FT(i * i) * STEP);
if ( p.size() > 0 ) {
if ( right(p[0]) ) {
pright.push_back(p[0]);
pleft.push_back(p[1]);
} else {
pright.push_back(p[1]);
pleft.push_back(p[0]);
}
}
}
}
template<class QTWIDGET>
void draw_qt(QTWIDGET& W) const
{
std::vector< Point_2 > pleft, pright;
generate_points_qt(pleft, pright);
for (unsigned int i = 0; i < pleft.size() - 1; i++) {
W << Segment_2(pleft[i], pleft[i+1]);
}
for (unsigned int i = 0; i < pright.size() - 1; i++) {
W << Segment_2(pright[i], pright[i+1]);
}
}
void generate_points(std::vector<Point_2>& pleft,
std::vector<Point_2>& pright) const
{
std::vector< Point_2 > p;
pleft.push_back(o);
pright.push_back(o);
// double mind = distance(o, f1) - r1;
for (int i = 1; i <= 100; i++) {
p = compute_points(FT(i * i) * STEP);
if ( p.size() > 0 ) {
if ( right(p[0]) ) {
pright.push_back(p[0]);
pleft.push_back(p[1]);
} else {
pright.push_back(p[1]);
pleft.push_back(p[0]);
}
}
}
}
template< class Stream >
void draw(Stream &W) const
{
std::vector< Point_2 > pleft, pright;
generate_points(pleft,pright);
for (unsigned int i = 0; i < pleft.size() - 1; i++) {
W << Segment_2(pleft[i], pleft[i+1]);
}
for (unsigned int i = 0; i < pright.size() - 1; i++) {
W << Segment_2(pright[i], pright[i+1]);
}
}
};
template< class Stream, class Gt >
inline
Stream& operator<<(Stream& s, const Hyperbola_2<Gt> &H)
{
H.draw(s);
return s;
}
} //namespace CGAL
#endif // CGAL_HYPERBOLA_2_H
|