 CGAL::Vector_3<Kernel>

Definition

An object of the class Vector_3<Kernel> is a vector in the three-dimensional vector space 3. 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_3::Cartesian_const_iterator An iterator for enumerating the Cartesian coordinates of a vector.

Creation

 Vector_3 v ( Point_3 a, Point_3 b); introduces the vector b-a. Vector_3 v ( Segment_3 s); introduces the vector s.target()-s.source(). Vector_3 v ( Ray_3 r); introduces a vector having the same direction as r. Vector_3 v ( Line_3 l); introduces a vector having the same direction as l. Vector_3 v ( Null_vector NULL_VECTOR); introduces a null vector v. Vector_3 v ( int x, int y, int z); introduces a vector v initialized to (x, y, z). Vector_3 v ( double x, double y, double z); introduces a vector v initialized to (x, y, z). Vector_3 v ( Kernel::RT hx, Kernel::RT hy, Kernel::RT hz, Kernel::RT hw = RT(1)); introduces a vector v initialized to (hx/hw, hy/hw, hz/hw). Vector_3 v ( Kernel::FT x, Kernel::FT y, Kernel::FT z); introduces a vector v initialized to (x, y, z).

Operations

 bool v.operator== ( w) Test for equality: two vectors are equal, iff their x, y and z coordinates are equal. You can compare a vector with the NULL_VECTOR. bool v.operator!= ( w) 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 () returns the homogeneous x coordinate. Kernel::RT v.hy () returns the homogeneous y coordinate. Kernel::RT v.hz () returns the homogeneous z coordinate. Kernel::RT v.hw () 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 () returns the x-coordinate of v, that is hx/hw. Kernel::FT v.y () returns the y-coordinate of v, that is hy/hw. Kernel::FT v.z () returns the z coordinate of v, that is hz/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) returns the i'th homogeneous coordinate of v, starting with 0.
 Precondition: 0 ≤ i ≤ 3.

Kernel::FT v.cartesian ( int i) returns the i'th Cartesian coordinate of v, starting at 0.
 Precondition: 0 ≤ i ≤ 2.

Kernel::FT v.operator[] ( int i) returns cartesian(i).
 Precondition: 0 ≤ i ≤ 2.

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

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

int v.dimension () returns the dimension (the constant 3).

Vector_3<Kernel> v.transform ( Aff_transformation_3<Kernel> t)
returns the vector obtained by applying t on v.

Direction_3<Kernel> v.direction () returns the direction of v.

Operators

The following operations can be applied on vectors:

 Vector_3 v.operator+ ( w) Addition. Vector_3 v.operator- ( w) Subtraction. Vector_3 v.operator- () Returns the opposite vector. Kernel::FT v.operator* ( w) returns the scalar product (= inner product) of the two vectors. Vector_3 operator* ( v, Kernel::RT s) Multiplication with a scalar from the right. Vector_3 operator* ( v, Kernel::FT s) Multiplication with a scalar from the right. Vector_3 operator* ( Kernel::RT s, v) Multiplication with a scalar from the left. Vector_3 operator* ( Kernel::FT s, v) Multiplication with a scalar from the left. Vector_3 v.operator/ ( Kernel::RT s) Division by a scalar. Kernel::FT v.squared_length () returns the squared length of v.