- More bisector() functions.

This commit is contained in:
Sylvain Pion 2003-12-04 09:45:57 +00:00
parent c5d4a32c14
commit cee8ecd658
19 changed files with 317 additions and 40 deletions

View File

@ -1,3 +1,6 @@
Version 102.7 (4 December 2003)
- More bisector() functions.
Version 102.6 (3 December 2003)
- Add parallel().

View File

@ -893,6 +893,16 @@ namespace CartesianKernelFunctors {
bisector_of_pointsC2(p.x(), p.y(), q.x(), q.y(), a, b, c);
return Line_2(a, b, c);
}
Line_2
operator()(const Line_2& p, const Line_2& q) const
{
FT a, b, c;
bisector_of_linesC2(p.a(), p.b(), p.c(),
q.a(), q.b(), q.c(),
a, b, c);
return Line_2(a, b, c);
}
};
template <typename K>
@ -914,6 +924,16 @@ namespace CartesianKernelFunctors {
a, b, c, d);
return Plane_3(a, b, c, d);
}
Plane_3
operator()(const Plane_3& p, const Plane_3& q) const
{
FT a, b, c, d;
bisector_of_planesC3(p.a(), p.b(), p.c(), p.d(),
q.a(), q.b(), q.c(), q.d(),
a, b, c, d);
return Plane_3(a, b, c, d);
}
};
template <typename K>

View File

@ -47,15 +47,6 @@ line_from_point_direction(const PointC2<K> &p,
return K().construct_line_2_object()(p, d);
}
template < class K >
inline
LineC2<K>
bisector(const PointC2<K> &p,
const PointC2<K> &q)
{
return K().construct_bisector_2_object()(p, q);
}
template < class K >
inline
LineC2<K>

View File

@ -56,14 +56,6 @@ plane_from_point_direction(const PointC3<R> &p,
return PlaneC3<R>(A, B, C, D);
}
template <typename K>
inline
typename K::Plane_3
bisector(const PointC3<K> &p, const PointC3<K> &q)
{
return K().construct_bisector_3_object()(p, q);
}
CGAL_END_NAMESPACE
#endif // CGAL_CARTESIAN_PLANE_CONSTRUCTIONS_3_H

View File

@ -142,6 +142,28 @@ bisector_of_pointsC2(const FT &px, const FT &py,
CGAL_NTS square(px) - CGAL_NTS square(py);
}
template < class FT >
CGAL_KERNEL_INLINE
void
bisector_of_linesC2(const FT &pa, const FT &pb, const FT &pc,
const FT &qa, const FT &qb, const FT &qc,
FT &a, FT &b, FT &c)
{
// We normalize the equations of the 2 lines, and we then add them.
FT n1 = CGAL_NTS sqrt(CGAL_NTS square(pa) + CGAL_NTS square(pb));
FT n2 = CGAL_NTS sqrt(CGAL_NTS square(qa) + CGAL_NTS square(qb));
a = n2 * pa + n1 * qa;
b = n2 * pb + n1 * qb;
c = n2 * pc + n1 * qc;
// Care must be taken for the case when this produces a degenerate line.
if (a == 0 && b == 0) {
a = n2 * pa - n1 * qa;
b = n2 * pb - n1 * qb;
c = n2 * pc - n1 * qc;
}
}
template < class FT >
inline
FT

View File

@ -398,6 +398,31 @@ bisector_of_pointsC3(const FT &px, const FT &py, const FT &pz,
- CGAL_NTS square(px) - CGAL_NTS square(py) - CGAL_NTS square(pz);
}
template < class FT >
void
bisector_of_planesC3(const FT &pa, const FT &pb, const FT &pc, const FT &pd,
const FT &qa, const FT &qb, const FT &qc, const FT &qd,
FT &a, FT &b, FT &c, FT &d)
{
// We normalize the equations of the 2 planes, and we then add them.
FT n1 = CGAL_NTS sqrt(CGAL_NTS square(pa) + CGAL_NTS square(pb) +
CGAL_NTS square(pc));
FT n2 = CGAL_NTS sqrt(CGAL_NTS square(qa) + CGAL_NTS square(qb) +
CGAL_NTS square(qc));
a = n2 * pa + n1 * qa;
b = n2 * pb + n1 * qb;
c = n2 * pc + n1 * qc;
d = n2 * pd + n1 * qd;
// Care must be taken for the case when this produces a degenerate line.
if (a == 0 && b == 0 && c == 0) {
a = n2 * pa - n1 * qa;
b = n2 * pb - n1 * qb;
c = n2 * pc - n1 * qc;
d = n2 * pd - n1 * qd;
}
}
CGAL_END_NAMESPACE
#endif // CGAL_CONSTRUCTIONS_KERNEL_FTC3_H

