Algorithms_in_C++ 1.0.0
Set of 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>
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.
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 |
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 |
int main | ( | void | ) |
bool PointInCircle | ( | const std::vector< Point > & | P, |
const Point & | Center, | ||
double | R ) |
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 |
void test | ( | ) |
Test case: result should be:
Circle with
radius 3.318493136080724
centre at (3.0454545454545454, 1.3181818181818181)
void test2 | ( | ) |
Test case: result should be:
Circle with
radius 1.4142135623730951
centre at (1.0, 1.0)
void test3 | ( | ) |
Test case: result should be:
Circle with
radius 1.821078397711709
centre at (2.142857142857143, 1.7857142857142856)
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 |