See Chapter 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.
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.
| ||||
| ||||
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.
| ||||
| ||||
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.
| ||||
| ||||
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>. | ||||
| ||||
| ||||
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
|
| |||
returns the cross product of and . |
As in the two-dimensional case you subtract a point from the
symbolic constant CGAL_ORIGIN to obtain the locus vector of .
In order to obtain the point corresponding to a vector you simply
have to add to CGAL_ORIGIN.
See Section for an example.
As in the two-dimensional case, points, vectors and directions use a handle/representative mechanism.