1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <windows.h>
#include <iostream>
#include <cmath>
template<class _Ty> class vec2 {
public :
vec2() {x=y=0.0;}
vec2(_Ty X, _Ty Y) {x=X; y=Y;}
vec2 operator+(const vec2& vec) {return vec2(x+vec.x, y+vec.y);}
vec2 operator-(const vec2& vec) {return vec2(x-vec.x, y-vec.y);}
vec2 operator*(const vec2& vec) {return vec2(x*vec.x, y*vec.y);}
_Ty x, y;
};
double distance(const vec2<double>& point1, const vec2<double>& point2) {
return sqrt(pow(point2.x - point1.x, 2) + pow(point2.y - point1.y, 2));
}
int main(int argc, char** argv) {
SetConsoleTitleA("Radius");
/*
To compute the radius of a circle, you need either:
The center point of the circle and one other point which lies on its circumference.
Three points which lie on its circumference.
If I recall correctly, there's some other possibilities as well.
To find a point which lies on a circle's circumference, you need:
The center point of the circle and the radius.
*/
/*Example program of finding the radius, given the center(0, 0) and another point on the circumference.*/
vec2<double> center, point(5.0, 7.8);
double rad = distance(center, point);
std::cout << "The radius of the circle is " << rad << std::endl;
/*Example program of finding a point on the circumference, given the radius and the center(0, 0).*/
double deg = 0.0;//some random angle.
double rad = 1.0;//unit circle.
vec2<double> center, point(cos(deg)*rad, sin(deg)*rad);
std::cout << "The point coordinates are [" << point.x << ", " << point.y << "]" << std::endl;
/**/
std::cin.get();
return 0;
}
|