Core 1.0
Circle2 Class Reference

Circles in the plane. More...

#include <circle.h>

Inheritance diagram for Circle2:
CircleArc2 Disc2 SmoothDisc2

Public Member Functions

 Circle2 ()
 Empty.
 Circle2 (const double &)
 Create a circle centered at origin.
 Circle2 (const Vector2 &, const double &)
 Create a circle.
 Circle2 (const Vector2 &, const Vector2 &, const Vector2 &)
 Create the circle passing through 3 points.
 Circle2 (const QVector< Vector2 > &)
 Creates a circle enclosing a set of points.
 Circle2 (const Circle2 &, const Circle2 &)
 Create a circle embedding two circles.
bool Inside (const Vector2 &) const
 Check if a point is inside the circle.
bool Inside (const Circle2 &) const
 Test if a circle is entirely embedded in another one.
bool Inside (const Box2 &) const
 Test if a box is inside the circle.
bool InsideRange (const Vector2 &, const double &) const
 Check if a point is within a given range of the circle.
Vector2 Center () const
 Center of the circle.
Vector2 Vertex (const double &) const
 Vertex on the circle.
Vector2 Tangent (const double &) const
 Tangent to the circle.
double Radius () const
 Radius of the circle.
void Extend (const Vector2 &)
 Extend the circle so that the argument point should be embedded in the new circle.
Circle2 Extended (const double &) const
 Extend the radius of the circle.
bool Intersect (const Box2 &) const
 Check intersection with a box.
bool Intersect (const Circle2 &) const
 Check if two circles intersect each other.
bool Intersect (const Circle2 &, Vector2 &, Vector2 &) const
 Check if two circles intersect each other and compute intersection points.
bool Intersect (const Ray2 &, double &, double &) const
 Check the intersection between a circle and a ray.
bool Intersect (const Ray2 &) const
 Check the intersection between a circle and a ray.
bool Intersect (const Segment2 &) const
 Check the intersection between a circle and a segment.
Vector2 Normal (const Vector2 &) const
 Compute the distance vector between a circle and a point.
double R (const Vector2 &) const
 Compute the squared distance between a point and the circle.
Box2 GetBox () const
 Compute the axis aligned bounding box of a circle.
Circle2 Translated (const Vector2 &) const
 Translate a circle.
Circle2 Rotated (const Matrix2 &) const
 Rotates a circle.
Circle2 Transformed (const Frame2 &) const
 Return a circle transformed by a frame.
Circle2 Scaled (const double &) const
 Return a uniformly scaled circle.
void Translate (const Vector2 &)
 Translate a circle.
void Rotate (const Matrix2 &)
 Rotates a circle.
void Scale (const double &)
 Scales a circle.
double Area () const
 Area of the circle.
double Length () const
 Perimeter of the circle.
double Area (const Circle2 &) const
 Compute the area of the surface between two circles.
Vector2 RandomInside (Random &=Random::R239) const
 Generate a random vector inside the circle.
Vector2 RandomOn (Random &=Random::R239) const
 Generate a random vector on the circle.
Vector2 Vogel (int, int) const
 Generate a spiraling point in the disc.
QVector< Vector2 > Poisson (const double &, int, bool=false, Random &=Random::R239) const
 Compute a Poisson disc distribution inside a circle.
QVector< Vector2 > PoissonNorder (const double &, int, Random &=Random::R239) const
 Compute a Poisson disc distribution on the boundary of a circle.
QVector< Vector2 > Border (const double &, Random &=Random::R239) const
 Compute a Poisson disc distribution on the boundary of the circle.
QuadricCurve2 QuadricBezierArc (const double &) const
 Compute the quadratic B�zier approximation of a circle arc.
QuadricCurve2 QuadricBezierArc (const double &, const double &) const
 Compute the quadratic B�zier approximation of a circle arc.
CubicCurve2 CubicBezierArc (const double &) const
 Compute the cubic B�zier approximation of a circle arc.
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draw a circle.

Static Public Member Functions

static Vector2 RandomUnit (Random &=Random::R239)
 Compute a random vertex inside a unit disc.

Static Public Attributes

static const Circle2 Unit
 Unit circle.
static const Circle2 Infinite
 Infinite circle.

Protected Attributes

Vector2 c = Vector2::Null
 Center.
double r = 1.0
 Radius.

