33 #include <boost/random/mersenne_twister.hpp> 34 #include <boost/random/uniform_01.hpp> 35 #include <boost/random/variate_generator.hpp> 44 #define PRECISION double // todo: use template instead 45 #define PI360 6.283185307179586 46 #define PI90 1.570796326794897 47 #define RAD2ANGLE(X) ((X)*57.295779513082322) 48 #define ANGLE2RAD(X) ((X)*1.745329251994e-02) 49 #define RAD2ANGLEMAP(X) (X > M_PI ? RAD2ANGLE(PI360 - X) : RAD2ANGLE(X)) 62 CVec() { x = y = z = 0.0; w = 1.0;}
78 return CVec( x*s, y*s, z*s );
82 return CVec( x/s, y/s, z/s );
88 x = v.
x; y = v.
y; z = v.
z; w = 1.0f;
107 return CVec( x + v.
x, y + v.
y, z + v.
z );
146 return CVec( x - v.
x, y - v.
y, z - v.
z );
153 return CVec( -x, -y, -z );
159 return x*v.
x + y*v.
y + z*v.
z;
165 return CVec( y*v.
z - z*v.
y, z*v.
x - x*v.
z, x*v.
y - y*v.
x );
170 return sqrt(x*x+y*y+z*z);
222 std::string
toString(
bool round =
false);
226 void print(
bool round =
false)
const;
234 void randomOrientation(
double max = 2.0 * M_PI);
280 static double calcDotProduct(
double firstVector[],
double secondVector[],
int size);
285 static void calcMatrixResult(
double matrix[],
double vector[],
int rows,
int columns,
double resultVector[]);
288 static void getRotationFromMatrix(
const CMatrix &mat,
CVec &axis,
double &angle);
289 static void getQuaternionFromRotation(
CVec &quater,
CVec &axis,
double angle);
296 static void transposeMatrix(
double *matrix,
double *resultMatrix,
int size);
301 static void multiplyMatrices(
double *firstMatrix,
double *secondMatrix,
int firstRows,
int firstColumns,
int secondColumns,
double *resultMatrix);
306 static void quaternionFromMatrix(
const CMatrix &mat,
CVec &quaternion);
309 static void matrixFromQuaternion(
CVec &quaternion,
CMatrix &matrix);
312 static void getMatrixFromRotation(
CMatrix &mat,
const CVec &axis,
double angle);
315 static void getEulerZXZ(
CMatrix &mat,
CVec &first);
318 static void getOrientation(
CMatrix &mat,
CVec &first,
CVec &second,
bool old =
false);
323 static void getRotation(
CMatrix &mat,
CVec &vec,
bool old =
false);
326 static void getRotation(
CMatrix &mat,
double x,
double y,
double z,
bool old =
false);
336 static void calcAngles(
double leg1,
double leg2,
double x,
double y,
double &first,
double &second);
340 double sign(
double value);
343 unsigned long fac(
unsigned int value);
346 void getMeanFromVectors(std::vector<std::vector<double> > &values, std::vector<double> &mean);
348 double getSigmoid(
double value,
double offset,
double factor);
365 void rosenbrock(
int n,
double *
x,
double *bl,
double *bu,
366 double bigbnd,
int maxiter,
double eps,
int verbose,
367 void obj(
int,
double *,
double *,
void *),
void *extraparams);
369 double bigbnd,
int maxiter,
double eps,
int verbose,
370 void obj(
int,
double *,
double *,
void *),
void *extraparams);
384 tmpCMatrixMul[0] = first.
a[0] * second.
a[0] + first.
a[4] * second.
a[1] + first.
a[8] * second.
a[2];
385 tmpCMatrixMul[1] = first.
a[1] * second.
a[0] + first.
a[5] * second.
a[1] + first.
a[9] * second.
a[2];
386 tmpCMatrixMul[2] = first.
a[2] * second.
a[0] + first.
a[6] * second.
a[1] + first.
a[10] * second.
a[2];
387 tmpCMatrixMul[3] = 0.0;
388 tmpCMatrixMul[4] = first.
a[0] * second.
a[4] + first.
a[4] * second.
a[5] + first.
a[8] * second.
a[6];
389 tmpCMatrixMul[5] = first.
a[1] * second.
a[4] + first.
a[5] * second.
a[5] + first.
a[9] * second.
a[6];
390 tmpCMatrixMul[6] = first.
a[2] * second.
a[4] + first.
a[6] * second.
a[5] + first.
a[10] * second.
a[6];
391 tmpCMatrixMul[7] = 0.0;
392 tmpCMatrixMul[8] = first.
a[0] * second.
a[8] + first.
a[4] * second.
a[9] + first.
a[8] * second.
a[10];
393 tmpCMatrixMul[9] = first.
a[1] * second.
a[8] + first.
a[5] * second.
a[9] + first.
a[9] * second.
a[10];
394 tmpCMatrixMul[10] = first.
a[2] * second.
a[8] + first.
a[6] * second.
a[9] + first.
a[10] * second.
a[10];
395 tmpCMatrixMul[11] = 0.0;
396 tmpCMatrixMul[12] = first.
a[0] * second.
a[12] + first.
a[4] * second.
a[13] + first.
a[8] * second.
a[14] + first.
a[12] * second.
a[15];
397 tmpCMatrixMul[13] = first.
a[1] * second.
a[12] + first.
a[5] * second.
a[13] + first.
a[9] * second.
a[14] + first.
a[13] * second.
a[15];
398 tmpCMatrixMul[14] = first.
a[2] * second.
a[12] + first.
a[6] * second.
a[13] + first.
a[10] * second.
a[14] + first.
a[14] * second.
a[15];
399 tmpCMatrixMul[15] = first.
a[15] * second.
a[15];
400 memcpy(a, tmpCMatrixMul, 16*
sizeof(
PRECISION));
407 a[0] = first.
a[0] * second.
a[0] + first.
a[4] * second.
a[1] + first.
a[8] * second.
a[2];
408 a[1] = first.
a[1] * second.
a[0] + first.
a[5] * second.
a[1] + first.
a[9] * second.
a[2];
409 a[2] = first.
a[2] * second.
a[0] + first.
a[6] * second.
a[1] + first.
a[10] * second.
a[2];
411 a[4] = first.
a[0] * second.
a[4] + first.
a[4] * second.
a[5] + first.
a[8] * second.
a[6];
412 a[5] = first.
a[1] * second.
a[4] + first.
a[5] * second.
a[5] + first.
a[9] * second.
a[6];
413 a[6] = first.
a[2] * second.
a[4] + first.
a[6] * second.
a[5] + first.
a[10] * second.
a[6];
415 a[8] = first.
a[0] * second.
a[8] + first.
a[4] * second.
a[9] + first.
a[8] * second.
a[10];
416 a[9] = first.
a[1] * second.
a[8] + first.
a[5] * second.
a[9] + first.
a[9] * second.
a[10];
417 a[10] = first.
a[2] * second.
a[8] + first.
a[6] * second.
a[9] + first.
a[10] * second.
a[10];
419 a[12] = first.
a[0] * second.
a[12] + first.
a[4] * second.
a[13] + first.
a[8] * second.
a[14] + first.
a[12] * second.
a[15];
420 a[13] = first.
a[1] * second.
a[12] + first.
a[5] * second.
a[13] + first.
a[9] * second.
a[14] + first.
a[13] * second.
a[15];
421 a[14] = first.
a[2] * second.
a[12] + first.
a[6] * second.
a[13] + first.
a[10] * second.
a[14] + first.
a[14] * second.
a[15];
422 a[15] = first.
a[15] * second.
a[15];
426 extern boost::uniform_01<double>
pRngDist;
427 extern boost::variate_generator<boost::mt19937&, boost::uniform_01<double> >
pRngUniform01;
437 return min + (int) (((
double)(max - min)) *
pRngUniform01() + 0.5);
449 v = (2.0*u1 - 1.0)*(2.0*u1 - 1.0) + (2.0*u2 - 1.0)*(2.0*u2 - 1.0);
452 x = (2.0*u1 -1.0)*sqrt(-2.0*log(v) / v);
458 #define SWAPELEMENTS(x,y) tmp = a[x];a[x]=a[y];a[y] = tmp; 483 a[12] = a[0] * x + a[4] * y + a[8] *
z;
484 a[13] = a[1] * x + a[5] * y + a[9] *
z;
485 a[14] = a[2] * x + a[6] * y + a[10] *
z;
void calculateTransformationFromPlane(CVec &plane, CMatrix &transformation)
Denavit Hartenberg Link information.
boost::uniform_01< double > pRngDist
CVec operator*(PRECISION s) const
Scalar multiplication.
CVec operator+(const CVec &v) const
Vector addition.
double getSigmoid(double value, double offset, double factor)
CVec & operator/=(PRECISION s)
void mul(const CMatrix &first, const CMatrix &second)
Assigns product of two matrices to matrix.
void getMeanFromVectors(std::vector< std::vector< double > > &values, std::vector< double > &mean)
CVec(PRECISION x, PRECISION y, PRECISION z)
double getLogisticProb(double alpha, double beta)
double getGaussian(double value, double mean, double std)
CVec operator^(const CVec &v) const
Cross product.
boost::mt19937 pRngMt19937
void mulNoAlloc(const CMatrix &first, const CMatrix &second)
CVec & operator+=(const CVec &v)
#define SWAPELEMENTS(x, y)
CVec operator/(PRECISION s) const
double getGaussianProb(double mean, double std)
void print() const
Prints vector as (x,y,z) to console.
void setUniformSeed(unsigned int seed)
void simulatedannealing(int n, double *x, double *bl, double *bu, double bigbnd, int maxiter, double eps, int verbose, void obj(int, double *, double *, void *), void *extraparams)
double getGaussianWithoutNormalization(double value, double mean, double std)
PRECISION operator[](unsigned int i) const
Array access (read)
int rnd(PRECISION value)
Rounds a value.
unsigned long fac(unsigned int value)
boost::variate_generator< boost::mt19937 &, boost::uniform_01< double > > pRngUniform01
CVec operator-() const
Vector negation.
void rosenbrock(int n, double *x, double *bl, double *bu, double bigbnd, int maxiter, double eps, int verbose, void obj(int, double *, double *, void *), void *extraparams)
void orientation2scaledAxis(CMatrix &matrix, CVec &axis)
void matrixToArray(const CMatrix &matrix, std::vector< double > &values)
PRECISION operator|(const CVec &v) const
Dot product.
CVec & operator*=(PRECISION s)
void scaledAxis2Orientation(CVec &axis, CMatrix &matrix)
CVec & operator-=(const CVec &v)
CVec & operator=(const CVec &v)
Assigns values of vector v to vector.
double vectorlength(std::vector< double > &v)
void invert()
Inverts the matrix (only for homogenous matrices)
void arrayToMatrix(CMatrix &matrix, std::vector< double > &values)
void convertMatrix(CMatrix &from, double(*R)[3], double *T)
double sign(double value)
int roundToInt(double value)