Advertisement
Guest User

3DP

a guest
Nov 27th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. // Objekte fürs lineare Gleichungssystem: m*x = b, Lösung kommt in x.
  2.     Mat m, x, b;
  3.     int dim = 3; // the computing dimension (e.g. 3 for X, Y, Z)
  4.     std::stringstream txtDebug;
  5.  
  6.     // init matrices
  7.     m = Mat(dim*iN, dim+1, CV_64FC1, double(0));
  8.     x = Mat(dim+iN, 1, CV_64FC1, double(0));
  9.     b = Mat(dim*iN, 1, CV_64FC1, double(0));
  10.  
  11.     // fill matrices with known information
  12.     for (int i=0;i<iN;i++)
  13.         for (int j=0;j<dim;j++)
  14.         {
  15.             m.at<double>(i*dim+j,j)   = 1.0;
  16.             m.at<double>(i*dim+j,dim) = (-1) * matDir.at<double>(j,i);
  17.             b.at<double>(i*dim+j,0)   = matPoint.at<double>(j,i);
  18.         }
  19.  
  20.     // get inverse of m and solve equation
  21.     x = m.inv(DECOMP_SVD) * b;
  22.  
  23.     // debug
  24.     for (int i=0;i<x.rows;i++)
  25.     {
  26.         for (int j=0;j<x.cols;j++)
  27.         {
  28.             txtDebug << " " << x.at<double>(i,j) << "; ";   // In die Output Edit Box des Dialogs
  29.             //if (i%4 == 0)
  30.         }
  31.         txtDebug << "\r\n";
  32.     }
  33.     txtOut.Format("%s",txtDebug.str().c_str());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement