CGAL 5.2.4 - 2D and 3D Linear Geometry Kernel
CGAL::Vector_2< Kernel > Class Template Reference

#include <CGAL/Vector_2.h>

Definition

An object v of the class Vector_2 is a vector in the two-dimensional vector space \( \mathbb{R}^2\).

Geometrically spoken, a vector is the difference of two points \( p_2\), \( p_1\) and denotes the direction and the distance from \( p_1\) to \( p_2\).

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.

Is Model Of:

Kernel::Vector_2

Hashable if Kernel is a cartesian kernel and if Kernel::FT is Hashable

Public Member Functions

Kernel::FT squared_length () const
 returns the squared length of v.
 
Vector_2< Kerneloperator* (const Vector_2< Kernel > &v, const Kernel::RT &s)
 Multiplication with a scalar from the right.
 
Vector_2< Kerneloperator* (const Vector_2< Kernel > &v, const Kernel::FT &s)
 Multiplication with a scalar from the right.
 
Vector_2< Kerneloperator* (const Kernel::RT &s, const Vector_2< Kernel > &v)
 Multiplication with a scalar from the left.
 
Vector_2< Kerneloperator* (const Kernel::FT &s, const Vector_2< Kernel > &v)
 Multiplication with a scalar from the left.
 

Types

typedef unspecified_type Cartesian_const_iterator
 An iterator for enumerating the Cartesian coordinates of a vector.
 

Creation

 Vector_2 (const Point_2< Kernel > &a, const Point_2< Kernel > &b)
 introduces the vector b-a.
 
 Vector_2 (const Segment_2< Kernel > &s)
 introduces the vector s.target()-s.source().
 
 Vector_2 (const Ray_2< Kernel > &r)
 introduces the vector having the same direction as r.
 
 Vector_2 (const Line_2< Kernel > &l)
 introduces the vector having the same direction as l.
 
 Vector_2 (const Null_vector &NULL_VECTOR)
 introduces a null vector v.
 
 Vector_2 (int x, int y)
 introduces a vector v initialized to (x,y).
 
 Vector_2 (double x, double y)
 introduces a vector v initialized to (x,y).
 
 Vector_2 (const Kernel::RT &hx, const Kernel::RT &hy, const Kernel::RT &hw=RT(1))
 introduces a vector v initialized to (hx/hw,hy/hw). More...
 
 Vector_2 (const Kernel::FT &x, const Kernel::FT &y)
 introduces a vector v initialized to (x,y).
 

Coordinate Access

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. Note that you do not lose information with the homogeneous representation, because the FieldNumberType is a quotient.

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

Convenience Operators

The following operations are for convenience and for compatibility with higher dimensional vectors.

Again they come in a Cartesian and homogeneous flavor.

Kernel::RT homogeneous (int i) const
 returns the i'th homogeneous coordinate of v. More...
 
Kernel::FT cartesian (int i) const
 returns the i'th Cartesian coordinate of v. More...
 
Kernel::FT operator[] (int i) const
 returns cartesian(i). More...
 
Cartesian_const_iterator cartesian_begin () const
 returns an iterator to the Cartesian coordinates of v, starting with the 0th coordinate.
 
Cartesian_const_iterator cartesian_end () const
 returns an off the end iterator to the Cartesian coordinates of v.
 
int dimension () const
 returns the dimension (the constant 2).
 
Direction_2< Kerneldirection () const
 returns the direction which passes through v.
 
Vector_2< Kerneltransform (const Aff_transformation_2< Kernel > &t) const
 returns the vector obtained by applying t on v.
 
Vector_2< Kernelperpendicular (const Orientation &o) const
 returns the vector perpendicular to v in clockwise or counterclockwise orientation.
 

Operators

bool operator== (const Vector_2< Kernel > &w) const
 Test for equality: two vectors are equal, iff their \( x\) and \( y\) coordinates are equal. More...
 
bool operator!= (const Vector_2< Kernel > &w) const
 Test for inequality. More...
 
Vector_2< Kerneloperator+ (const Vector_2< Kernel > &w) const
 Addition.
 
Vector_2< Kernel > & operator+= (const Vector_2< Kernel > &w)
 Addition.
 
Vector_2< Kerneloperator- (const Vector_2< Kernel > &w) const
 Subtraction.
 
Vector_2< Kernel > & operator-= (const Vector_2< Kernel > &w)
 Subtraction.
 
Vector_2< Kerneloperator- () const
 returns the opposite vector.
 
Kernel::FT operator* (const Vector_2< Kernel > &w) const
 returns the scalar product (= inner product) of the two vectors.
 
Vector_2< Kerneloperator/ (const Kernel::RT &s) const
 Division by a scalar.
 
Vector_2< Kernel > & operator/= (const Kernel::RT &s)
 Division by a scalar.
 
Vector_2< Kernel > & operator*= (const Kernel::RT &s)
 Multiplication by a scalar.
 

Constructor & Destructor Documentation

◆ Vector_2()

template<typename Kernel >
CGAL::Vector_2< Kernel >::Vector_2 ( const Kernel::RT hx,
const Kernel::RT hy,
const Kernel::RT hw = RT(1) 
)

introduces a vector v initialized to (hx/hw,hy/hw).

Precondition
\( hw\neq0\).

Member Function Documentation

◆ cartesian()

template<typename Kernel >
Kernel::FT CGAL::Vector_2< Kernel >::cartesian ( int  i) const

returns the i'th Cartesian coordinate of v.

Precondition
\( 0\leq i \leq1\).

◆ homogeneous()

template<typename Kernel >
Kernel::RT CGAL::Vector_2< Kernel >::homogeneous ( int  i) const

returns the i'th homogeneous coordinate of v.

Precondition
\( 0\leq i \leq2\).

◆ operator!=()

template<typename Kernel >
bool CGAL::Vector_2< Kernel >::operator!= ( const Vector_2< Kernel > &  w) const

Test for inequality.

You can compare a vector with the NULL_VECTOR.

◆ operator==()

template<typename Kernel >
bool CGAL::Vector_2< Kernel >::operator== ( const Vector_2< Kernel > &  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.

◆ operator[]()

template<typename Kernel >
Kernel::FT CGAL::Vector_2< Kernel >::operator[] ( int  i) const

returns cartesian(i).

Precondition
\( 0\leq i \leq1\).