|
Core 1.0
|
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. | |
A lune is defined as the difference between two discs.
Create a lune as the difference of two discs.
| d,c | Circle and cutting circle (the radius of the cutting circle should be larger). |
Create a lune as the difference of two discs.
| a,b | Centers of the two discs. |
| ra,rb | Radii of the two discs. |
| 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).
| 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.
| scene | Graphics scene. |
| pen | The pen. |
| brush | The brush, should the lune be filled. |
| Box2 Lune2::GetBox | ( | ) | const |
Compute the bouding box.
Calls Lune2::GetCylinder()
|
inline |
Check if a point is inside the lune, i.e., inside the first disc and outside the second one.
| p | Point. |
| 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.
| box | The box. |
| 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.
| circle | The circle. |
| 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.
| lune | The other lune. |
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:
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.
| p | Point. |
| 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.
| p | Point. |
Return a lune rotated by a given matrix.
| r | Rotation matrix. |
| Lune2 Lune2::Scaled | ( | const double & | s | ) | const |
Return a lune scaled by a given factor.
| s | Scaling factor. |
| 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.
| p | Point. |
Translate a lune.
| t | Translation vector. |
|
friend |
Overloaded.
| s | Stream. |
| lune | The lune. |