View File

@ -1,3 +1,6 @@
2.108 (4 December 2003)
- More bisector() functions.
2.107 (3 December 2003)
- Add parallel().

View File

@ -42,14 +42,6 @@ gp_linear_intersection(const LineH2<R>& l1, const LineH2<R>& l2)
l1.a()*l2.b() - l2.a()*l1.b() );
}
template <typename K>
CGAL_KERNEL_MEDIUM_INLINE
typename K::Line_2
bisector( const PointH2<K>& p, const PointH2<K>& q )
{
return K().construct_bisector_2_object()(p, q);
}
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
typename R::FT

View File

@ -1319,6 +1319,7 @@ namespace HomogeneousKernelFunctors {
template <typename K>
class Construct_bisector_2
{
typedef typename K::RT RT;
typedef typename K::FT FT;
typedef typename K::Point_2 Point_2;
typedef typename K::Line_2 Line_2;
@ -1329,8 +1330,6 @@ namespace HomogeneousKernelFunctors {
Line_2
operator()(const Point_2& p, const Point_2& q) const
{
typedef typename K::RT RT;
// Bisector equation is based on equation
// ( X - p.x())^2 + (Y - p.y())^2 == ( X - q.x())^2 + (Y - q.y())
// and x() = hx()/hw() ...
@ -1349,11 +1348,22 @@ namespace HomogeneousKernelFunctors {
return Line_2( a, b, c );
}
Line_2
operator()(const Line_2& p, const Line_2& q) const
{
RT a, b, c;
bisector_of_linesC2(p.a(), p.b(), p.c(),
q.a(), q.b(), q.c(),
a, b, c);
return Line_2(a, b, c);
}
};
template <typename K>
class Construct_bisector_3
{
typedef typename K::RT RT;
typedef typename K::FT FT;
typedef typename K::Point_3 Point_3;
typedef typename K::Plane_3 Plane_3;
@ -1364,8 +1374,6 @@ namespace HomogeneousKernelFunctors {
Plane_3
operator()(const Point_3& p, const Point_3& q) const
{
typedef typename K::RT RT;
// Bisector equation is based on equation
// ( X - p.x())^2 + (Y - p.y())^2 == ( X - q.x())^2 + (Y - q.y())
// and x() = hx()/hw() ...
@ -1387,6 +1395,16 @@ namespace HomogeneousKernelFunctors {
return Plane_3( a, b, c, d );
}
Plane_3
operator()(const Plane_3& p, const Plane_3& q) const
{
RT a, b, c, d;
bisector_of_planesC3(p.a(), p.b(), p.c(), p.d(),
q.a(), q.b(), q.c(), q.d(),
a, b, c, d);
return Plane_3(a, b, c, d);
}
};

View File

@ -1,3 +1,6 @@
2.70 (4 December 2003)
- More bisector() functions.
2.69 (19 November 2003)
- Added bisector(Point_3, Point_3).

View File

@ -95,15 +95,6 @@ typename R::FT
squared_distance( PointH3<R> const& p, PointH3<R> const& q)
{ return (p-q)*(p-q); }
template <typename K>
CGAL_KERNEL_MEDIUM_INLINE
typename K::Plane_3
bisector( const PointH3<K>& p, const PointH3<K>& q )
{
return K().construct_bisector_3_object()(p, q);
}
template <class R>
CGAL_KERNEL_MEDIUM_INLINE
PointH3<R>
@ -222,8 +213,10 @@ circumcenter( PointH3<R> const& p,
PointH3<R> const& r)
{
return gp_linear_intersection( PlaneH3<R>(p,q,r),
bisector(p,q),
bisector(p,r));
bisector(static_cast<const Point_3<R>& >(p),
static_cast<const Point_3<R>& >(q)),
bisector(static_cast<const Point_3<R>& >(p),
static_cast<const Point_3<R>& >(r)));
}
template <class R>

View File

@ -1,3 +1,6 @@
1.94 (4 December 2003)
- More bisector() functions.
1.93 (2 December 2003)
- Add parallel().

View File

@ -9,7 +9,22 @@ A model for this must provide:
The bisector is oriented in such a way that \ccc{p} lies on its
positive side. \ccPrecond{\ccc{p} and \ccc{q} are not equal.}}
\ccMemberFunction{Kernel::Line_2 operator()(const Kernel::Line_2&l1,
const Kernel::Line_2&l2);}
{constructs the bisector of the two lines $l1$ and $l2$.
In the general case, the bisector has the direction of the vector which
is the sum of the normalized directions of the two lines, and which passes
through the intersection of \ccc{l1} and \ccc{l2}.
If \ccc{l1} and \ccc{l2} are parallel, then the bisector is defined as the line
which has the same direction as \ccc{l1}, and which is at the same distance
from \ccc{l1} and \ccc{l2}.
This function requires that \ccc{Kernel::RT} supports the \ccc{sqrt()}
operation.}
\ccRefines
AdaptableFunctor (with two arguments)
\ccSeeAlso
\ccRefIdfierPage{CGAL::bisector}
\end{ccRefFunctionObjectConcept}

View File

@ -9,7 +9,22 @@ A model for this must provide:
The bisector is oriented in such a way that \ccc{p} lies on its
positive side. \ccPrecond{\ccc{p} and \ccc{q} are not equal.}}
\ccMemberFunction{Kernel::Plane_3 operator()(const Kernel::Plane_3&h1,
const Kernel::Plane_3&h2);}
{constructs the bisector of the two planes $h1$ and $h2$.
In the general case, the bisector has a normal vector which has the same
direction as the sum of the normalized normal vectors of the two planes, and
passes through the intersection of \ccc{h1} and \ccc{h2}.
If \ccc{h1} and \ccc{h2} are parallel, then the bisector is defined as the
plane which has the same oriented normal vector as \ccc{l1}, and which is at
the same distance from \ccc{h1} and \ccc{h2}.
This function requires that \ccc{Kernel::RT} supports the \ccc{sqrt()}
operation.}
\ccRefines
AdaptableFunctor (with two arguments)
\ccSeeAlso
\ccRefIdfierPage{CGAL::bisector}
\end{ccRefFunctionObjectConcept}

View File

@ -6,10 +6,34 @@
The bisector is oriented in such a way that \ccc{p} lies on its
positive side. \ccPrecond{\ccc{p} and \ccc{q} are not equal.}}
\ccFunction{Line_2<Kernel> bisector(const Line_2<Kernel> &l1,
const Line_2<Kernel> &l2);}
{constructs the bisector of the two lines $l1$ and $l2$.
In the general case, the bisector has the direction of the vector which
is the sum of the normalized directions of the two lines, and which passes
through the intersection of \ccc{l1} and \ccc{l2}.
If \ccc{l1} and \ccc{l2} are parallel, then the bisector is defined as the line
which has the same direction as \ccc{l1}, and which is at the same distance
from \ccc{l1} and \ccc{l2}.
This function requires that \ccc{Kernel::RT} supports the \ccc{sqrt()}
operation.}
\ccFunction{Plane_3<Kernel> bisector(const Point_3<Kernel> &p,
const Point_3<Kernel> &q);}
{constructs the bisector plane of the two points \ccc{p} and \ccc{q}.
The bisector is oriented in such a way that \ccc{p} lies on its
positive side. \ccPrecond{\ccc{p} and \ccc{q} are not equal.}}
\ccFunction{Plane_3<Kernel> bisector(const Plane_3<Kernel> &h1,
const Plane_3<Kernel> &h2);}
{constructs the bisector of the two planes $h1$ and $h2$.
In the general case, the bisector has a normal vector which has the same
direction as the sum of the normalized normal vectors of the two planes, and
passes through the intersection of \ccc{h1} and \ccc{h2}.
If \ccc{h1} and \ccc{h2} are parallel, then the bisector is defined as the
plane which has the same oriented normal vector as \ccc{l1}, and which is at
the same distance from \ccc{h1} and \ccc{h2}.
This function requires that \ccc{Kernel::RT} supports the \ccc{sqrt()}
operation.}
\end{ccRefFunction}

View File

@ -26,8 +26,44 @@
// Generic functions calling the kernel functor.
#include <CGAL/user_classes.h>
CGAL_BEGIN_NAMESPACE
template <typename K>
inline
typename K::Line_2
bisector(const typename K::Point_2 &p,
const typename K::Point_2 &q, const K &k)
{
return k.construct_bisector_2_object()(p, q);
}
template <typename K>
inline
typename K::Line_2
bisector(const typename K::Line_2 &l1,
const typename K::Line_2 &l2, const K &k)
{
return k.construct_bisector_2_object()(l1, l2);
}
template <typename K>
inline
typename K::Line_2
bisector(const Point_2<K> &p, const Point_2<K> &q)
{
return bisector(p, q, K());
}
template <typename K>
inline
typename K::Line_2
bisector(const Line_2<K> &l1, const Line_2<K> &l2)
{
return bisector(l1, l2, K());
}
template <typename K>
inline
bool

View File

@ -28,6 +28,40 @@
CGAL_BEGIN_NAMESPACE
template <typename K>
inline
typename K::Plane_3
bisector(const typename K::Point_3 &p,
const typename K::Point_3 &q, const K &k)
{
return k.construct_bisector_3_object()(p, q);
}
template <typename K>
inline
typename K::Plane_3
bisector(const typename K::Plane_3 &h1,
const typename K::Plane_3 &h2, const K &k)
{
return k.construct_bisector_3_object()(h1, h2);
}
template <typename K>
inline
typename K::Plane_3
bisector(const Point_3<K> &p, const Point_3<K> &q)
{
return bisector(p, q, K());
}
template <typename K>
inline
typename K::Plane_3
bisector(const Plane_3<K> &h1, const Plane_3<K> &h2)
{
return bisector(h1, h2, K());
}
template <typename K>
inline
bool

View File

@ -22,6 +22,46 @@
#ifndef CGAL__TEST_FCT_LINE_2_H
#define CGAL__TEST_FCT_LINE_2_H
// Accessory function testing functions that require sqrt().
// Doesn't instantiate anything if RT doesn't support sqrt().
template <class R>
bool
_test_fct_line_sqrt_2(const R&, CGAL::Tag_false)
{
bool UNTESTED_STUFF_BECAUSE_SQRT_IS_NOT_SUPPORTED;
std::cout << std::endl
<< "WARNING : FT doesn't support sqrt(),"
" hence some functions are not tested." << std::endl;
return true;
}
template <class R>
bool
_test_fct_line_sqrt_2(const R&, CGAL::Tag_true)
{
typedef typename R::Point_2 Point_2;
typedef typename R::Line_2 Line_2;
// bisector of 2 lines (uses sqrt()...)
Point_2 q0(0, 0, 1);
Point_2 q1(1, 0, 1);
Point_2 q2(0, 1, 1);
Point_2 q3(1, 1, 1);
Point_2 q4(2, 0, 1);
Line_2 ql1 (q0, q1);
Line_2 ql2 (q0, q2);
Line_2 ql3 (q0, q3);
Line_2 ql4 (q0, q4);
Line_2 ql5 (q1, q0);
Line_2 bl3 = CGAL::bisector(ql1, ql2);
assert( bl3 == ql3 );
assert( CGAL::bisector(ql4, ql2) == ql3 );
assert( CGAL::bisector(ql1, ql5) == ql1 );
return true;
}
template <class R>
bool
@ -142,6 +182,9 @@ _test_fct_line_2(const R& )
assert(bl1.oriented_side(p2) == CGAL::ON_POSITIVE_SIDE);
assert( CGAL::parallel(bl1, bl2) );
// More tests, that require sqrt().
_test_fct_line_sqrt_2(R(), typename CGAL::Number_type_traits<FT>::Has_sqrt());
std::cout << "done" << std::endl;
return true;
}

