TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Get centre and radius of the smallest circle that circumscribes given set of points. More...
#include <cmath>
#include <iostream>
#include <vector>
Go to the source code of this file.
Classes | |
struct | Point |
Functions | |
double | LenghtLine (const Point &A, const Point &B) |
double | TriangleArea (const Point &A, const Point &B, const Point &C) |
bool | PointInCircle (const std::vector< Point > &P, const Point &Center, double R) |
double | circle (const std::vector< Point > &P) |
void | test () |
void | test2 () |
void | test3 () |
int | main () |
Get centre and radius of the smallest circle that circumscribes given set of points.
Definition in file smallest_circle.cpp.
double circle | ( | const std::vector< Point > & | P | ) |
Find the centre and radius of a circle enclosing a set of points.
The function returns the radius of the circle and prints the coordinated of the centre of the circle.
[in] | P | vector of points |
Definition at line 87 of file smallest_circle.cpp.
Compute the Euclidian distance between two points \(A\equiv(x_1,y_1)\) and \(B\equiv(x_2,y_2)\) using the formula:
\[d=\sqrt{\left(x_1-x_2\right)^2+\left(y_1-y_2\right)^2}\]
[in] | A | point A |
[in] | B | point B |
Definition at line 37 of file smallest_circle.cpp.
int main | ( | void | ) |
Main program
Definition at line 198 of file smallest_circle.cpp.
Check if a set of points lie within given circle. This is true if the distance of all the points from the centre of the circle is less than the radius of the circle
[in] | P | set of points to check |
[in] | Center | coordinates to centre of the circle |
[in] | R | radius of the circle |
Definition at line 72 of file smallest_circle.cpp.
void test | ( | ) |
Test case: result should be:
Circle with
radius 3.318493136080724
centre at (3.0454545454545454, 1.3181818181818181)
Definition at line 158 of file smallest_circle.cpp.
void test2 | ( | ) |
Test case: result should be:
Circle with
radius 1.4142135623730951
centre at (1.0, 1.0)
Definition at line 173 of file smallest_circle.cpp.
void test3 | ( | ) |
Test case: result should be:
Circle with
radius 1.821078397711709
centre at (2.142857142857143, 1.7857142857142856)
Definition at line 188 of file smallest_circle.cpp.
Compute the area of triangle formed by three points using Heron's formula. If the lengths of the sides of the triangle are \(a,\,b,\,c\) and \(s=\displaystyle\frac{a+b+c}{2}\) is the semi-perimeter then the area is given by
\[A=\sqrt{s(s-a)(s-b)(s-c)}\]
[in] | A | vertex A |
[in] | B | vertex B |
[in] | C | vertex C |
Definition at line 54 of file smallest_circle.cpp.