CGAL 6.1 - 2D and 3D Linear Geometry Kernel

Loading...
Searching...
No Matches
List of all members
CGAL::Cartesian_converter< K1, K2, NTConverter > Class Template Reference
Reference Manual » Cartesian/Homogeneous Conversion

`#include <CGAL/Cartesian_converter.h>`

## Definition

template<typename K1, typename K2, typename NTConverter>
class CGAL::Cartesian_converter< K1, K2, NTConverter >

`Cartesian_converter` converts objects from the kernel traits `K1` to the kernel traits `K2` using `NTConverter` to do the conversion.

Those traits must be of the form `Cartesian<FT1>` and `Cartesian<FT2>` (or the equivalent with `Simple_cartesian`). It then provides the following operators to convert objects from `K1` to `K2`.

The third template parameter `NTConverter` is a function object that must provide `K2::FT operator()(K1::FT n)` that converts `n` to an `K2::FT` which has the same value.

The default value of this parameter is `CGAL::NT_converter<K1::FT, K2::FT>`.

Example

In the following example, we compute exactly the intersection point between a line and a triangle, and we then create a double approximation of this point.

File Kernel_23/cartesian_converter.cpp

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Quotient.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Cartesian_converter.h>
typedef CGAL::Simple_cartesian<double> IK;
typedef CGAL::Simple_cartesian<CGAL::Quotient<CGAL::MP_Float> > EK;
typedef CGAL::Cartesian_converter<IK,EK> IK_to_EK;
typedef CGAL::Cartesian_converter<EK,IK> EK_to_IK;
int main(){
IK::Triangle_3 t1(
IK::Point_3(0.,0.,0.),
IK::Point_3(1.,0.,-1.),
IK::Point_3(0.,1.,3.)
);
IK::Line_3 l1(
IK::Point_3(0.2,0.25,-7),
IK::Point_3(0.25,0.3,4)
);
IK_to_EK to_exact;
EK::Triangle_3 t2=to_exact(t1);
EK::Line_3 l2=to_exact(l1);
const auto inter = CGAL::intersection(t2,l2);
// As we are sure that there IS an intersection
// and that the intersection IS a point
// we do not have to check for this, or put it in a try/catch
const EK::Point_3& exact_pt = std::get<EK::Point_3>(*inter);
EK_to_IK to_inexact;
IK::Point_3 inexact_pt = to_inexact(exact_pt);
std::cout << inexact_pt << std::endl;
return 0;
}
MP_Float.h
Quotient.h
CGAL::Cartesian_converter
Cartesian_converter converts objects from the kernel traits K1 to the kernel traits K2 using NTConver...
Definition: Cartesian_converter.h:33
CGAL::intersection
decltype(auto) intersection(Type1< R > f1, Type2< R > f2)
CGAL::Simple_cartesian
A model for a Kernel using Cartesian coordinates to represent the geometric objects.
Definition: Simple_cartesian.h:31

See also
  `CGAL::Cartesian<FieldNumberType>`
  `CGAL::Simple_cartesian<FieldNumberType>`

Examples
  Filtered_kernel/Filtered_predicate.cpp, and Kernel_23/cartesian_converter.cpp.

## Creation
| Cartesian_converter ()
| Default constructor.

## Operations
Similar operators are defined for the other kernel traits types `Point_3`, `Vector_2`...
K2::Point_2 | operator() (const K1::Point_2 &p)
| returns a `K2::Point_2` which coordinates are those of `p`, converted by `NTConverter`.