Core 1.0
Lens2 Class Reference

Lenses in the plane with uniform radius. More...

#include <lens.h>

Inheritance diagram for Lens2:
Axis2

Public Member Functions

 Lens2 (const Vector2 &, const Vector2 &, const double &)
 Create a lens.
 Lens2 (const Vector2 &, const double &, const double &)
 Create a lens from its thickness and its height.
bool Inside (const Vector2 &) const
 Test if a point is inside the lens.
double R (const Vector2 &) const
 Compute the squared Euclidean distance to the lens.
double Signed (const Vector2 &) const
 Compute the Euclidean distance to the lens.
Vector2 Normal (const Vector2 &) const
 Compute the distance vector between the lens and a point.
bool Intersect (const Circle2 &) const
 Check if the lens intersects a circle.
bool Intersect (const Lens2 &) const
 Check if the lens intersects another lens.
double Height () const
 Compute the height of the lens.
double Thickness () const
 Compute the thickness of the lens.
Vector2 Center () const
 Compute the center of the lens.
double Alpha () const
 Compute the internal half opening angle of the lens.
Lens2 Rotated (const double &) const
 Rotation.
Lens2 Translated (const Vector2 &) const
 Translation.
double Area () const
 Compute the area of the lens.
Box2 GetBox () const
 Compute the (tight) bounding box.
OrientedBox2 GetOrientedBox () const
 Compute the (tight) bounding box.
Frame2 GetFrame () const
 Compute the local frame of the lens.
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draw the lens.

Protected Attributes

double r = 1.0
 Radius.
double height = sqrt(3.0) / 2.0
 Height of the lens, defined as \( \sqrt{r^2-l^2/4} \) where l is the distance between the centers.
Protected Attributes inherited from Axis2
Vector2 b = Vector2(1.0, 0.0)
 End vertexes of the axis.
Vector2 axis = Vector2::X
 Normalized axis vector.
double length = 1.0
 Length of the axis.

Friends

std::ostream & operator<< (std::ostream &s, const Lens2 &l)
 Overloaded.

Additional Inherited Members

Protected Member Functions inherited from Axis2
double Radial (const Vector2 &, Vector2 &, Vector2 &) const
 Compute the radial coordinates of a point.
Vector2 Radial (const Vector2 &) const
 Compute the radial coordinates of a point.
 Axis2 ()
 Empty.
 Axis2 (const Vector2 &, const Vector2 &)
 Creates an axis given end vertices.
 ~Axis2 ()
 Empty.
Vector2 Vertex (int) const
 Return one of the end vertexes of the axis.
Vector2 Point (const double &) const
 Compute a point on the axis.
Vector2 GetAxis () const
 Returns the normalized axis vector.
constexpr double Length () const
 Return the axis length.
void Translate (const Vector2 &)
 Translation.
void Rotate (const Matrix2 &)
 Rotation.
void Scale (const double &)
 Scaling.
Vector2 Symmetric (const Vector2 &) const
 Symmetric point.
Circle2 Symmetric (const Circle2 &) const
 Symmetric circle.
Box2 Symmetric (const Box2 &) const
 Symmetric box.

Detailed Description

Lenses in the plane with uniform radius.

A lens is defined as the intersection of two circles. Lenses are used in beta-skeletons geometric graphs.

Constructor & Destructor Documentation

◆ Lens2() [1/2]

Lens2::Lens2 ( const Vector2 & a,
const Vector2 & b,
const double & r )

Create a lens.

Parameters
a,bCenters of the circles.
rRadius.

◆ Lens2() [2/2]

Lens2::Lens2 ( const Vector2 & c,
const double & t,
const double & h )

Create a lens from its thickness and its height.

The lens is the intersection of two discs of radius \( r \) whose centers are on the x axis, symmetrically with respect to c. The thickness t is the width of the lens along the axis of the centers, and h is the half height, that is, the distance from c to the corners of the lens, as returned by Height(). The radius and the distance l between the centers are:

\[r=\frac{h^2+t^2/4}{t}, \quad l=2r-t. \]

The parameters should satisfy \( 0<t \le 2h \): the case \( t=2h \) is the disc of radius h, and for larger values of t the distance l is negative and the object is not the lens of thickness t. This is not checked.

Parameters
cCenter of the lens.
tThickness, which is the value returned by Thickness().
hHalf height.

Member Function Documentation

◆ Alpha()

double Lens2::Alpha ( ) const
inline

Compute the internal half opening angle of the lens.

This is an inlined and optimized version of:

Lens2 lens;
double a = acos(lens.Height()/(0.5*lens.Thickness()));
double Thickness() const
Compute the thickness of the lens.
Definition lens.h:104
Lens2(const Vector2 &, const Vector2 &, const double &)
Create a lens.
Definition lens2.cpp:20
double Height() const
Compute the height of the lens.
Definition lens.h:96

◆ Area()

double Lens2::Area ( ) const

Compute the area of the lens.

This is a simplified version of the equation of the area of two intersecting circles with different radii.

See also
Circle2::Area(const Circle2&) const

◆ Draw()

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

Draw the lens.

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

◆ Inside()

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

Test if a point is inside the lens.

Parameters
pPoint.

◆ Intersect() [1/2]

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

Check if the lens intersects a circle.

The circle intersects the lens if the Euclidean distance between its center and the lens is less than its radius.

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

◆ Intersect() [2/2]

bool Lens2::Intersect ( const Lens2 & lens) const

Check if the lens intersects another lens.

A lens is the intersection of two discs: two lenses intersect if and only if their four discs have a common point. The common region of discs is either one of the discs, in which case its center is in all the discs, or it has a vertex, which is an intersection point of two circles. It is therefore enough to test the four centers and the intersection points of the circles taken two by two.

Parameters
lensThe other lens.

◆ Normal()

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

Compute the distance vector between the lens and a point.

The vector goes from the closest point of the lens to the point, so that the projection of the point on the lens is p-Normal(p). It is null if the point is inside the lens.

The boundary of the lens is made of an arc of the first circle, inside the second disc, and of an arc of the second circle, inside the first disc, which meet at the two corners of the lens. On an arc, the closest point to p is the radial projection of p on the circle if it belongs to the arc, and one of the corners otherwise. The closest point of the lens is therefore the closest point among:

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

◆ R()

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

Compute the squared Euclidean distance to the lens.

Parameters
pPoint.

◆ Rotated()

Lens2 Lens2::Rotated ( const double & angle) const

Rotation.

Parameters
angleRotation angle.

◆ Signed()

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

Compute the Euclidean distance to the lens.

We compute the exact Euclean distance, not the approximation \( max(\|p-a\|,\|p-b\|\).

Parameters
pPoint.

◆ Translated()

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

Translation.

Parameters
tTranslation vector.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Lens2 & l )
friend

Overloaded.

Parameters
sStream.
lLens.