-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vectornt.cpp
144 lines (123 loc) · 2.7 KB
/
Vectornt.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*********************************************************************************
*Copyright(C) 2013-2016 Qingan Yan (yanqinganssg (at) gmail.com or yanqingan (at) whu.edu.cn)
*Author: Qingan Yan
*Version: v15.2
*Date: Sep-10-2015
*Description: This program is used to display point clouds from .out and .ply file format,
which is the output of Bundler.
*Notice: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation.
*For more information, please view my homepage at https://yanqingan.github.io
**********************************************************************************/
#include <math.h>
#include "Vectornt.h"
//Vectornt::Vectornt()
//{
//}
Vector2f::Vector2f(float x, float y)
{
this->x = x;
this->y = y;
}
void Vector2f::operator =(const Vector2f ve)
{
x = ve.x;
y = ve.y;
}
Vector2f Vector2f::operator -(const Vector2f ve)
{
Vector2f temp;
temp.x = x - ve.x;
temp.y = y - ve.y;
return temp;
}
Vector2f Vector2f::operator +(const Vector2f ve)
{
Vector2f temp;
temp.x = x + ve.x;
temp.y = y + ve.y;
return temp;
}
Vector3f::Vector3f(float x, float y, float z)
{
this->x = x;
this->y = y;
this->z = z;
}
void Vector3f::operator =(const Vector3f ve)
{
x = ve.x;
y = ve.y;
z = ve.z;
}
Vector3f Vector3f::operator -(const Vector3f ve)
{
Vector3f temp;
temp.x = x - ve.x;
temp.y = y - ve.y;
temp.z = z - ve.z;
return temp;
}
Vector3f Vector3f::operator +(const Vector3f ve)
{
Vector3f temp;
temp.x = x + ve.x;
temp.y = y + ve.y;
temp.z = z + ve.z;
return temp;
}
Vector3f Vector3f::CrossProduct(const Vector3f ve)
{
Vector3f temp;
temp.x = y * ve.z - z * ve.y;
temp.y = z * ve.x - x * ve.z;
temp.z = x * ve.y - y * ve.x;
//temp.Normalize();
return temp;
}
float Vector3f::DotProduct(const Vector3f ve)
{
float temp;
temp = x * ve.x + y * ve.y + z * ve.z;
return temp;
}
void Vector3f::Normalize()
{
float sum = 1.0 / (x * x + y * y + z * z);
x *= sum;
y *= sum;
z *= sum;
}
float Vector3f::Norm_2()
{
return (x * x + y * y + z * z);
}
Vector3i::Vector3i(int x, int y, int z)
{
this->x = x;
this->y = y;
this->z = z;
}
void Vector3i::operator =(const Vector3i ve)
{
x = ve.x;
y = ve.y;
z = ve.z;
}
Vector3i Vector3i::operator -(const Vector3i ve)
{
Vector3i temp;
temp.x = x - ve.x;
temp.y = y - ve.y;
temp.z = z - ve.z;
return temp;
}
Vector3i Vector3i::operator +(const Vector3i ve)
{
Vector3i temp;
temp.x = x + ve.x;
temp.y = y + ve.y;
temp.z = z + ve.z;
return temp;
}