# 2D Circles

This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

## Functions

 Cir2D cir2d (...) Cir2D cir2d_from_box (...) Cir2D cir2d_from_points (...) Cir2D cir2d_minimum (...) real cir2d_area (...) bool_t cir2d_is_null (...)

## Types and Constants

Circles allow us to group a set of points within the same container volume. Collision detection will be performed optimally since it is the geometric test that requires the fewest operations. Given a set of points, we can calculate the container circle in various ways (Figure 1) depending on the precision and speed needed.

• Use cir2d_from_boxf to get the circle from a 2D box.
• Use cir2d_minimumf to obtain the circle of minimum radius from a set of points.
• Use cir2d_from_pointsf to obtain the circle from the the set average. More balanced option in terms of precision/performance.

## kNULL

```const Cir2Df kCIR2D_NULLf;

const Cir2Dd kCIR2D_NULLd;

const Cir2D Cir2D::kNULL;```

Represents a null circle (no geometry).

## cir2d ()

Create a 2d circle from its components.

```Cir2Df
cir2df(const real32_t x,
const real32_t y,
const real32_t r);

Cir2Dd
cir2dd(const real64_t x,
const real64_t y,
const real64_t r);

Cir2D
Cir2D(const real x,
const real y,
const real r);
```
 x Center x coordinate. y Center y coordinate. r Radius.

Return

The 2d circle.

## cir2d_from_box ()

Create a circle containing a 2D box.

```Cir2Df
cir2d_from_boxf(const B2D *box);

Cir2Dd
cir2d_from_boxd(const B2D *box);

Cir2D
Cir2D::from_box(const B2D *box);
```
 box The box.

Return

The circle.

## cir2d_from_points ()

Create a circle containing a set of points.

```Cir2Df
cir2d_from_pointsf(const V2Df *p,
const uint32_t n);

Cir2Dd
cir2d_from_pointsd(const V2Dd *p,
const uint32_t n);

Cir2D
Cir2D::from_points(const V2D *p,
const uint32_t n);
```
 p The points vector. n The number of points.

Return

The circle.

Remarks

The center will be the midpoint of the set. The radius will be the distance to the farthest point from that center. Provides a good fit with linear cost.

## cir2d_minimum ()

Calculate the circle of minimum radius that contains a set of points.

```Cir2Df
cir2d_minimumf(const V2Df *p,
const uint32_t n);

Cir2Dd
cir2d_minimumd(const V2Dd *p,
const uint32_t n);

Cir2D
Cir2D::minimum(const V2D *p,
const uint32_t n);
```
 p The points vector. n The number of points.

Return

The circle.

Remarks

Provides optimal adjustment in linear time. However, it is slower than cir2d_from_pointsf.

## cir2d_area ()

Gets the area of ​​the circle.

```real32_t
cir2d_areaf(const Cir2Df *cir);

real64_t

real
Cir2D::area(const Cir2D *cir);
```
 cir The circle.

Return

The area `(πr²)`.

## cir2d_is_null ()

Check if a circle is null (dimensionless).

```bool_t
cir2d_is_nullf(const Cir2Df *cir);

bool_t
cir2d_is_nulld(const Cir2Dd *cir);

bool_t
Cir2D::is_null(const Cir2D *cir);
```
 cir The circle.

Return

`TRUE` if it is null, `FALSE` if it contains any point.

Remarks

A single point is a valid circle with radius = 0.