📄 aff_transformationh2.h
字号:
// Copyright (c) 1999 Utrecht University (The Netherlands),// ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),// INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg// (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),// and Tel-Aviv University (Israel). 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 Lesser General Public License as// published by the Free Software Foundation; version 2.1 of the License.// See the file LICENSE.LGPL distributed with CGAL.//// 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: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.3-branch/Homogeneous_kernel/include/CGAL/Homogeneous/Aff_transformationH2.h $// $Id: Aff_transformationH2.h 28567 2006-02-16 14:30:13Z lsaboret $// //// Author(s) : Stefan Schirra#ifndef CGAL_AFF_TRANSFORMATIONH2_H#define CGAL_AFF_TRANSFORMATIONH2_H#include <CGAL/Handle_for_virtual.h>#include <CGAL/rational_rotation.h>CGAL_BEGIN_NAMESPACEtemplate <class R>class Aff_transformationH2;template <class R>class Aff_transformation_repH2;template <class R>Aff_transformationH2<R>_general_transformation_composition( Aff_transformation_repH2<R> l, Aff_transformation_repH2<R> r);template <class R>class Aff_transformation_rep_baseH2 : public Ref_counted_virtual{ public: typedef typename R::RT RT; typedef typename R::FT FT; typedef typename R::Point_2 Point_2; typedef typename R::Vector_2 Vector_2; typedef typename R::Direction_2 Direction_2; virtual ~Aff_transformation_rep_baseH2(){} virtual Point_2 transform(const Point_2& p) const = 0; virtual Vector_2 transform(const Vector_2& v) const = 0; virtual Direction_2 transform(const Direction_2& d) const = 0; virtual Aff_transformationH2<R> inverse() const = 0; virtual Aff_transformation_repH2<R> general_form() const = 0; virtual bool is_even() const = 0; virtual RT homogeneous(int i, int j) const = 0; virtual FT cartesian(int i, int j) const = 0;};template < class R >class Aff_transformation_repH2 : public Aff_transformation_rep_baseH2<R>{ public: typedef typename R::RT RT; typedef typename R::FT FT; typedef typename R::Point_2 Point_2; typedef typename R::Vector_2 Vector_2; typedef typename R::Direction_2 Direction_2; Aff_transformation_repH2() {} Aff_transformation_repH2(const RT& m00, const RT& m01, const RT& m02, const RT& m10, const RT& m11, const RT& m12, const RT& m22) : a(m00), b(m01), c(m02), d(m10), e(m11), f(m12), g(m22) {} virtual ~Aff_transformation_repH2() {} virtual Point_2 transform(const Point_2& p) const { return Point_2( a * p.hx() + b * p.hy() + c * p.hw(), d * p.hx() + e * p.hy() + f * p.hw(), g * p.hw() ); } virtual Vector_2 transform(const Vector_2& v) const { return Vector_2( a * v.hx() + b * v.hy(), d * v.hx() + e * v.hy(), g * v.hw() ); } virtual Direction_2 transform(const Direction_2& dir) const { if ( g > RT(0) ) return Direction_2( a * dir.x() + b * dir.y(), d * dir.x() + e * dir.y() ); else return - Direction_2(a * dir.x() + b * dir.y(), d * dir.x() + e * dir.y() ); } virtual Aff_transformationH2<R> inverse() const { RT ai = e*g; RT bi = - b*g; RT ci = b*f - e*c; RT di = - d*g; RT ei = a*g; RT fi = d*c - a*f; RT gi = a*e - b*d; return Aff_transformationH2<R>( ai, bi, ci, di, ei, fi, gi) ; } virtual Aff_transformation_repH2<R> general_form() const { return *this; } virtual bool is_even() const { return CGAL_NTS sign<RT>( (a*e - b*d)*g ) == POSITIVE; } virtual RT homogeneous(int i, int j) const; virtual FT cartesian(int i, int j) const; RT a; // | a b c | | x | | xn | RT b; // | d e f | * | y | = | yn | RT c; // | 0 0 g | | w | | wn | RT d; RT e; RT f; RT g; friend Aff_transformationH2<R> _general_transformation_composition <> ( Aff_transformation_repH2<R> l, Aff_transformation_repH2<R> r);};template < class R >class Identity_repH2 : public Aff_transformation_rep_baseH2<R>{ public: typedef typename R::RT RT; typedef typename R::FT FT; typedef typename R::Point_2 Point_2; typedef typename R::Vector_2 Vector_2; typedef typename R::Direction_2 Direction_2; Identity_repH2() {} virtual ~Identity_repH2() {} virtual Point_2 transform(const Point_2 & p) const { return p; } virtual Vector_2 transform(const Vector_2 & v) const { return v; } virtual Direction_2 transform(const Direction_2 & d) const { return d; } virtual Aff_transformationH2<R> inverse() const { return Aff_transformationH2<R>(IDENTITY); } virtual bool is_even() const { return true; } virtual Aff_transformation_repH2<R> general_form() const { const RT RT0(0); const RT RT1(1); return Aff_transformation_repH2<R>( RT1, RT0, RT0, RT0, RT1, RT0, RT1 ); } virtual RT homogeneous(int i, int j) const { return (i==j) ? RT(1) : RT(0); } virtual FT cartesian(int i, int j) const { return (i==j) ? FT(1) : FT(0); }};template < class R >class Translation_repH2 : public Aff_transformation_rep_baseH2<R>{ public: typedef typename R::RT RT; typedef typename R::FT FT; typedef typename R::Point_2 Point_2; typedef typename R::Vector_2 Vector_2; typedef typename R::Direction_2 Direction_2; Translation_repH2() {} Translation_repH2(const Vector_2 & tv) : _tv(tv) {} virtual ~Translation_repH2() {} virtual Point_2 transform(const Point_2 & p) const { return (p + _tv); } virtual Vector_2 transform(const Vector_2 & v) const { return (v); } virtual Direction_2 transform(const Direction_2 & d) const { return (d); } virtual Aff_transformationH2<R> inverse() const { return Aff_transformationH2<R>(TRANSLATION, - _tv); } virtual bool is_even() const { return true; } virtual Aff_transformation_repH2<R> general_form() const { return Aff_transformation_repH2<R>( _tv.hw(), RT(0) , _tv.hx(), RT(0), _tv.hw(), _tv.hy(), _tv.hw() ); } virtual RT homogeneous(int i, int j) const; virtual FT cartesian(int i, int j) const; private: Vector_2 _tv;};template < class R >class Rotation_repH2 : public Aff_transformation_rep_baseH2<R>{ public: typedef typename R::RT RT; typedef typename R::FT FT; typedef typename R::Point_2 Point_2; typedef typename R::Vector_2 Vector_2; typedef typename R::Direction_2 Direction_2; Rotation_repH2() { } Rotation_repH2(const RT& sin, const RT& cos, const RT& den) : _sin(sin), _cos(cos), _den(den) { if ( den < RT(0) ) { _sin = - _sin; _cos = - _cos; _den = - _den; }; } ~Rotation_repH2() { } virtual Point_2 transform(const Point_2 & p) const { return Point_2( p.hx()*_cos - p.hy()*_sin, p.hx()*_sin + p.hy()*_cos, p.hw()*_den ); } virtual Vector_2 transform(const Vector_2 & v) const { return Vector_2( v.hx()*_cos - v.hy()*_sin, v.hx()*_sin + v.hy()*_cos, v.hw()*_den ); } virtual Direction_2 transform(const Direction_2 & d) const { return Direction_2( d.x()*_cos - d.y()*_sin, d.x()*_sin + d.y()*_cos); } virtual Aff_transformationH2<R> inverse() const { return Aff_transformationH2<R>(ROTATION, - _sin, _cos, _den); } virtual bool is_even() const { return true; } virtual Aff_transformation_repH2<R> general_form() const { return Aff_transformation_repH2<R>( _cos, - _sin, RT(0) , _sin, _cos, RT(0) , _den ); } virtual RT homogeneous(int i, int j) const; virtual FT cartesian(int i, int j) const; private: RT _sin; RT _cos; RT _den;};template < class R >class Scaling_repH2 : public Aff_transformation_rep_baseH2<R>{ public: typedef typename R::RT RT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -