Core 1.0
|
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... | |
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.
|
explicit |
Create a quadrangle.
a,b,c,d | Vertices (given in trigonometric order). |
|
explicit |
Create a planr quadrangle from a quadrangle.
q | Quadrangle. |
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).
void Quadrangle2::Draw | ( | QGraphicsScene & | scene, |
const QPen & | pen = QPen() , |
||
const QBrush & | brush = QBrush() |
||
) | const |
Draw the quadrangle.
scene | Graphics scene. |
pen | The pen. |
brush | The brush, should the triangle be filled. |
bool Quadrangle2::Inside | ( | const Vector2 & | q | ) | const |
Check if a point is inside the quadrangle.
q | Point. |
|
static |
Inverse bilinear coordinates of a point in a quadrangle.
a,b,c,d | Vertices of the quadrangle. |
p | Point. |
u,v | Bi-linear coordinates. |
bool Quadrangle2::InverseBilinear | ( | const Vector2 & | q, |
double & | u, | ||
double & | v | ||
) | const |
Compute the inverse bi-linear coordinates of a point in the quadrangle.
q | Point. |
u,v | Bi-linear coordinates. |
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.
q | Point. |
double Quadrangle2::R | ( | const Vector2 & | q | ) | const |
Compute the squared distance between a point and the quadrangle.
q | Point. |
void Quadrangle2::Rotate | ( | const Matrix2 & | r | ) |
Rotate the quadrangle.
r | Rotation matrix. |
void Quadrangle2::Scale | ( | const double & | s | ) |
Scale the quadrangle.
s | Scaling factor. |
void Quadrangle2::Transform | ( | const Frame2 & | f | ) |
Transform a quadrangle.
f | Transform. |
void Quadrangle2::Translate | ( | const Vector2 & | t | ) |
Translate the quadrangle.
t | Translation vector. |
Vector2 Quadrangle2::Vertex | ( | const double & | u, |
const double & | v | ||
) | const |
Compute the position of a vertex inside the quadrangle.
u,v | Parametric coordinates of the vertex. |
|
friend |
Overloaded.
s | Stream. |
q | The Quadrangle. |