Core 1.0
Lune2 Class Reference

A lune is defined as the difference between two discs. More...

#include <scales.h>

Public Member Functions

 Lune2 (const Circle2 &, const Circle2 &)
 Create a lune as the difference of two discs.
 Lune2 (const Vector2 &, const Vector2 &, const double &, const double &)
 Create a lune as the difference of two discs.
Lune2 Translated (const Vector2 &) const
 Translate a lune.
Lune2 Rotated (const Matrix2 &) const
 Return a lune rotated by a given matrix.
Lune2 Scaled (const double &) const
 Return a lune scaled by a given factor.
Box2 GetBox () const
 Compute the bouding box.
double Signed (const Vector2 &) const
 Compute the signed distance between the lune and a point.
double R (const Vector2 &) const
 Compute the squared distance between the lune and a point.
Vector2 Normal (const Vector2 &) const
 Compute the distance vector between the lune and a point.
bool Inside (const Vector2 &) const
 Check if a point is inside the lune, i.e., inside the first disc and outside the second one.
bool Intersect (const Circle2 &) const
 Check if the lune intersects a circle, i.e., a disc.
bool Intersect (const Lune2 &) const
 Check if the lune intersects another lune.
bool Intersect (const Box2 &) const
 Check if the lune intersects a box.
double Area () const
 Compute the area of the lune.
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draw a lune.

Protected Attributes

Vector2 b
 Centers.
double rb
 Radii.

Friends

std::ostream & operator<< (std::ostream &s, const Lune2 &lune)
 Overloaded.

Detailed Description

A lune is defined as the difference between two discs.

See also
Lens

Constructor & Destructor Documentation

◆ Lune2() [1/2]

Lune2::Lune2 ( const Circle2 & d,
const Circle2 & c )

Create a lune as the difference of two discs.

Parameters
d,cCircle and cutting circle (the radius of the cutting circle should be larger).

◆ Lune2() [2/2]

Lune2::Lune2 ( const Vector2 & a,
const Vector2 & b,
const double & ra,
const double & rb )

Create a lune as the difference of two discs.

Parameters
a,bCenters of the two discs.
ra,rbRadii of the two discs.

Member Function Documentation

◆ Area()

double Lune2::Area ( ) const

Compute the area of the lune.

The area is the area of the first disc minus the area of its intersection with the second disc. The area is null if the first disc is inside the second one (empty lune).

Returns
The area.

◆ Draw()

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

Draw a lune.

The boundary of a lune is made of an outer arc of the first circle, outside the second disc, and of an inner arc of the second circle, inside the first disc, which meet at the two intersection points of the circles. The special cases are drawn as follows: nothing if the first disc is inside the second one (empty lune), the first disc if the discs are disjoint, and the first disc with a hole if the second disc is inside the first one.

Qt measures the angles of arcs counterclockwise on the screen, i.e., clockwise in the scene as the y axis points downward: the angles of the scene are negated.

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

◆ GetBox()

Box2 Lune2::GetBox ( ) const

Compute the bouding box.

Calls Lune2::GetCylinder()

◆ Inside()

bool Lune2::Inside ( const Vector2 & p) const
inline

Check if a point is inside the lune, i.e., inside the first disc and outside the second one.

Parameters
pPoint.

◆ Intersect() [1/3]

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

Check if the lune intersects a box.

Let S be the intersection of the box and of the first disc. The lune is the first disc minus the open second disc, so that it intersects the box if and only if S is not empty and is not inside the open second disc. As S is convex, the point of S which is the farthest from the second center is either a vertex of S, i.e., a corner of the box inside the first disc or an intersection point of an edge of the box with the first circle, or the point of the first circle which is the farthest from the second center, if it belongs to the box. The lune intersects the box if this point is not in the open second disc. An empty lune, i.e., a lune whose first disc is inside the second one, intersects nothing.

Parameters
boxThe box.

◆ Intersect() [2/3]

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

Check if the lune intersects a circle, i.e., a disc.

The disc intersects the lune if the Euclidean distance between its center and the lune is less than its radius. An empty lune, i.e., a lune whose first disc is inside the second one, intersects nothing.

Parameters
circleThe circle.
See also
Lune2::R(const Vector2&) const

◆ Intersect() [3/3]

bool Lune2::Intersect ( const Lune2 & lune) const

Check if the lune intersects another lune.

The common region of two lunes is the intersection of the first discs, minus the union of the second discs. If it is not empty, its boundary is made of arcs of the four circles, whose end points are intersection points of two circles, except for a circle without any intersection with the others, which is then a full boundary component. It is therefore enough to test the intersection points of the circles taken two by two, and one point of every circle which does not intersect any other circle.

Parameters
luneThe other lune.

◆ Normal()

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

Compute the distance vector between the lune and a point.

The result is the vector from the closest point of the lune to the point p, like Disc2::Normal(const Vector2&). It is null if p is in the lune, and also if the lune is empty, i.e., if the first disc is contained in the second one.

The boundary of the lune is made of an outer arc of the first circle and of an inner arc of the second circle, which meet at the two intersection points of the circles (the corners). On an arc of circle, the closest point to p is the radial projection of p on the circle if it belongs to the arc, and one of the two end points of the arc otherwise. The closest point of the lune is therefore the closest point among:

  • the radial projection of p on the first circle, if it is outside the second disc;
  • the radial projection of p on the second circle, if it is inside the first disc;
  • the two corners.

If the circles do not cross, there is no corner and the cases are simpler: the lune is the first disc if the discs are disjoint, and the first disc with a hole if the second disc is inside the first one. The cost of the function is constant.

Parameters
pPoint.
Returns
The distance vector.
See also
Lune2::R, Lune2::Inside

◆ R()

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

Compute the squared distance between the lune and a point.

The distance is the Euclidean distance to the closest point of the lune, it is null inside the lune.

Parameters
pPoint.
See also
Lune2::Normal

◆ Rotated()

Lune2 Lune2::Rotated ( const Matrix2 & r) const

Return a lune rotated by a given matrix.

Parameters
rRotation matrix.

◆ Scaled()

Lune2 Lune2::Scaled ( const double & s) const

Return a lune scaled by a given factor.

Parameters
sScaling factor.

◆ Signed()

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

Compute the signed distance between the lune and a point.

The result is negative in the lune, positive outside and null on its boundary, but this function does not generate an Euclidean distance: it is the maximum of the signed distances to the first disc and to the complement of the second disc, which is only a bound of the distance to the lune. Use Lune2::R() or Lune2::Normal() for the exact distance.

Parameters
pPoint.

◆ Translated()

Lune2 Lune2::Translated ( const Vector2 & t) const

Translate a lune.

Parameters
tTranslation vector.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Lune2 & lune )
friend

Overloaded.

Parameters
sStream.
luneThe lune.