Navigation: Up, Table of Contents, Bibliography, Index, Title Page

3D Point, Vector and Direction

See Chapter reference arrow on points, vectors, and directions in two dimensions for an explanation why we distinguish between points, vectors and directions. This chapter will only give the functions that can be applied on such objects in three dimensions.

Point Conversion

For convenience, CGAL provides functions for conversion of points between homogeneous and Cartesian representation.

#include <CGAL/cartesian_homogeneous_conversion.h>

Conversion from Cartesian representation to homogeneous representation with the same number type is straightforward. The homogenizing coordinate is set to 1, all other homogeneous coordinates are copied from the corresponding Cartesian coordinate.

CGAL_Point_3< CGAL_Homogeneous<RT> >
CGAL_cartesian_to_homogeneous ( CGAL_Point_3< CGAL_Cartesian<RT> > cp)
converts 3d point cp with Cartesian representation into a 3d point with homogeneous representation with the same number type.

Conversion from homogeneous representation to Cartesian representation with the same number type involves division by the homogenizing coordinate.

CGAL_Point_3< CGAL_Cartesian<FT> >
CGAL_homogeneous_to_cartesian ( CGAL_Point_3< CGAL_Homogeneous<FT> > hp)
converts 3d point hp with homogeneous representation into a 3d point with Cartesian representation with the same number type.

Since conversion involves division, concerning exactness, the correspondence is rather between homogeneous representation with number type RT and Cartesian representation with number type CGAL_Quotient<RT> than between representation with the same number type.

CGAL_Point_3< CGAL_Cartesian<CGAL_Quotient<RT> > >
CGAL_homogeneous_to_quotient_cartesian ( CGAL_Point_3<CGAL_Homogeneous<RT> > hp)
converts the 3d point hp with homogeneous representation with number type RT into a 3d point with Cartesian representation with number type CGAL_Quotient<RT>.

CGAL_Point_3< CGAL_Homogeneous<RT> >
CGAL_quotient_cartesian_to_homogeneous ( CGAL_Point_3< CGAL_Cartesian< CGAL_Quotient<RT> > > cp)
converts 3d point cp with Cartesian representation with number type CGAL_Quotient<RT> into a 3d point with homogeneous representation with number type RT.

For the above functions, conversion from homogeneous representation to Cartesian representation with quotients is always exact. Conversion from Cartesian representation with quotients to homogeneous representation, however, might be inexact with some number types due to overflow or rounding in multiplications.

On 3D vectors we also have

CGAL_Vector_3<R>
CGAL_cross_product ( CGAL_Vector_3<R> u,
CGAL_Vector_3<R> v)
returns the cross product of u and v.

Conversion between Points and Vectors

As in the two-dimensional case you subtract a point p from the symbolic constant CGAL_ORIGIN to obtain the locus vector of p. In order to obtain the point corresponding to a vector v you simply have to add v to CGAL_ORIGIN. See Section reference arrow for an example.

Implementation

As in the two-dimensional case, points, vectors and directions use a handle/representative mechanism.


Next chapter: 3D Line, Ray and Segment
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Wed, January 20, 1999.