View File

@ -21,6 +21,48 @@
#ifndef CGAL__TEST_FCT_PLANE_3_H
#define CGAL__TEST_FCT_PLANE_3_H
// Accessory function testing functions that require sqrt().
// Doesn't instantiate anything if RT doesn't support sqrt().
template <class R>
bool
_test_fct_plane_sqrt_3(const R&, CGAL::Tag_false)
{
bool UNTESTED_STUFF_BECAUSE_SQRT_IS_NOT_SUPPORTED;
std::cout << std::endl
<< "WARNING : FT doesn't support sqrt(),"
" hence some functions are not tested." << std::endl;
return true;
}
template <class R>
bool
_test_fct_plane_sqrt_3(const R&, CGAL::Tag_true)
{
typedef typename R::Point_3 Point_3;
typedef typename R::Plane_3 Plane_3;
// bisector of 2 planes
Point_3 q0(0, 0, 0, 1);
Point_3 q1(1, 0, 0, 1);
Point_3 q2(0, 1, 0, 1);
Point_3 q3(1, 1, 0, 1);
Point_3 q4(2, 0, 0, 1);
Point_3 q5(0, 0, 1, 1);
Plane_3 ql1 (q0, q1, q5);
Plane_3 ql2 (q0, q2, q5);
Plane_3 ql3 (q0, q3, q5);
Plane_3 ql4 (q0, q4, q5);
Plane_3 ql5 (q1, q0, q5);
Plane_3 bl3 = CGAL::bisector(ql1, ql2);
assert( bl3 == ql3 );
assert( CGAL::bisector(ql4, ql2) == ql3 );
assert( CGAL::bisector(ql1, ql5) == ql1 );
return true;
}
template <class R>
bool
_test_fct_plane_3(const R& )
@ -59,6 +101,9 @@ _test_fct_plane_3(const R& )
assert( CGAL::parallel(h1, h2) );
assert( ! CGAL::parallel(h1, h5) );
// More tests, that require sqrt().
_test_fct_plane_sqrt_3(R(), typename CGAL::Number_type_traits<FT>::Has_sqrt());
std::cout << "done" << std::endl;
return true;
}