KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
circle.h
1/**
2 * @brief A 2D circle defined by a center point and radius.
3 */
4#ifndef CIRCLE_H
5#define CIRCLE_H
6
7#include <QPointF>
8#include <Kanoop/kanoopcommon.h>
9#include <Kanoop/geometry/point.h>
10
11class Line;
12
13/**
14 * @brief Represents a 2D circle with centre and radius, supporting geometric queries.
15 */
16class KANOOP_EXPORT Circle
17{
18public:
19 /** @brief Default constructor — creates a zero-radius circle at the origin. */
20 Circle() : _radius(0) {}
21
22 /**
23 * @brief Construct a circle from a centre point and radius.
24 * @param center Centre of the circle
25 * @param radius Radius of the circle
26 */
27 Circle(const QPointF center, double radius) :
28 _center(center), _radius(radius) {}
29
30 /**
31 * @brief Construct the unique circle passing through three non-collinear points.
32 * @param a First point on the circle
33 * @param b Second point on the circle
34 * @param c Third point on the circle
35 * @return Circumscribed circle, or an invalid circle if points are collinear
36 */
37 static Circle fromThreePoints(const Point& a, const Point& b, const Point& c);
38
39 /**
40 * @brief Return the centre of the circle.
41 * @return Centre QPointF
42 */
43 QPointF center() const { return _center; }
44
45 /**
46 * @brief Set the centre of the circle.
47 * @param value New centre point
48 */
49 void setCenter(const QPointF& value) { _center = value; }
50
51 /**
52 * @brief Return the radius of the circle.
53 * @return Radius value
54 */
55 double radius() const { return _radius; }
56
57 /**
58 * @brief Set the radius of the circle.
59 * @param value New radius value
60 */
61 void setRadius(double value) { _radius = value; }
62
63 /**
64 * @brief Return the circumference of the circle.
65 * @return Circumference (2 * pi * radius)
66 */
67 double circumference() const;
68
69 /**
70 * @brief Return the diameter of the circle.
71 * @return Diameter (2 * radius)
72 */
73 double diameter() const;
74
75 /**
76 * @brief Return the area of the circle.
77 * @return Area (pi * radius^2)
78 */
79 double area() const;
80
81 /**
82 * @brief Test whether a line intersects this circle.
83 * @param line Line segment to test
84 * @return true if the line intersects or is tangent to the circle
85 */
86 bool intersects(const Line& line) const;
87
88 /**
89 * @brief Find the intersection points of a line with this circle.
90 * @param line Line segment to intersect
91 * @param intersection1 Output for the first intersection point
92 * @param intersection2 Output for the second intersection point
93 * @return Number of intersection points (0, 1, or 2)
94 */
95 int intersects(const Line& line, QPointF& intersection1, QPointF& intersection2) const;
96
97 /**
98 * @brief Format the circle as a human-readable string.
99 * @return String representation of centre and radius
100 */
101 QString toString() const;
102
103private:
104 /** @brief Compute the intersection of two lines given in slope-intercept form. */
105 static Point findIntersection(double m1, double b1, double m2, double b2);
106
107 Point _center;
108 double _radius;
109};
110
111#endif // CIRCLE_H
Represents a 2D circle with centre and radius, supporting geometric queries.
Definition circle.h:17
void setRadius(double value)
Set the radius of the circle.
Definition circle.h:61
Circle(const QPointF center, double radius)
Construct a circle from a centre point and radius.
Definition circle.h:27
QPointF center() const
Return the centre of the circle.
Definition circle.h:43
double circumference() const
Return the circumference of the circle.
static Circle fromThreePoints(const Point &a, const Point &b, const Point &c)
Construct the unique circle passing through three non-collinear points.
double radius() const
Return the radius of the circle.
Definition circle.h:55
double diameter() const
Return the diameter of the circle.
Circle()
Default constructor — creates a zero-radius circle at the origin.
Definition circle.h:20
bool intersects(const Line &line) const
Test whether a line intersects this circle.
double area() const
Return the area of the circle.
void setCenter(const QPointF &value)
Set the centre of the circle.
Definition circle.h:49
QString toString() const
Format the circle as a human-readable string.
int intersects(const Line &line, QPointF &intersection1, QPointF &intersection2) const
Find the intersection points of a line with this circle.
Represents a 2D line segment between two Point endpoints.
Definition line.h:28
A 2D floating-point point extending QPointF with movement and spatial query methods.
Definition point.h:16