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

2D Vector (CGAL_Vector_2)

Definition

An object of the class CGAL_Vector_2 is a vector in the two-dimensional vector space R2. Geometrically spoken, a vector is the difference of two points p2, p1 and denotes the direction and the distance from p1 to p2.

CGAL defines a symbolic constant CGAL_NULL_VECTOR. We will explicitly state where you can pass this constant as an argument instead of a vector initialized with zeros.

#include <CGAL/Vector_2.h>

Creation

CGAL_Vector_2<R> v ( CGAL_Null_vector CGAL_NULL_VECTOR);
introduces a null vector v.

CGAL_Vector_2<R> v ( R::RT hx, R::RT hy, R::RT hw = R::RT(1));
introduces a vector v initialized to (hx/hw,hy/hw). If the third argument is not explicitly given, it defaults to R::RT(1).
Precondition: hw not equal to 0

Operations

bool v == w Test for equality: two vectors are equal, iff their x and y coordinates are equal. You can compare a vector with the CGAL_NULL_VECTOR.
bool v != w Test for inequality. You can compare a vector with the CGAL_NULL_VECTOR.

There are two sets of coordinate access functions, namely to the homogeneous and to the Cartesian coordinates. They can be used independently from the chosen representation type R.

R::RT v.hx () returns the homogeneous x coordinate.
R::RT v.hy () returns the homogeneous y coordinate.
R::RT v.hw () returns the homogenizing coordinate.

Here come the Cartesian access functions. Note that you do not loose information with the homogeneous representation, because then the field type is a quotient.

R::FT v.x () returns the x-coordinate of v, that is hx/hw.
R::FT v.y () returns the y-coordinate of v, that is hy/hw.

The following operations are for convenience and for making the class CGAL_Vector_2 compatible with code for higher dimensional vectors. Again they come in a Cartesian and homogeneous flavor.

R::RT v.homogeneous ( int i)
returns the i'th homogeneous coordinate of v, starting with 0.
Precondition: 0<=i <=2.
R::FT v.cartesian ( int i)
returns the i'th Cartesian coordinate of v, starting at 0.
Precondition: 0<=i <=1.
R::FT v [ int i] returns coordinate(i).
Precondition: 0<=i <=1.
int v.dimension () returns the dimension (the constant 2).

Miscellaneous

CGAL_Direction_2<R>
v.direction () returns the direction which passes through v.
CGAL_Vector_2<R> v.transform ( CGAL_Aff_transformation_2<R> t)
returns the vector obtained by applying t on v.
CGAL_Vector_2<R> v.perpendicular ( CGAL_Orientation o)
returns the vector perpendicular to v in clockwise or counterclockwise orientation.

Operations

The following operations can be applied on vectors:

CGAL_Vector_2<R> v + w Addition.
CGAL_Vector_2<R> v - w Subtraction.
CGAL_Vector_2<R> - v returns the opposite vector.
R::FT v * w returns the scalar product (= inner product) of the two vectors.
CGAL_Vector_2<R> v * R::RT s Multiplication with a scalar from the right. Although it would be more natural, CGAL does not offer a multiplication with a scalar from the left. (This is due to problems of some compilers.)
CGAL_Vector_2<R> v * CGAL_Quotient<RT> s
Multiplication with a scalar from the right.
CGAL_Vector_2<R> v / R::RT s Division by a scalar.


Next: Class declaration of CGAL_Direction_2<R>
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Wed, January 20, 1999.