|
Core 1.0
|
Lenses in the plane with uniform radius. More...
#include <lens.h>
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. | |
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.
Create a lens.
If the distance between the centers is larger than \( 2r \), the discs do not overlap and the lens is empty: its height is null, and it is reduced to the midpoint of the centers for the computation of the distance.
| a,b | Centers of the circles. |
| r | Radius. |
| 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.
| c | Center of the lens. |
| t | Thickness, which is the value returned by Thickness(). |
| h | Half height. |
|
inline |
Compute the internal half opening angle of the lens.
The angle is defined by \( \cos \alpha = l/(2r) \), where l is the distance between the centers of the two discs and r their radius. It is the angle, seen from a center, between the line of the centers and a point where the circles meet, so that \( \sin \alpha = h/r \) where h is the height of the lens, see Lens2::Height().
| 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:
\[ A = 2 r^2 \arccos\left(\frac{l}{2r}\right) - \frac{l}{2} \sqrt{4r^2 - l^2}, \]
where \( l \) is the distance between the centers.
The area is null if the discs do not overlap, that is if \( l \geq 2r \) (the formula would otherwise involve the arccosine and the square root of values out of their domain, and return NaN).
| void Lens2::Draw | ( | QGraphicsScene & | scene, |
| const QPen & | pen = QPen(), | ||
| const QBrush & | brush = QBrush() ) const |
Draw the lens.
| scene | Graphics scene. |
| pen | The pen. |
| brush | The brush, should the circle be filled. |
| bool Lens2::Inside | ( | const Vector2 & | p | ) | const |
Test if a point is inside the lens.
| p | Point. |
| 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.
| circle | The circle. |
| 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.
| lens | The other lens. |
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:
| p | Point. |
| double Lens2::R | ( | const Vector2 & | p | ) | const |
Compute the squared Euclidean distance to the lens.
| p | Point. |
| Lens2 Lens2::Rotated | ( | const double & | angle | ) | const |
Rotation.
| angle | Rotation angle. |
| 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\|\).
| p | Point. |
|
friend |
Overloaded.
| s | Stream. |
| l | Lens. |