Class

CGAL::Vector_2<Kernel>

Definition

An object of the class Vector_2<Kernel> is a vector in the two-dimensional vector space 2. 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 NULL_VECTOR. We will explicitly state where you can pass this constant as an argument instead of a vector initialized with zeros.

Types

Vector_2<Kernel>::Cartesian_const_iterator
An iterator for enumerating the Cartesian coordinates of a vector.

Creation

Vector_2<Kernel> v ( Point_2<Kernel> a, Point_2<Kernel> b);
introduces the vector b-a.


Vector_2<Kernel> v ( Segment_2<Kernel> s);
introduces the vector s.target()-s.source().


Vector_2<Kernel> v ( Ray_2<Kernel> r);
introduces the vector having the same direction as r.


Vector_2<Kernel> v ( Line_2<Kernel> l);
introduces the vector having the same direction as l.


Vector_2<Kernel> v ( Null_vector NULL_VECTOR);
introduces a null vector v.


Vector_2<Kernel> v ( int x, int y);
introduces a vector v initialized to (x,y).


Vector_2<Kernel> v ( double x, double y);
introduces a vector v initialized to (x,y).


Vector_2<Kernel> v ( Kernel::RT hx, Kernel::RT hy, Kernel::RT hw = RT(1));
introduces a vector v initialized to (hx/hw,hy/hw).
Precondition: hw 0


Vector_2<Kernel> v ( Kernel::FT x, Kernel::FT y);
introduces a vector v initialized to (x,y).

Operations

bool v.operator== ( w) const Test for equality: two vectors are equal, iff their x and y coordinates are equal. You can compare a vector with the NULL_VECTOR.

bool v.operator!= ( w) const Test for inequality. You can compare a vector with the 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 kernel model.

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

Note that you do not loose information with the homogeneous representation, because the FieldNumberType is a quotient.

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

The following operations are for convenience and for compatibility with higher dimensional vectors. Again they come in a Cartesian and homogeneous flavor.

Kernel::RT v.homogeneous ( int i) const returns the i'th homogeneous coordinate of v, starting with 0.
Precondition: 0 i 2.
Kernel::FT v.cartesian ( int i) const returns the i'th Cartesian coordinate of v, starting at 0.
Precondition: 0 i 1.
Kernel::FT v.operator[] ( int i) const returns cartesian(i).
Precondition: 0 i 1.

Cartesian_const_iterator v.cartesian_begin () const returns an iterator to the Cartesian coordinates of v, starting with the 0th coordinate.

Cartesian_const_iterator v.cartesian_end () const returns an off the end iterator to the Cartesian coordinates of v.

int v.dimension () const returns the dimension (the constant 2).

Direction_2<Kernel> v.direction () const returns the direction which passes through v.

Vector_2<Kernel> v.transform ( Aff_transformation_2<Kernel> t) const
returns the vector obtained by applying t on v.

Vector_2<Kernel> v.perpendicular ( Orientation o) const
returns the vector perpendicular to v in clockwise or counterclockwise orientation.

Operators

The following operations can be applied to vectors:

Vector_2<Kernel> v.operator+ ( w) const Addition.

Vector_2<Kernel> v.operator- ( w) const Subtraction.

Vector_2<Kernel> v.operator- () const returns the opposite vector.

Kernel::FT v.operator* ( w) const returns the scalar product (= inner product) of the two vectors.

Vector_2<Kernel> operator* ( v, Kernel::RT s) Multiplication with a scalar from the right.

Vector_2<Kernel> operator* ( v, Kernel::FT s) Multiplication with a scalar from the right.

Vector_2<Kernel> operator* ( Kernel::RT s, v) Multiplication with a scalar from the left.

Vector_2<Kernel> operator* ( Kernel::FT s, v) Multiplication with a scalar from the left.

Vector_2<Kernel> v.operator/ ( Kernel::RT s) const
Division by a scalar.

Kernel::FT v.squared_length () const returns the squared length of v.

See Also

Kernel::Vector_2