-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImagePoint.cpp
More file actions
66 lines (54 loc) · 1.83 KB
/
ImagePoint.cpp
File metadata and controls
66 lines (54 loc) · 1.83 KB
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
#include "PJLib.h"
namespace PJLib
{
ImagePoint::ImagePoint(double row, double col)
{
this->row = row;
this->col = col;
}
double ImagePoint::DistanceTo(ImagePoint p)
{
return sqrt(pow(p.row - this->row, 2) + pow(p.col - this->col, 2));
}
ImagePoint ImagePoint::MidPoint(ImagePoint p)
{
double row = (this->row + p.row) / 2;
double col = (this->col + p.col) / 2;
return ImagePoint(row, col);
}
/* Angles */
double ImagePoint::AngleXAxisInRadians(ImagePoint p)
{
return atan((this->row - p.row) / (p.col - this->col));
}
double ImagePoint::AngleYAxisInRadians(ImagePoint p)
{
return (PI/2 - atan((this->row - p.row) / (p.col - this->col)));
}
/* Transformations and transpositions */
ImagePoint ImagePoint::TransformPoint(double phi, double length)
{
return ImagePoint(this->row + sin(phi) * length, this->col - cos(phi) * length);
}
ImagePoint ImagePoint::TransposePoint(ImagePoint newCenterPoint, double angle)
{
ImagePoint pointInOld = ImagePoint(this->row, this->col);
double row, col, rowHelp, colHelp;
/* Translation */
colHelp = pointInOld.col - newCenterPoint.col;
rowHelp = pointInOld.row - newCenterPoint.row;
/* Rotation */
col = colHelp * cos(angle) - rowHelp * sin(angle);
row = colHelp * sin(angle) + rowHelp * cos(angle);
return ImagePoint(row, col);
}
/* Operators */
ImagePoint ImagePoint::operator -(ImagePoint b)
{
return ImagePoint(this->row - b.row, this->col - b.col);
}
ImagePoint ImagePoint::operator +(ImagePoint b)
{
return ImagePoint(this->row + b.row, this->col + b.col);
}
}