-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHyperPlane.cpp
61 lines (53 loc) · 1.24 KB
/
HyperPlane.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
#include "StdAfx.h"
#include "HyperPlane.h"
HyperPlane::HyperPlane(float A, float B, float C, float D, float E) :
mNormal(A, B, C, D)
{
float norm = mNormal.length();
assert(norm != 0.);
mRho = E / norm;
mNormal.normalise();
}
HyperPlane::HyperPlane(const Vector4f &normal, float rho) :
mNormal(normal)
{
float norm = mNormal.length();
assert(norm != 0.);
mRho = rho / norm;
mNormal.normalise();
}
HyperPlane::~HyperPlane(void)
{
}
float HyperPlane::Distance(const Vector4f &point) const
{
return std::fabsf(mNormal * point + mRho);
}
float HyperPlane::Value(const Vector4f &point) const
{
return mNormal * point + mRho;
}
// Íàõîæäåíèå òî÷êè ïåðåñå÷åíèÿ îòðåçêà è ãèïåðïëîñêîñòè
HyperPlane::IntersectionType HyperPlane::Intersection(
const Vector4f &point1, const Vector4f &point2,
Vector4f &result_point) const
{
float v1 = Value(point1);
float v2 = Value(point2);
if (v1 == 0.0 && v2 == 0.0)
return IST_LINE;
if (v1 * v2 > 0.0)
return IST_NONE;
if (v1 == 0.0)
{
result_point = point1;
return IST_VERTEX;
}
if (v2 == 0.0)
{
result_point = point2;
return IST_VERTEX;
}
result_point = point2 * (v1 / (v1 - v2)) - point1 * (v2 / (v1 - v2));
return IST_POINT;
}