Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

КомпГр_ЛР2_Заболотников_Петрова_Романова_9373

.pdf
Скачиваний:
27
Добавлен:
20.06.2023
Размер:
854.54 Кб
Скачать

Paint::Paint()

{

//QVector<double> x1 = {1};

//QVector<double> x2 = {4};

//QVector<double> x3 = {7};

//QVector<double> x4 = {0};

//QVector<double> x5 = {0};

//QVector<double> y1 = {1};

//QVector<double> y2 = {4};

//QVector<double> y3 = {2};

//QVector<double> y4 = {0};

//QVector<double> y5 = {0};

double massiveX[5][1] = {{1},{4},{7},{0},{0}}; double massiveY[5][1] = {{1},{4},{2},{0},{0}};

for(int i = 0; i < 5; i ++)

{

QVector<double> tempX; QVector<double> tempY;

for (int j = 0; j < 1; j++)

{

tempX.push_back(massiveX[i][j]); tempY.push_back(massiveY[i][j]);

}

X.push_back(tempX);

Y.push_back(tempY);

}

numberOfPoints = 3; calcP();

}

QVector<double> Paint::getx(int point)

{

return X[point-1];

}

QVector<double> Paint::gety(int point)

{

return Y[point-1];

}

QVector<double> Paint::getPx()

{

return Px;

}

QVector<double> Paint::getPy()

{

return Py;

}

void Paint::calcP()

{

clearP();

for (double t = 0; t < 1.05; t = t + 0.05)

{

Px.push_back(clacPx(t));

Py.push_back(clacPy(t));

}

}

11

double Paint::clacPx(double t)

{

double value = 0;

int n = numberOfPoints - 1; for (int i = 0; i <= n; i++)

{

value = value + X[i][0]*(fact(n)/(fact(i)*fact(n- i)))*pow(t,i)*pow((1-t),(n-i));

}

return value;

}

double Paint::clacPy(double t)

{

double value = 0;

int n = numberOfPoints - 1; for (int i = 0; i <= n; i++)

{

value = value + Y[i][0]*(fact(n)/(fact(i)*fact(n- i)))*pow(t,i)*pow((1-t),(n-i));

}

return value;

}

void Paint::clearP()

{

Px.clear();

Py.clear();

}

void Paint::setNewPoints(double x1N, double x2N, double x3N, double x4N, double x5N, double y1N, double y2N, double y3N, double y4N, double y5N)

{

X.clear();

Y.clear();

double massiveX[5][1] = {{x1N},{x2N},{x3N},{x4N},{x5N}}; double massiveY[5][1] = {{y1N},{y2N},{y3N},{y4N},{y5N}};

for(int i = 0; i < 5; i ++)

{

QVector<double> tempX; QVector<double> tempY;

for (int j = 0; j < 1; j++)

{

tempX.push_back(massiveX[i][j]); tempY.push_back(massiveY[i][j]);

}

X.push_back(tempX);

Y.push_back(tempY);

}

}

int Paint::findNearest(int index, QVector<double> PxBuf, QVector<double> PyBuf)

{

int len = PxBuf.length(); int minInd = -1;

double minVal = 100000000; for (int i = 0; i < len; i++)

{

12

int dist;

dist = sqrt(pow((Px[index]-PxBuf[i]),2)+pow(Py[index] - PyBuf[i],2)); if (dist < minVal)

{

minInd = i; minVal = dist;

}

}

return minInd;

}

void Paint::setNum(int num)

{

numberOfPoints = num;

}

int Paint::getNum()

{

return numberOfPoints;

}

int Paint::fact(int val)

{

if(val == 0) return 1; else

{

return val*fact(val-1);

}

}

13