rendered paste body#include "punkt.h"#include "dane.h"#include <iostream>#include <time.h>#include <math.h>#include <iomanip>#define PI 4*atan(1)using namespace std;double punkt :: delta = 0;punkt :: punkt (){ //generowanie tensora symetrycznego tensor = new double*[3]; for(int i=0; i<3; i++) tensor[i] = new double[3]; srand((unsigned int)time(NULL)); //zapelnianie tensora danymi tensor[0][0] = rand()%(maxw-minw+1)+minw + delta; tensor[0][1] = rand()%(maxw-minw+1)+minw + delta; tensor[0][2] = rand()%(maxw-minw+1)+minw + delta; tensor[1][0] = tensor[0][1]; tensor[1][1] = rand()%(maxw-minw+1)+minw + delta; tensor[1][2] = rand()%(maxw-minw+1)+minw + delta; tensor[2][0] = tensor[0][2]; tensor[2][1] = tensor[1][2]; tensor[2][2] = rand()%(maxw-minw+1)+minw + delta;delta++;}punkt :: ~punkt(){for(int i=0; i<3; i++)delete tensor[i];delete tensor;}void punkt :: show(){ for(int i = 0; i<3; i++){ for(int j=0; j<3; j++){ cout<<noshowpos<<setprecision(4)<<tensor[i][j]<<"\t"; } cout<<endl; }cout<<endl; }void punkt :: oblicz_wspolczynniki(){I1 = (long int)(tensor[0][0] + tensor[1][1] + tensor[2][2]);I2 = (long int)((tensor[1][1]*tensor[2][2] - tensor[1][2]*tensor[2][1]) + (tensor[0][0]*tensor[2][2] - tensor[0][2]*tensor[2][0]) + (tensor[0][0]*tensor[1][1] - tensor[0][1]*tensor[1][0]));I3 = (long int)(tensor[0][0]*tensor[1][1]*tensor[2][2] + tensor[1][0]*tensor[2][1]*tensor[0][2] + tensor[2][0]*tensor[0][1]*tensor[1][2] - tensor[1][0]*tensor[0][1]*tensor[2][2] -tensor[0][0]*tensor[2][1]*tensor[1][2] - tensor[2][0]*tensor[1][1]*tensor[0][2]);if(I1<0) -I1;if(I3<0) -I3; }void punkt :: show_rownanie(){cout<<showpos<<"x^3 "<<I1<<"x^2 "<<I2<<"x "<<I3<<" = 0"<<endl;}void punkt :: oblicz_pierwiastki(){ double p,q,r,th,u,v,c,delta,eps=1e-12; c=-I1/(3.); p=(3*I2-pow(I1,2))/(9.); q=(2*pow(I1,3)-9*I1*I2+27*I3)/(54.); delta=pow(q,2)+pow(p,3); if(fabs(delta)<eps) delta=0.; if (delta>0){ u=cbrt(-q-sqrt(delta)); v=cbrt(-q+sqrt(delta)); tensor[0][0] = u+v+c; tensor[1][1] = 0; tensor[2][2] = 0; tensor[0][1] = 0; tensor[0][2] = 0; tensor[1][0] = 0; tensor[1][2] = 0; tensor[2][0] = 0; tensor[2][1] = 0; } if(delta<=0.){ r=hypot(-q,sqrt(-delta)); th=atan2(sqrt(-delta),-q); tensor[0][0] = 2*cbrt(r)*cos((th/3.))+c; tensor[1][1] = 2*cbrt(r)*cos((th+2*PI)/3.)+c; tensor[2][2] = 2*cbrt(r)*cos((th-2*PI)/3.)+c; tensor[0][1] = 0; tensor[0][2] = 0; tensor[1][0] = 0; tensor[1][2] = 0; tensor[2][0] = 0; tensor[2][1] = 0; }}