-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyMathLib.cpp
78 lines (68 loc) · 2.33 KB
/
MyMathLib.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "MyMathLib.h"
double MyMathLib::CalTowPointDistance(Matrix<double, 1, 3> A, Matrix<double, 1, 3> B)
{
return sqrt(pow(A(0, 0) - B(0, 0), 2) + pow(A(0, 1) - B(0, 1), 2) + pow(A(0, 2) - B(0, 2), 2));
}
double MyMathLib::CalTowPointDistance(Point3d A, Point3d B)
{
return sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2) + pow(A.z - B.z, 2));
}
/////点到直线的距离
double MyMathLib::DistanceOfPointToLine(Point3d a, Point3d b, Point3d s)
{
double ab = sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0) + pow(a.z - b.z, 2.0));
double as = sqrt(pow((a.x - s.x), 2.0) + pow((a.y - s.y), 2.0) + pow((a.z - s.z), 2.0));
double bs = sqrt(pow((s.x - b.x), 2.0) + pow((s.y - b.y), 2.0) + pow((s.z - b.z), 2.0));
double cos_A = (pow(as, 2.0) + pow(ab, 2.0) - pow(bs, 2.0)) / (2 * ab * as);
double sin_A = sqrt(1 - pow(cos_A, 2.0));
return as * sin_A;
}
double MyMathLib::MyMax(double i, double j)
{
if (i > j)
return i;
else
return j;
}
long MyMathLib::factorial(long number)
{
if (number <= 1)
return 1;
else
return number * factorial(number - 1);
}
/////Cnm,
int MyMathLib::combinator(int n, int m)
{
int temp;
if (n < m)
{
temp = n;
n = m;
m = temp;
}
return factorial(n) / (factorial(m) * factorial(n - m));
}
void MyMathLib::drawCross(cv::Mat img, cv::Point point, cv::Scalar color, int size, int thickness)
{
//绘制横线
line(img, Point(point.x - size / 2, point.y), Point(point.x + size / 2, point.y), color, thickness, 8, 0);
//绘制竖线
line(img, Point(point.x, point.y - size / 2), Point(point.x, point.y + size / 2), color, thickness, 8, 0);
}
void MyMathLib::CameraInterParaTransfer4x3(Matrix<double, 4, 3> &A, Matrix3d InterParaMat)
{
InterParaMat(0, 0) = 1 / InterParaMat(0, 0);
InterParaMat(1, 1) = 1 / InterParaMat(1, 1);
InterParaMat(0, 2) = -InterParaMat(0, 2) * InterParaMat(0, 0);
InterParaMat(1, 2) = -InterParaMat(1, 2) * InterParaMat(1, 1);
A = (InterParaMat * A.transpose()).transpose();
}
void MyMathLib::PointTransfer1x3(Matrix<double, 1, 3> &A, Matrix3d InterParaMat)
{
InterParaMat(0, 0) = 1 / InterParaMat(0, 0);
InterParaMat(1, 1) = 1 / InterParaMat(1, 1);
InterParaMat(0, 2) = -InterParaMat(0, 2) * InterParaMat(0, 0);
InterParaMat(1, 2) = -InterParaMat(1, 2) * InterParaMat(1, 1);
A = (InterParaMat * A.transpose()).transpose();
}