Static Protected Attributes

static constexpr const double Epsilon = 1.e-6
 Epslion for intersection tests

Friends

std::ostream & operator<< (std::ostream &s, const Circle2 &circle)
 Overloaded.

Detailed Description

Circles in the plane.

See also
Circle

Constructor & Destructor Documentation

◆ Circle2() [1/5]

Circle2::Circle2 ( const double & r)
explicit

Create a circle centered at origin.

Parameters
rRadius.

◆ Circle2() [2/5]

Circle2::Circle2 ( const Vector2 & c,
const double & r )
explicit

Create a circle.

Parameters
cCenter.
rRadius.

◆ Circle2() [3/5]

Circle2::Circle2 ( const Vector2 & a,
const Vector2 & b,
const Vector2 & c )
explicit

Create the circle passing through 3 points.

This is the circumscribed circle of the triangle.

Parameters
a,b,cPoints.

◆ Circle2() [4/5]

Circle2::Circle2 ( const QVector< Vector2 > & s)
explicit

Creates a circle enclosing a set of points.

The algorithm computes a fast approximation of the bounding ball for a point set based on the algorithm given by [Jack Ritter, 1990].

Parameters
sSet of points, which should not be empty.

◆ Circle2() [5/5]

Circle2::Circle2 ( const Circle2 & ca,
const Circle2 & cb )
explicit

Create a circle embedding two circles.

Parameters
ca,cbCircles.

Member Function Documentation

◆ Area()

double Circle2::Area ( const Circle2 & circle) const

Compute the area of the surface between two circles.

If the circles do not intersect, the function returns 0; if the smallest is included in the largest, the function returns the area of the smallest, otherwise complex computations are performed.

Parameters
circleThe other circle.

◆ Border()

QVector< Vector2 > Circle2::Border ( const double & ra,
Random & random = Random::R239 ) const

Compute a Poisson disc distribution on the boundary of the circle.

See also
Circle2::Poisson
Parameters
raRadius of the disc.
randomRandom number generator.

◆ CubicBezierArc()

CubicCurve2 Circle2::CubicBezierArc ( const double & t) const

Compute the cubic B�zier approximation of a circle arc.

Parameters
tAngle.

◆ Draw()

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

Draw a circle.

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

◆ Extend()

void Circle2::Extend ( const Vector2 & p)

Extend the circle so that the argument point should be embedded in the new circle.

This is the same as computing the smallest enclosing circle of a circle and a point.

Parameters
pPoint.

◆ Extended()

Circle2 Circle2::Extended ( const double & re) const

Extend the radius of the circle.

Parameters
reRadius extension.

◆ Inside() [1/3]

bool Circle2::Inside ( const Box2 & box) const

Test if a box is inside the circle.

Parameters
boxThe box.

◆ Inside() [2/3]

bool Circle2::Inside ( const Circle2 & circle) const

Test if a circle is entirely embedded in another one.

Parameters
circleThe other circle.

◆ Inside() [3/3]

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

Check if a point is inside the circle.

Parameters
pPoint.

◆ InsideRange()

bool Circle2::InsideRange ( const Vector2 & p,
const double & e ) const

Check if a point is within a given range of the circle.

Parameters
pPoint.
eRange.

◆ Intersect() [1/6]

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

Check intersection with a box.

Simply compute the distance between the center of the circle and the box and compare to radius of the circle.

See also
Box::R(const Vector&) const
Parameters
boxThe box.

◆ Intersect() [2/6]

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

Check if two circles intersect each other.

Parameters
circleThe other circle.

◆ Intersect() [3/6]

bool Circle2::Intersect ( const Circle2 & circle,
Vector2 & a,
Vector2 & b ) const

Check if two circles intersect each other and compute intersection points.

Parameters
circleThe other circle.
a,bIntersection points, unchanged if the circles do not intersect.

The function returns false if the circles are disjoint, if one is inside the other, or if they are concentric (there is no intersection point, or infinitely many).

◆ Intersect() [4/6]

bool Circle2::Intersect ( const Ray2 & ray) const

Check the intersection between a circle and a ray.

Parameters
rayThe (normalized) ray.

◆ Intersect() [5/6]

bool Circle2::Intersect ( const Ray2 & ray,
double & ta,
double & tb ) const

Check the intersection between a circle and a ray.

