Core 1.0
Public Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
Hexagon2 Class Reference

Flat topped hexagon in the plane. More...

#include <hexagon.h>

Inheritance diagram for Hexagon2:
HexagonAlpha2 HexagonArray2 Hexagonal ScalarHexagonField2

Public Member Functions

 Hexagon2 ()
 Empty.
 
 Hexagon2 (const Vector2 &, const double &)
 Create an hexagon. More...
 
 Hexagon2 (const double &)
 Create an hexagon. More...
 
void Translate (const Vector2 &)
 Translate a hexagon. More...
 
void Scale (const double &)
 Scale a hexagon. More...
 
double Width () const
 Width of the hexagon.
 
double Height () const
 Height of the hexagon.
 
bool Inside (const Vector2 &) const
 Test if a point is inside. More...
 
bool Intersect (const Hexagon2 &) const
 Check if two hexagons intersect. More...
 
double R (const Vector2 &) const
 Compute the squared Euclidean distance to the hexagon. More...
 
double Signed (const Vector2 &) const
 Compute the signed Euclidean distance to the hexagon. More...
 
Vector2 Normal (const Vector2 &) const
 Computes the distance vector between a hexagon and a point. More...
 
Vector2 Center () const
 Return the center of the hexagonal cell.
 
double Radius () const
 Return the radius of the hexagonal cell.
 
Vector2 Radial (int) const
 Return the radial vector of the k-th vertex. More...
 
Vector2 Edge (int) const
 Return the edge vector connecting vertexes k and k+1. More...
 
Vector2 Vertex (int) const
 Return the coordinates of the k-th vertex. More...
 
Box2 GetBox () const
 Compute the bounding box of a hexagon.
 
double Area () const
 Area of the hexagon.
 
double Perimeter () const
 Perimeter of the hexagon.
 
bool Intersect (const Circle2 &) const
 Check the intersection with a circle. More...
 
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draws an hexagon. More...
 

Static Protected Member Functions

static int Sector (const Vector2 &)
 Compute the sector given an input direction. More...
 

Protected Attributes

Vector2 c = Vector2::Null
 Center.
 
double r = 1.0
 Radius.
 

Static Protected Attributes

static const Vector2 vertex [6]
 Array of vertices.
 
static const Vector2 normal [6]
 Array of normal vectors to the edges.
 
static const Vector2 edge [6]
 Unit edge vectors.
 
static const double Alpha = sqrt(3.0) / 2.0
 Constant sin(π/6)=√3/2.
 

Friends

std::ostream & operator<< (std::ostream &, const Hexagon2 &)
 Overloaded. More...
 

Detailed Description

Flat topped hexagon in the plane.

Constructor & Destructor Documentation

◆ Hexagon2() [1/2]

Hexagon2::Hexagon2 ( const Vector2 c,
const double &  r 
)
explicit

Create an hexagon.

Parameters
cCenter.
rRadius.

◆ Hexagon2() [2/2]

Hexagon2::Hexagon2 ( const double &  r)
explicit

Create an hexagon.

Parameters
rRadius.

Member Function Documentation

◆ Draw()

void Hexagon2::Draw ( QGraphicsScene &  scene,
const QPen &  pen = QPen(),
const QBrush &  brush = QBrush() 
) const

Draws an hexagon.

Parameters
sceneGraphics scene.
penThe pen.
brushThe brush.

◆ Edge()

Vector2 Hexagon2::Edge ( int  k) const
inline

Return the edge vector connecting vertexes k and k+1.

Parameters
kIndex, should be in [0,5].

◆ Inside()

bool Hexagon2::Inside ( const Vector2 p) const

Test if a point is inside.

Parameters
pPoint.

◆ Intersect() [1/2]

bool Hexagon2::Intersect ( const Circle2 circle) const

Check the intersection with a circle.

Accurate intersection test using the distance from the center of the circle to the hexagon.

Parameters
circleThe circle.

◆ Intersect() [2/2]

bool Hexagon2::Intersect ( const Hexagon2 hexagon) const

Check if two hexagons intersect.

Parameters
hexagonHexagon.

◆ Normal()

Vector2 Hexagon2::Normal ( const Vector2 p) const

Computes the distance vector between a hexagon and a point.

Parameters
pPoint.

◆ R()

double Hexagon2::R ( const Vector2 p) const

Compute the squared Euclidean distance to the hexagon.

Parameters
pPoint.

◆ Radial()

Vector2 Hexagon2::Radial ( int  k) const
inline

Return the radial vector of the k-th vertex.

Parameters
kIndex, should be in [0,5].

◆ Scale()

void Hexagon2::Scale ( const double &  s)

Scale a hexagon.

Parameters
sScaling factor.

◆ Sector()

int Hexagon2::Sector ( const Vector2 d)
staticprotected

Compute the sector given an input direction.

Parameters
dDirection.

◆ Signed()

double Hexagon2::Signed ( const Vector2 p) const

Compute the signed Euclidean distance to the hexagon.

Parameters
pPoint.

◆ Translate()

void Hexagon2::Translate ( const Vector2 t)

Translate a hexagon.

Parameters
tTranslation vector.

◆ Vertex()

Vector2 Hexagon2::Vertex ( int  k) const
inline

Return the coordinates of the k-th vertex.

Parameters
kIndex, should be in [0,5].

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Hexagon2 hex 
)
friend

Overloaded.

Parameters
sStream.
hexThe hexagon.