71 FILE *f = fopen(pFilePath,
"r");
83 char *pBuffer =
new char[nFileSize];
84 if (fread(pBuffer, nFileSize, 1, f) != 1)
93 if (sscanf(pBuffer,
"%f%f%f", &vector.
x, &vector.
y, &vector.
z) != 3)
107 FILE *f = fopen(pFilePath,
"r");
113 if (nFileSize > 1024)
119 char *pBuffer =
new char[nFileSize];
120 if (fread(pBuffer, nFileSize, 1, f) != 1)
129 if (sscanf(pBuffer,
"%f%f%f%f%f%f%f%f%f",
130 &matrix.
r1, &matrix.
r2, &matrix.
r3,
131 &matrix.
r4, &matrix.
r5, &matrix.
r6,
132 &matrix.
r7, &matrix.
r8, &matrix.
r9) != 9)
146 FILE *f = fopen(pFilePath,
"r");
152 if (nFileSize > 1024)
158 char *pBuffer =
new char[nFileSize];
159 if (fread(pBuffer, nFileSize, 1, f) != 1)
168 if (sscanf(pBuffer,
"%f%f%f%f%f%f%f%f%f%f%f%f",
185 FILE *f = fopen(pFilePath,
"w");
189 if (fprintf(f,
"%.10f %.10f %.10f", vector.
x, vector.
y, vector.
z) <= 0)
202 FILE *f = fopen(pFilePath,
"w");
206 if (fprintf(f,
"%.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f",
207 matrix.
r1, matrix.
r2, matrix.
r3,
208 matrix.
r4, matrix.
r5, matrix.
r6,
209 matrix.
r7, matrix.
r8, matrix.
r9) <= 0)
222 FILE *f = fopen(pFilePath,
"w");
226 if (fprintf(f,
"%.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f %.10f\n%.10f %.10f %.10f",
252 vec.
x = sourceVector.
x;
253 vec.
y = sourceVector.
y;
254 vec.
z = sourceVector.
z;
272 matrix.
r1 = sourceMatrix.
r1;
273 matrix.
r2 = sourceMatrix.
r2;
274 matrix.
r3 = sourceMatrix.
r3;
275 matrix.
r4 = sourceMatrix.
r4;
276 matrix.
r5 = sourceMatrix.
r5;
277 matrix.
r6 = sourceMatrix.
r6;
278 matrix.
r7 = sourceMatrix.
r7;
279 matrix.
r8 = sourceMatrix.
r8;
280 matrix.
r9 = sourceMatrix.
r9;
285 const float alpha = rotation.
x;
286 const float beta = rotation.
y;
287 const float gamma = rotation.
z;
289 const float sinfalpha = sinf(alpha);
290 const float cosfalpha = cosf(alpha);
291 const float sinfbeta = sinf(beta);
292 const float cosfbeta = cosf(beta);
293 const float sinfgamma = sinf(gamma);
294 const float cosfgamma = cosf(gamma);
296 matrix.
r1 = cosfbeta * cosfgamma;
297 matrix.
r2 = - cosfbeta * sinfgamma;
298 matrix.
r3 = sinfbeta;
299 matrix.
r4 = cosfalpha * sinfgamma + sinfalpha * sinfbeta * cosfgamma;
300 matrix.
r5 = cosfalpha * cosfgamma - sinfalpha * sinfbeta * sinfgamma;
301 matrix.
r6 = - sinfalpha * cosfbeta;
302 matrix.
r7 = sinfalpha * sinfgamma - cosfalpha * sinfbeta * cosfgamma;
303 matrix.
r8 = sinfalpha * cosfgamma + cosfalpha * sinfbeta * sinfgamma;
304 matrix.
r9 = cosfalpha * cosfbeta;
309 const float sinfalpha = sinf(alpha);
310 const float cosfalpha = cosf(alpha);
311 const float sinfbeta = sinf(beta);
312 const float cosfbeta = cosf(beta);
313 const float sinfgamma = sinf(gamma);
314 const float cosfgamma = cosf(gamma);
316 matrix.
r1 = cosfbeta * cosfgamma;
317 matrix.
r2 = - cosfbeta * sinfgamma;
318 matrix.
r3 = sinfbeta;
319 matrix.
r4 = cosfalpha * sinfgamma + sinfalpha * sinfbeta * cosfgamma;
320 matrix.
r5 = cosfalpha * cosfgamma - sinfalpha * sinfbeta * sinfgamma;
321 matrix.
r6 = - sinfalpha * cosfbeta;
322 matrix.
r7 = sinfalpha * sinfgamma - cosfalpha * sinfbeta * cosfgamma;
323 matrix.
r8 = sinfalpha * cosfgamma + cosfalpha * sinfbeta * sinfgamma;
324 matrix.
r9 = cosfalpha * cosfbeta;
343 matrix.
r2 = matrix.
r3 = matrix.
r4 = matrix.
r7 = 0;
344 matrix.
r5 = matrix.
r9 = cosf(theta);
345 matrix.
r6 = matrix.
r8 = sinf(theta);
346 matrix.
r6 = -matrix.
r6;
352 matrix.
r2 = matrix.
r4 = matrix.
r6 = matrix.
r8 = 0;
353 matrix.
r1 = matrix.
r9 = cosf(theta);
354 matrix.
r3 = matrix.
r7 = sinf(theta);
355 matrix.
r7 = -matrix.
r7;
361 matrix.
r3 = matrix.
r6 = matrix.
r7 = matrix.
r8 = 0;
362 matrix.
r1 = matrix.
r5 = cosf(theta);
363 matrix.
r2 = matrix.
r4 = sinf(theta);
364 matrix.
r2 = -matrix.
r2;
374 const float t1 = cosf(theta);
375 const float t2 = 1 - t1;
376 const float t3 = v1 *
v1;
377 const float t6 = t2 *
v1;
378 const float t7 = t6 *
v2;
379 const float t8 = sinf(theta);
380 const float t9 = t8 *
v3;
381 const float t11 = t6 *
v3;
382 const float t12 = t8 *
v2;
383 const float t15 = v2 *
v2;
384 const float t19 = t2 * v2 *
v3;
385 const float t20 = t8 *
v1;
386 const float t24 = v3 *
v3;
388 matrix.
r1 = t1 + t2 * t3;
390 matrix.
r3 = t11 + t12;
392 matrix.
r5 = t1 + t2 * t15;
393 matrix.
r6 = t19 - t20;
394 matrix.
r7 = t11 - t12;
395 matrix.
r8 = t19 + t20;
396 matrix.
r9 = t1 + t2 * t24;
406 const float s = sinf(theta);
407 const float c = cosf(theta);
408 const float t = 1.0f -
c;
410 matrix.
r1 = t * x * x +
c;
411 matrix.
r2 = t * x * y - s *
z;
412 matrix.
r3 = t * x * z + s *
y;
413 matrix.
r4 = t * x * y + s *
z;
414 matrix.
r5 = t * y * y +
c;
415 matrix.
r6 = t * y * z - s *
x;
416 matrix.
r7 = t * x * z - s *
y;
417 matrix.
r8 = t * y * z + s *
x;
418 matrix.
r9 = t * z * z +
c;
424 const float x = vec.
x;
425 const float y = vec.
y;
426 const float z = vec.
z;
428 result.
x = matrix.
r1 * x + matrix.
r2 * y + matrix.
r3 *
z;
429 result.
y = matrix.
r4 * x + matrix.
r5 * y + matrix.
r6 *
z;
430 result.
z = matrix.
r7 * x + matrix.
r8 * y + matrix.
r9 *
z;
435 const float x = vector1.
x;
436 const float y = vector1.
y;
437 const float z = vector1.
z;
439 result.
x = matrix.
r1 * x + matrix.
r2 * y + matrix.
r3 * z + vector2.
x;
440 result.
y = matrix.
r4 * x + matrix.
r5 * y + matrix.
r6 * z + vector2.
y;
441 result.
z = matrix.
r7 * x + matrix.
r8 * y + matrix.
r9 * z + vector2.
z;
446 const float x1 = matrix1.
r1 * matrix2.
r1 + matrix1.
r2 * matrix2.
r4 + matrix1.
r3 * matrix2.
r7;
447 const float x2 = matrix1.
r1 * matrix2.
r2 + matrix1.
r2 * matrix2.
r5 + matrix1.
r3 * matrix2.
r8;
448 const float x3 = matrix1.
r1 * matrix2.
r3 + matrix1.
r2 * matrix2.
r6 + matrix1.
r3 * matrix2.
r9;
449 const float x4 = matrix1.
r4 * matrix2.
r1 + matrix1.
r5 * matrix2.
r4 + matrix1.
r6 * matrix2.
r7;
450 const float x5 = matrix1.
r4 * matrix2.
r2 + matrix1.
r5 * matrix2.
r5 + matrix1.
r6 * matrix2.
r8;
451 const float x6 = matrix1.
r4 * matrix2.
r3 + matrix1.
r5 * matrix2.
r6 + matrix1.
r6 * matrix2.
r9;
452 const float x7 = matrix1.
r7 * matrix2.
r1 + matrix1.
r8 * matrix2.
r4 + matrix1.
r9 * matrix2.
r7;
453 const float x8 = matrix1.
r7 * matrix2.
r2 + matrix1.
r8 * matrix2.
r5 + matrix1.
r9 * matrix2.
r8;
454 const float x9 = matrix1.
r7 * matrix2.
r3 + matrix1.
r8 * matrix2.
r6 + matrix1.
r9 * matrix2.
r9;
469 result.
r1 = vector1.
x * vector2.
x;
470 result.
r2 = vector1.
x * vector2.
y;
471 result.
r3 = vector1.
x * vector2.
z;
472 result.
r4 = vector1.
y * vector2.
x;
473 result.
r5 = vector1.
y * vector2.
y;
474 result.
r6 = vector1.
y * vector2.
z;
475 result.
r7 = vector1.
z * vector2.
x;
476 result.
r8 = vector1.
z * vector2.
y;
477 result.
r9 = vector1.
z * vector2.
z;
483 vec.
x += vectorToAdd.
x;
484 vec.
y += vectorToAdd.
y;
485 vec.
z += vectorToAdd.
z;
490 vec.
x -= vectorToSubtract.
x;
491 vec.
y -= vectorToSubtract.
y;
492 vec.
z -= vectorToSubtract.
z;
497 result.
x = vector1.
x + vector2.
x;
498 result.
y = vector1.
y + vector2.
y;
499 result.
z = vector1.
z + vector2.
z;
504 result.
x = scalar * vec.
x;
505 result.
y = scalar * vec.
y;
506 result.
z = scalar * vec.
z;
511 result.
r1 = scalar * matrix.
r1;
512 result.
r2 = scalar * matrix.
r2;
513 result.
r3 = scalar * matrix.
r3;
514 result.
r4 = scalar * matrix.
r4;
515 result.
r5 = scalar * matrix.
r5;
516 result.
r6 = scalar * matrix.
r6;
517 result.
r7 = scalar * matrix.
r7;
518 result.
r8 = scalar * matrix.
r8;
519 result.
r9 = scalar * matrix.
r9;
524 result.
x = vector1.
x - vector2.
x;
525 result.
y = vector1.
y - vector2.
y;
526 result.
z = vector1.
z - vector2.
z;
541 MulMatVec(matrix, vec, translation, result);
555 MulMatVec(matrix, vec, translation, result);
561 return vector1.
x * vector2.
x + vector1.
y * vector2.
y + vector1.
z * vector2.
z;
566 const float x = vector1.
y * vector2.
z - vector1.
z * vector2.
y;
567 const float y = vector1.
z * vector2.
x - vector1.
x * vector2.
z;
568 result.
z = vector1.
x * vector2.
y - vector1.
y * vector2.
x;
575 const float length = sqrtf(vec.
x * vec.
x + vec.
y * vec.
y + vec.
z * vec.
z);
587 return sqrtf(vec.
x * vec.
x + vec.
y * vec.
y + vec.
z * vec.
z);
592 return vec.
x * vec.
x + vec.
y * vec.
y + vec.
z * vec.
z;
597 const float x1 = vector1.
x - vector2.
x;
598 const float x2 = vector1.
y - vector2.
y;
599 const float x3 = vector1.
z - vector2.
z;
601 return sqrtf(x1 * x1 + x2 * x2 + x3 * x3);
606 const float x1 = vector1.
x - vector2.
x;
607 const float x2 = vector1.
y - vector2.
y;
608 const float x3 = vector1.
z - vector2.
z;
610 return x1 * x1 + x2 * x2 + x3 * x3;
615 const float sp = vector1.
x * vector2.
x + vector1.
y * vector2.
y + vector1.
z * vector2.
z;
616 const float l1 = sqrtf(vector1.
x * vector1.
x + vector1.
y * vector1.
y + vector1.
z * vector1.
z);
617 const float l2 = sqrtf(vector2.
x * vector2.
x + vector2.
y * vector2.
y + vector2.
z * vector2.
z);
620 float r = sp / (l1 * l2);
621 if (r > 1.0) r = 1.0;
622 if (r < -1.0) r = -1.0;
628 const float t0 = matrix1.
x * matrix2.
r1 + matrix1.
y * matrix2.
r4 + matrix1.
z * matrix2.
r7;
629 const float t1 = matrix1.
x * matrix2.
r2 + matrix1.
y * matrix2.
r5 + matrix1.
z * matrix2.
r8;
630 const float t2 = matrix1.
x * matrix2.
r3 + matrix1.
y * matrix2.
r6 + matrix1.
z * matrix2.
r9;
632 return t0 * matrix1.
x + t1 * matrix1.
y + t2 * matrix1.
z;
639 result.
r1 = matrix.
r1;
640 result.
r5 = matrix.
r5;
641 result.
r9 = matrix.
r9;
644 result.
r4 = matrix.
r2;
648 result.
r3 = matrix.
r7;
652 result.
r6 = matrix.
r8;
659 const float a = matrix.
r1;
660 const float b = matrix.
r2;
661 const float c = matrix.
r3;
662 const float d = matrix.
r4;
663 const float e = matrix.
r5;
664 const float f = matrix.
r6;
665 const float g = matrix.
r7;
666 const float h = matrix.
r8;
667 const float i = matrix.
r9;
669 float det_inverse = 1 / (-c * e * g + b * f * g + c * d * h - a * f * h - b * d * i + a * e * i);
671 result.
r1 = (-f * h + e * i) * det_inverse;
672 result.
r2 = (c * h - b * i) * det_inverse;
673 result.
r3 = (-c * e + b * f) * det_inverse;
674 result.
r4 = (f * g - d * i) * det_inverse;
675 result.
r5 = (-c * g + a * i) * det_inverse;
676 result.
r6 = (c * d - a * f) * det_inverse;
677 result.
r7 = (-e * g + d * h) * det_inverse;
678 result.
r8 = (b * g - a * h) * det_inverse;
679 result.
r9 = (-b * d + a * e) * det_inverse;
684 matrix.
r1 = matrix1.
r1 + matrix2.
r1;
685 matrix.
r2 = matrix1.
r2 + matrix2.
r2;
686 matrix.
r3 = matrix1.
r3 + matrix2.
r3;
687 matrix.
r4 = matrix1.
r4 + matrix2.
r4;
688 matrix.
r5 = matrix1.
r5 + matrix2.
r5;
689 matrix.
r6 = matrix1.
r6 + matrix2.
r6;
690 matrix.
r7 = matrix1.
r7 + matrix2.
r7;
691 matrix.
r8 = matrix1.
r8 + matrix2.
r8;
692 matrix.
r9 = matrix1.
r9 + matrix2.
r9;
697 matrix.
r1 += matrixToAdd.
r1;
698 matrix.
r2 += matrixToAdd.
r2;
699 matrix.
r3 += matrixToAdd.
r3;
700 matrix.
r4 += matrixToAdd.
r4;
701 matrix.
r5 += matrixToAdd.
r5;
702 matrix.
r6 += matrixToAdd.
r6;
703 matrix.
r7 += matrixToAdd.
r7;
704 matrix.
r8 += matrixToAdd.
r8;
705 matrix.
r9 += matrixToAdd.
r9;
710 result.
r1 = matrix1.
r1 - matrix2.
r1;
711 result.
r2 = matrix1.
r2 - matrix2.
r2;
712 result.
r3 = matrix1.
r3 - matrix2.
r3;
713 result.
r4 = matrix1.
r4 - matrix2.
r4;
714 result.
r5 = matrix1.
r5 - matrix2.
r5;
715 result.
r6 = matrix1.
r6 - matrix2.
r6;
716 result.
r7 = matrix1.
r7 - matrix2.
r7;
717 result.
r8 = matrix1.
r8 - matrix2.
r8;
718 result.
r9 = matrix1.
r9 - matrix2.
r9;
723 return matrix.
r1 * matrix.
r5 * matrix.
r9 724 + matrix.
r2 * matrix.
r6 * matrix.
r7 725 + matrix.
r3 * matrix.
r4 * matrix.
r8 726 - matrix.
r3 * matrix.
r5 * matrix.
r7 727 - matrix.
r1 * matrix.
r6 * matrix.
r8 728 - matrix.
r2 * matrix.
r4 * matrix.
r9;
768 v.
x += quat1.
w * quat2.
v.
x + quat1.
w * quat2.
v.
x;
769 v.
y += quat1.
w * quat2.
v.
y + quat1.
w * quat2.
v.
y;
770 v.
z += quat1.
w * quat2.
v.
z + quat1.
w * quat2.
v.
z;
814 const float d = theta;
816 const float v1 = vec.
x;
817 const float v2 = vec.
y;
818 const float v3 = vec.
z;
820 const float t2 = a *
b;
821 const float t3 = a *
c;
822 const float t4 = a * d;
823 const float t5 = -b *
b;
824 const float t6 = b *
c;
825 const float t7 = b * d;
826 const float t8 = -c *
c;
827 const float t9 = c * d;
828 const float t10 = -d * d;
830 result.
x = 2 * ((t8 + t10) * v1 + (t6 - t4) * v2 + (t3 + t7) * v3 ) +
v1;
831 result.
y = 2 * ((t4 + t6) * v1 + (t5 + t10) * v2 + (t9 - t2) * v3 ) +
v2;
832 result.
z = 2 * ((t7 - t3) * v1 + (t2 + t9) * v2 + (t5 + t8) * v3 ) +
v3;
874 const float x = R.
r8 - R.
r6;
875 const float y = R.
r3 - R.
r7;
876 const float z = R.
r4 - R.
r2;
878 const float r = sqrtf(x * x + y * y + z * z);
879 const float t = R.
r1 + R.
r5 + R.
r9;
881 angle = atan2(r, t - 1);
888 result.
x = 0.5f * (vector1.
x + vector2.
x);
889 result.
y = 0.5f * (vector1.
y + vector2.
y);
890 result.
z = 0.5f * (vector1.
z + vector2.
z);
906 float sum_x = 0.0f, sum_y = 0.0f, sum_z = 0.0f;
908 for (
int i = 0; i < nVectors; i++)
910 sum_x += pVectors[i].
x;
911 sum_y += pVectors[i].
y;
912 sum_z += pVectors[i].
z;
915 result.
x = sum_x / float(nVectors);
916 result.
y = sum_y / float(nVectors);
917 result.
z = sum_z / float(nVectors);
void MulVecTransposedVec(const Vec3d &vector1, const Vec3d &vector2, Mat3d &result)
void RotateVec(const Vec3d &vec, const Vec3d &rotation, Vec3d &result)
GLfloat GLfloat GLfloat v2
void SetTransformation(Transformation3d &transformation, const Vec3d &rotation, const Vec3d &translation)
float SquaredLength(const Vec3d &vec)
void CrossProduct(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
void RotateVecQuaternion(const Vec3d &vec, const Vec3d &axis, float theta, Vec3d &result)
void GetAxisAndAngle(const Mat3d &R, Vec3d &axis, float &angle)
void AddToMat(Mat3d &matrix, const Mat3d &matrixToAdd)
static int GetFileSize(FILE *fp)
void RotateVecYZX(const Vec3d &vec, const Vec3d &rotation, Vec3d &result)
void Transpose(const Mat3d &matrix, Mat3d &result)
float ScalarProduct(const Vec3d &vector1, const Vec3d &vector2)
void Average(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
Data structure for the representation of a 3D vector.
void SetRotationMatAxis(Mat3d &matrix, const Vec3d &axis, float theta)
float Length(const Vec3d &vec)
void SetRotationMat(Mat3d &matrix, const Vec3d &axis, float theta)
float ScalarProduct(const Vec2d &vector1, const Vec2d &vector2)
Data structure for the representation of a quaternion.
float Angle(const Vec3d &vector1, const Vec3d &vector2)
void SetVec(Vec3d &vec, float x, float y, float z)
void SetRotationMatZ(Mat3d &matrix, float theta)
void SetRotationMatYZX(Mat3d &matrix, const Vec3d &rotation)
void SetRotationMat(Mat2d &matrix, float angle)
void MulTransVec(const Transformation3d &transformation, const Vec3d &vec, Vec3d &result)
void MulVecScalar(const Vec3d &vec, float scalar, Vec3d &result)
float SquaredDistance(const Vec3d &vector1, const Vec3d &vector2)
void SubtractMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result)
void AddVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
void Invert(const Mat3d &matrix, Mat3d &result)
void MulMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result)
void AddToVec(Vec3d &vec, const Vec3d &vectorToAdd)
void MulMatScalar(const Mat3d &matrix, float scalar, Mat3d &result)
void MulMatVec(const Mat3d &matrix, const Vec3d &vec, Vec3d &result)
float Length(const Vec2d &vec)
void MulMatVec(const CFloatMatrix *pMatrix, const CFloatVector *pVector, CFloatVector *pResultVector)
GLclampf GLclampf GLclampf alpha
GLubyte GLubyte GLubyte a
void TransformVec(const Vec3d &vec, const Vec3d &rotation, const Vec3d &translation, Vec3d &result)
void MulMatMat(const CFloatMatrix *A, const CFloatMatrix *B, CFloatMatrix *pResultMatrix, bool bTransposeB=false)
void MulQuatQuat(const Quaternion &quat1, const Quaternion &quat2, Quaternion &result)
void TransformVecYZX(const Vec3d &vec, const Vec3d &rotation, const Vec3d &translation, Vec3d &result)
GLfloat GLfloat GLfloat GLfloat v3
void AddMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &matrix)
GLenum GLenum GLenum input
void RotateVecAngleAxis(const Vec3d &vec, const Vec3d &axis, float theta, Vec3d &result)
void SetRotationMatY(Mat3d &matrix, float theta)
GLdouble GLdouble GLdouble r
void SubtractFromVec(Vec3d &vec, const Vec3d &vectorToSubtract)
void NormalizeVec(Vec3d &vec)
void Mean(const CVec3dArray &vectorList, Vec3d &result)
GLuint GLsizei GLsizei * length
float EvaluateForm(const Vec3d &matrix1, const Mat3d &matrix2)
void SubtractVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
void SetVec(Vec2d &vec, float x, float y)
float Det(const Mat3d &matrix)
void SetMat(Mat3d &matrix, float r1, float r2, float r3, float r4, float r5, float r6, float r7, float r8, float r9)
const T * GetElements() const
bool LoadFromFile(Vec3d &vector, const char *pFilePath)
void SetRotationMatX(Mat3d &matrix, float theta)
float Distance(const Vec3d &vector1, const Vec3d &vector2)
Data structure for the representation of a 3x3 matrix.
double Mean(CByteImage *pImage1, CByteImage *pImage2)
Deprecated.
void MulTransTrans(const Transformation3d &transformation1, const Transformation3d &transformation2, Transformation3d &result)
bool SaveToFile(const Vec3d &vector, const char *pFilePath)