Note that intersections are sorted.

This function assumes that the ray is normalized, i.e. has a unit direction vector.

Parameters
rayThe (normalized) ray.
ta,tbIntersection depths.

◆ Intersect() [6/6]

bool Circle2::Intersect ( const Segment2 & segment) const

Check the intersection between a circle and a segment.

Parameters
segmentThe segment.

◆ Normal()

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

Compute the distance vector between a circle and a point.

Parameters
pPoint.

◆ Poisson()

QVector< Vector2 > Circle2::Poisson ( const double & ra,
int n,
bool border = false,
Random & random = Random::R239 ) const

Compute a Poisson disc distribution inside a circle.

This function uses a simple \( O(n^3) \) dart throwing algorithm.

See also
Box2::Poisson
Parameters
raRadius of the disc.
nNumber of candidate points.
borderTrue to sample the border
randomRandom number generator.

◆ PoissonNorder()

QVector< Vector2 > Circle2::PoissonNorder ( const double & ra,
int n,
Random & random = Random::R239 ) const

Compute a Poisson disc distribution on the boundary of a circle.

This function uses a simple \( O(n^2) \) dart throwing algorithm.

See also
Box2::Poisson
Parameters
raRadius of the disc.
nNumber of candidate points.
randomRandom number generator.

◆ QuadricBezierArc() [1/2]

QuadricCurve2 Circle2::QuadricBezierArc ( const double & t) const

Compute the quadratic B�zier approximation of a circle arc.

Approximation yields best results for 0 ≤ t ≤ \( \pi/4 \).

Parameters
tAngle.

◆ QuadricBezierArc() [2/2]

QuadricCurve2 Circle2::QuadricBezierArc ( const double & a,
const double & b ) const

Compute the quadratic B�zier approximation of a circle arc.

Approximation yields best results for 0 ≤ b-a ≤ \( \pi/4 \).

Parameters
a,bAngles.

◆ R()

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

Compute the squared distance between a point and the circle.

Parameters
pPoint.

◆ RandomInside()

Vector2 Circle2::RandomInside ( Random & random = Random::R239) const

Generate a random vector inside the circle.

Parameters
randomRandom number generator.

◆ RandomOn()

Vector2 Circle2::RandomOn ( Random & random = Random::R239) const

Generate a random vector on the circle.

Parameters
randomRandom number generator.

◆ RandomUnit()

Vector2 Circle2::RandomUnit ( Random & random = Random::R239)
static

Compute a random vertex inside a unit disc.

Parameters
randomRandom number generator.

◆ Rotate()

void Circle2::Rotate ( const Matrix2 & m)
inline

Rotates a circle.

Parameters
mRotation matrix.

◆ Rotated()

Circle2 Circle2::Rotated ( const Matrix2 & r) const
inline

Rotates a circle.

Parameters
rRotation matrix.

◆ Scale()

void Circle2::Scale ( const double & s)
inline

Scales a circle.

Parameters
sScaling factor.

◆ Scaled()

Circle2 Circle2::Scaled ( const double & s) const
inline

Return a uniformly scaled circle.

Parameters
sScaling factor.

◆ Tangent()

Vector2 Circle2::Tangent ( const double & a) const

Tangent to the circle.

Parameters
aAngle.

◆ Transformed()

Circle2 Circle2::Transformed ( const Frame2 & f) const
inline

Return a circle transformed by a frame.

Parameters
fTransformation.

◆ Translate()

void Circle2::Translate ( const Vector2 & t)
inline

Translate a circle.

Parameters
tTranslation vector.

◆ Translated()

Circle2 Circle2::Translated ( const Vector2 & t) const
inline

Translate a circle.

Parameters
tTranslation vector.

◆ Vertex()

Vector2 Circle2::Vertex ( const double & a) const

Vertex on the circle.

Parameters
aAngle.

◆ Vogel()

Vector2 Circle2::Vogel ( int i,
int n ) const

Generate a spiraling point in the disc.

Points generated for i in [0, n-1] follow Vogel's sunflower spiral, which distributes them uniformly in the disc of the circle: the distance to the center is proportional to the square root of the index, and the angle increases by the golden angle.

Parameters
iInteger, should be <n.
nNumber of points.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Circle2 & circle )
friend

Overloaded.

Parameters
sStream.
circleThe circle.