Core 1.0
Annulus2 Class Reference

An annulus, the region between two concentric circles. More...

#include <annulus.h>

Public Member Functions

 Annulus2 ()
 Empty.
 Annulus2 (const double &, const double &)
 Creates a annulus.
 Annulus2 (const Vector2 &, const double &, const double &)
 Creates a annulus.
 Annulus2 (const Circle2 &, const double &)
 Creates a annulus.
 ~Annulus2 ()
 Empty.
Box2 GetBox () const
 Bounding box.
Vector2 RandomInside (Random &=Random::R239) const
 Generate a random vector inside the region between the two concentric circles.
double Area () const
 Area.
double R (const Vector2 &) const
 Compute the squared distance to a point.
double Signed (const Vector2 &) const
 Compute the squared distance to a point.
Vector2 Normal (const Vector2 &) const
 Computes the distance vector between an annulus and a point.
int Intersect (const Ray2 &, double *) const
 Compute the intersection with a ray.
bool Intersect (const Circle2 &) const
 Check if the annulus and a circle intersect.
bool Intersect (const Box2 &) const
 Check if the annulus and a box intersect.
bool Intersect (const Annulus2 &) const
 Check if the annulus and another annulus intersect.
bool Inside (const Vector2 &) const
 Check if a point is inside.
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draw the shape.

Protected Attributes

Vector2 c = Vector2::Null
 Center of the circle.
double re = 1.0
 Interior and exterior radii.

Static Protected Attributes

static constexpr const double Epsilon = 1.e-6
 Epslion for intersection tests

Detailed Description

An annulus, the region between two concentric circles.

Constructor & Destructor Documentation

◆ Annulus2() [1/3]

Annulus2::Annulus2 ( const double & re,
const double & ri )
explicit

Creates a annulus.

Parameters
re,riExterior and interior Radii.

◆ Annulus2() [2/3]

Annulus2::Annulus2 ( const Vector2 & c,
const double & re,
const double & ri )
explicit

Creates a annulus.

Parameters
cCenter.
re,riExterior and interior radii, exterior should be greater.

◆ Annulus2() [3/3]

Annulus2::Annulus2 ( const Circle2 & c,
const double & ri )
explicit

Creates a annulus.

Parameters
cCircle, its radius should be greater than the interior radius.
riInterior Radius.

Member Function Documentation

◆ Draw()

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

Draw the shape.

Parameters
sceneGraphics scene.
penThe pen.
brushThe brush.

◆ Inside()

bool Annulus2::Inside ( const Vector2 & p) const

Check if a point is inside.

Parameters
pPoint.

◆ Intersect() [1/4]

bool Annulus2::Intersect ( const Annulus2 & annulus) const

Check if the annulus and another annulus intersect.

Let d be the distance between the centers. A point at distance s of the center of the first annulus and at distance t of the center of the second one exists if and only if |s-t| <= d <= s+t. The annuli intersect if such distances exist with s in [ri,re] and t in [ri',re'], which is equivalent to max(0, ri-re', ri'-re) <= d <= re+re': the first inequality tells that the intervals of distances can be reached by two points at distance at most d, the second one that the outer discs overlap. This holds in particular for concentric annuli (d = 0), which intersect if their intervals of radii overlap.

Parameters
annulusThe other annulus.

◆ Intersect() [2/4]

bool Annulus2::Intersect ( const Box2 & box) const

Check if the annulus and a box intersect.

The box is considered as a filled rectangle: the function returns true if the annulus and the box have at least one point in common. The distance to the center of the annulus varies continuously over the box, from the distance dmin between the center and the box (null if the center is inside the box) to the distance dmax between the center and the farthest corner of the box. The annulus and the box intersect if and only if the range [dmin,dmax] meets the interval [ri,re] of the annulus. Both tests are performed with squared lengths.

Parameters
boxThe box.
See also
Annulus2::Intersect(const Circle2&) const

◆ Intersect() [3/4]

bool Annulus2::Intersect ( const Circle2 & circle) const

Check if the annulus and a circle intersect.

The circle is considered as a disc, like in Circle2::Intersect(const Circle2&): the function returns true if the annulus and the disc have at least one point in common. A disc inside the hole of the annulus does not intersect it, unless it touches the interior circle, and a disc which contains the annulus intersects it.

The distance to the center of the annulus varies continuously over a disc, from max(0,d-r) to d+r, where d is the distance between the centers and r the radius of the circle. The annulus and the disc intersect if and only if this range meets the interval [ri,re] of the annulus. Both tests are performed with squared lengths.

Parameters
circleThe circle.
See also
Annulus2::Intersect(const Box2&) const

◆ Intersect() [4/4]

int Annulus2::Intersect ( const Ray2 & ray,
double * t ) const

Compute the intersection with a ray.

The ray should be normalized. If the ray crosses the hole, four depths are returned in increasing order: t[0] and t[3] are the depths on the exterior circle, t[1] and t[2] on the interior circle, and the annulus is the union of the intervals [t[0],t[1]] and [t[2],t[3]]. Otherwise two depths are returned, on the exterior circle.

Parameters
rayThe (normalized) ray.
tSet of intersections, which should have room for four depths.
Returns
The number of depths: 0, 2 or 4.

◆ Normal()

Vector2 Annulus2::Normal ( const Vector2 & p) const

Computes the distance vector between an annulus and a point.

The annulus is considered as a filled region: the vector is null if the point is inside the annulus, otherwise it goes from the nearest point of the annulus to the point, and its squared norm is Annulus2::R(). For a point in the hole, it points towards the center of the annulus. At the center, the nearest point is arbitrarily chosen on the positive x axis.

Parameters
pPoint.

◆ R()

double Annulus2::R ( const Vector2 & p) const

Compute the squared distance to a point.

Parameters
pPoint.

◆ RandomInside()

Vector2 Annulus2::RandomInside ( Random & random = Random::R239) const

Generate a random vector inside the region between the two concentric circles.

Parameters
randomRandom number generator.

◆ Signed()

double Annulus2::Signed ( const Vector2 & p) const

Compute the squared distance to a point.

Parameters
pPoint.