Website Summary Files Commits Branches @commit @diff @stats
path: root / Polymorphism / Figures / Triangle.hpp
blob: 5ac5a3584b97703fddebcc609cf4375f2771635c (plain) (blame)
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
#include "Figure.hpp"
class Triangle
{
public:
	Triangle(int x1, int y1, int x2, int y2, int x3, int y3) :Figure(3)
	{
		setPoint(0, x1, y1);
		setPoint(1, x2, y2);
		setPoint(2, x3, y3);
	}
	double getSide(int side)
	{
	        return getPoint(side).getDistTo(getPoint((side+1)%3));
	}
	double getPer()
	{
		return getSide(0)+getSide(1)+getSide(2);
	}
	double getArea()
	{
	        //Херонова формула
	        double halfP = getPer()/2; 
	        return sqrt(halfP * (halfP-getSide(0))*(halfP-getSide(1))*(halfP-getSide(2)));
	}
};