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

Convex quadrangles in the plane. More...

#include <quadrangle.h>

Public Member Functions

 Quadrangle2 ()
 Empty.
 
 Quadrangle2 (const Vector2 &, const Vector2 &, const Vector2 &, const Vector2 &)
 Create a quadrangle. More...
 
 Quadrangle2 (const Quadrangle &)
 Create a planr quadrangle from a quadrangle. More...
 
 ~Quadrangle2 ()
 Empty.
 
Vector2 Vertex (const double &, const double &) const
 Compute the position of a vertex inside the quadrangle. More...
 
bool InverseBilinear (const Vector2 &, double &, double &) const
 Compute the inverse bi-linear coordinates of a point in the quadrangle. More...
 
Box2 GetBox () const
 Compute the box embedding the shape.
 
bool Inside (const Vector2 &) const
 Check if a point is inside the quadrangle. More...
 
double R (const Vector2 &) const
 Compute the squared distance between a point and the quadrangle. More...
 
Vector2 Normal (const Vector2 &) const
 Computes the normal vector between a point and a quadrangle. More...
 
void Translate (const Vector2 &)
 Translate the quadrangle. More...
 
void Scale (const double &)
 Scale the quadrangle. More...
 
void Rotate (const Matrix2 &)
 Rotate the quadrangle. More...
 
void Transform (const Frame2 &)
 Transform a quadrangle. More...
 
double Perimeter () const
 Compute the perimeter of the quadrangle.
 
double Area () const
 Compute the area of the quadrangle. More...
 
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draw the quadrangle. More...
 

Static Public Member Functions

static bool InverseBilinear (const Vector2 &, const Vector2 &, const Vector2 &, const Vector2 &, const Vector2 &, double &, double &)
 Inverse bilinear coordinates of a point in a quadrangle. More...
 

Protected Attributes

Vector2 p [4] = { Vector2::Null,Vector2::X,Vector2::X + Vector2::Y,Vector2::Y }
 Vertices, stored in counter-clockwize order.
 

Static Protected Attributes

static double epsilon = 1.0e-10
 Internal \epsilon; constant.
 

Friends

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

Detailed Description

Convex quadrangles in the plane.

Note that the quadrangle should be convex, otherwise some functions will not work properly.

Some functions such as the squared distance R() and normal Normal() are computationally intensive.

Constructor & Destructor Documentation

◆ Quadrangle2() [1/2]

Quadrangle2::Quadrangle2 ( const Vector2 a,
const Vector2 b,
const Vector2 c,
const Vector2 d 
)
explicit

Create a quadrangle.

Parameters
a,b,c,dVertices (given in trigonometric order).

◆ Quadrangle2() [2/2]

Quadrangle2::Quadrangle2 ( const Quadrangle q)
explicit

Create a planr quadrangle from a quadrangle.

Parameters
qQuadrangle.

Member Function Documentation

◆ Area()

double Quadrangle2::Area ( ) const

Compute the area of the quadrangle.

The area is defined by Bretschneider's formula. The trigonometric adjustment in Bretschneider's formula for non-cyclicality of the quadrilateral can be rewritten non-trigonometrically in terms of the sides and the diagonals:

A2=(s-a)(s-b)(s-c)(s-d)-1/4(ac+bd+pq)(ac+bd-pq).

◆ Draw()

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

Draw the quadrangle.

Parameters
sceneGraphics scene.
penThe pen.
brushThe brush, should the triangle be filled.

◆ Inside()

bool Quadrangle2::Inside ( const Vector2 q) const

Check if a point is inside the quadrangle.

Parameters
qPoint.

◆ InverseBilinear() [1/2]

bool Quadrangle2::InverseBilinear ( const Vector2 a,
const Vector2 b,
const Vector2 c,
const Vector2 d,
const Vector2 p,
double &  u,
double &  v 
)
static

Inverse bilinear coordinates of a point in a quadrangle.

Parameters
a,b,c,dVertices of the quadrangle.
pPoint.
u,vBi-linear coordinates.

◆ InverseBilinear() [2/2]

bool Quadrangle2::InverseBilinear ( const Vector2 q,
double &  u,
double &  v 
) const

Compute the inverse bi-linear coordinates of a point in the quadrangle.

Parameters
qPoint.
u,vBi-linear coordinates.
Returns
Boolean that checks whether a solution has been found.

◆ Normal()

Vector2 Quadrangle2::Normal ( const Vector2 q) const

Computes the normal vector between a point and a quadrangle.

Let q the projection of p onto the box, the normal vector is defined as n=p-q. The returned vector is null if the point is inside the quadrangle.

Parameters
qPoint.

◆ R()

double Quadrangle2::R ( const Vector2 q) const

Compute the squared distance between a point and the quadrangle.

Parameters
qPoint.
See also
Normal()

◆ Rotate()

void Quadrangle2::Rotate ( const Matrix2 r)

Rotate the quadrangle.

Parameters
rRotation matrix.

◆ Scale()

void Quadrangle2::Scale ( const double &  s)

Scale the quadrangle.

Parameters
sScaling factor.

◆ Transform()

void Quadrangle2::Transform ( const Frame2 f)

Transform a quadrangle.

Parameters
fTransform.

◆ Translate()

void Quadrangle2::Translate ( const Vector2 t)

Translate the quadrangle.

Parameters
tTranslation vector.

◆ Vertex()

Vector2 Quadrangle2::Vertex ( const double &  u,
const double &  v 
) const

Compute the position of a vertex inside the quadrangle.

Parameters
u,vParametric coordinates of the vertex.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Quadrangle2 q 
)
friend

Overloaded.

Parameters
sStream.
qThe Quadrangle.