-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeom.cpp
80 lines (73 loc) · 1.94 KB
/
geom.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
/*
* geom.cpp
*
* Created on: Feb 26, 2018
* Author: graffy
*/
#include <iostream>
#include "geom.hpp"
namespace scefig
{
void Geom::cropPlaneByAabb(const scefig::Plane & plane, const scefig::AxisAlignedBoundingBox & aabb, scefig::PolyLine & polyLine)
{
const Vector3 & planeNormal = plane.getNormal();
int iMostSignifAxis;
planeNormal.maxCoeff(&iMostSignifAxis); // argmax
/*
# if x is the most significant axis :
# | x1 | = | 1 1 1 | | -b | / a
# | x2 | | -1 1 1 | | -c |
# | x3 | | -1 -1 1 | | -d |
# | x4 | | 1 -1 1 |
# if y is the most significant axis :
# | y1 | = | 1 1 1 | | -c | / b
# | y2 | | -1 1 1 | | -d |
# | y3 | | -1 -1 1 | | -a |
# | y4 | | 1 -1 1 |
# if z is the most significant axis :
# | z1 | = | 1 1 1 | | -d | / c
# | z2 | | -1 1 1 | | -a |
# | z3 | | -1 -1 1 | | -b |
# | z4 | | 1 -1 1 |
*/
// Y = X A
//MatrixXf a(2,3); a << 1, 2, 3, 4, 5, 6;
Eigen::MatrixXf X(4,3);
X << 1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
-1.0,-1.0, 1.0,
1.0,-1.0, 1.0;
Vector3 A;
int j = (iMostSignifAxis + 1) % 4;
for( int i = 0; i<3; ++i)
{
A[i] = plane.getParams()[j] / plane.getParams()[iMostSignifAxis];
j = (j + 1) % 4;
}
Vector4 Y = X * A;
//print(Y)
for( int iVertex = 0 ; iVertex < 4; ++iVertex)
{
Vector3 vertex;
vertex[iMostSignifAxis] = Y[iVertex];
for(int iAxis = 0; iAxis < 2; ++iAxis)
{
vertex[(iMostSignifAxis+iAxis+1)%3] = X(iVertex,iAxis);
}
//print(vertex)
polyLine.appendVertex(vertex);
}
/*
#if iMostSignifAxis == 0:
# ax +by +cz +d = 0
# x = (-d -by -cz)/a
#elif iMostSignifAxis == 1:
# ax +by +cz +d = 0
# y = (-d -ax -cz)/b
#polyLine.appendVertex( numpy.array([1.0, 2.0, 3.0]) )
#polyLine.appendVertex( numpy.array([2.0, 3.0, 0.0]) )
#polyLine.appendVertex( numpy.array([4.0, 5.0, 6.0]) )
*/
polyLine.setClosedness(true);
}
} /* namespace scefig */