-
Notifications
You must be signed in to change notification settings - Fork 0
/
division_plane.cpp
38 lines (32 loc) · 919 Bytes
/
division_plane.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
#include "division_plane.h"
DivisionPlane::DivisionPlane() :
point(),
normal(),
mirror_precalc()
{
}
DivisionPlane::DivisionPlane(boost::numeric::ublas::vector<double> point_,
boost::numeric::ublas::vector<double> vector_) :
point(point_),
normal(vector_),
mirror_precalc()
{
precalc();
}
double DivisionPlane::rate(const boost::numeric::ublas::vector<double>& vec) const {
using namespace boost::numeric::ublas;
return inner_prod(vec - point, normal);
}
bool DivisionPlane::mirror(boost::numeric::ublas::vector<double> &vec, bool positive) const {
using namespace boost::numeric::ublas;
double rating = rate(vec);
if (positive == (rating < 0)) {
vec += rating * mirror_precalc;
return true;
}
return false;
}
void DivisionPlane::precalc() {
using namespace boost::numeric::ublas;
mirror_precalc = (-2 / inner_prod(normal, normal)) * normal;
}