int main(int argc, char **argv) { int sz=50; int i; double A[sz][sz]; int A_row,A_col; double *pA[sz]; for ( i=0; i<sz; ++i ) pA[i]=&A[i][0]; double b[sz]; int b_sz; double bp[sz]; int bp_sz; //для проверки double r1[sz]; int r1_sz; double r2[sz]; int r2_sz; double r3[sz]; int r3_sz; double r4[sz]; int r4_sz; input_matr(pA,&A_row,&A_col); vivod_matr(pA,A_row,A_col,"A"); input(b,&b_sz); vivod(b,b_sz,"b"); double x[sz]; int x_sz=b_sz; for(i=0; i<sz; i++) x[i]=10; for(i=0; i<100; ++i) { printf("Итерация = %d\t",i); vivod(x,x_sz,"x"); mnog_vec_matr (x, x_sz, pA, A_row,A_col, r1, &r1_sz); //r1=A*x // vivod(r1,r1_sz,"r1"); vecmin(r1,r1_sz,b,b_sz,r2,&r2_sz);//(rk=)r2=r1-b=A*x-b // vivod(r2,r2_sz,"r2"); mnog_vec_matr (r2, r2_sz, pA, A_row, A_col, r3, &r3_sz);//r3=A*rk // vivod(r3,r3_sz,"r3"); double chisl= scalmnog ( r2,r2_sz,r2,r2_sz);//chisl=r2*r2 // printf("chisl=%fl\n",chisl); double zn = scalmnog ( r2,r2_sz,r3,r3_sz);//zn=r2*r3 // printf("zn=%f\n",zn); double a=chisl/zn; // printf("a=%f\n",a); vecscal (a,r2,r2_sz,r4,&r4_sz);//r4=a*rk // vivod(r4,r4_sz,"r4"); vecmin(x,x_sz,r4,r4_sz,x,&x_sz); vivod(x,x_sz,"x"); } mnog_vec_matr(x,x_sz,pA,A_row,A_col,bp,&bp_sz); vivod(b,b_sz,"b"); vivod(bp,bp_sz,"bp"); return 0; }
Mesh::Mesh(const char* off_filename) : _normals(0), _min(INFINITY, INFINITY, INFINITY), _max(-INFINITY, -INFINITY, -INFINITY), _fullyTriangulated(true) { _filename = off_filename; { QStringList sl = _filename.split('/'); _name = sl.at(sl.size() - 1).split(".").at(0); } QFile file(_filename); if (not file.open(QIODevice::ReadOnly | QIODevice::Text)) { THROW(MeshException, QString("Unable to open file \'%1\' for reading.").arg(file.errorString())); } QTextStream in(&file); int lineNumber = 0; QString line; do { line = in.readLine(); lineNumber++; } while (not line.isEmpty() and line.at(0) == '#'); // is signature correct? line.truncate(3); if(line.isNull() or (line != "OFF" and line != "off")) THROW(MeshException, QString("\'%1\'' is not an OFF file ").arg(off_filename)); lineNumber++; // skip comments do { line = in.readLine(); lineNumber++; } while(not line.isNull() and line.at(0) == '#'); QStringList lst = line.split(' '); // get vertex_count face_count edge_count size_t vertex_count = lst.at(0).toULong(), face_count = lst.at(1).toULong();//, edge_count = lst.at(2).toULong(); resetMinMax(); // process vertices for (size_t i = 0; i < vertex_count and not in.atEnd(); i++) { lineNumber++; float coord[3]; in >> coord[0] >> coord[1] >> coord[2]; if (in.status() != QTextStream::Ok) THROW(MeshException, QString(" in %1:%1 failed to read coordinate.").arg(off_filename, QString::number(lineNumber))); _vertices.push_back(QVector3D(coord[0], coord[1], coord[2])); } // process faces for(size_t i = 0; i < face_count and not in.atEnd(); i++) { unsigned firstIndex, lastIndex; int poly_type; in >> poly_type; if (in.status() == QTextStream::Ok) { if(poly_type != 3) _fullyTriangulated = false; unsigned vertexIndex; for(int i = 0; i < poly_type; i++) { lastIndex = vertexIndex; in >> vertexIndex; if (in.status() == QTextStream::Ok) { if (i == 0) firstIndex = vertexIndex; else if (i > 2) // this triangulation should work for convex polygons { _triangleIndices.push_back(firstIndex); _triangleIndices.push_back(lastIndex); } _min = vecmin(_min, _vertices[vertexIndex]); _max = vecmax(_max, _vertices[vertexIndex]); _triangleIndices.push_back(vertexIndex); } else THROW(MeshException, QString("in %1:%2 polygon is not a Triangle.").arg(off_filename, QString::number(lineNumber))); } } else THROW(MeshException, QString("in %1:%2 failed to read number of vertices.").arg(off_filename, QString::number(lineNumber))); lineNumber++; }