Triangle

Kolorwanie:
Status:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
/*********TRIANGLE***************/

class Triangle : Polygon{
  public:
    Triangle(const Point A, const Point B, const Point C);

    double area() const;
};

/***************TRIANGLE****************/
Point triangleArray[3];

Point *createTriangleArray(const Point &A, const Point &B, const Point &C)
{
    triangleArray[0] = A;
    triangleArray[1] = B;
    triangleArray[2] = C;

    return triangleArray;
}


Triangle::Triangle(const Point A, const Point B, const Point C):Polygon(createTriangleArray(A, B, C), 3){}

double Triangle::area() const
{
    double xa,ya,xb,yb,xc,yc;
	double a, b, c, S, p;
	xa = pArr.get(0)->getX();
	ya = pArr.get(0)->getY();

	xb = pArr.get(1)->getX();
	yb = pArr.get(1)->getY();

	xc = pArr.get(2)->getX();
	yc = pArr.get(2)->getY();

	double lenght(double xa,double ya,double xb,double yb)
	{
    	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
	}

    a = lenght(xa,ya,xb,yb);
    b = lenght(xb,yb,xc,yc);
    c = lenght(xc,yc,xa,ya);

    p = (a + b + c)/2;
    S = sqrt(p*(p-a)*(p-b)*(p-c));

	return S;
}



Copyrights 2014-2019 © Wklejaj.pl Wszelkie prawa zastrzeżone.