HyperplaneCoordinateSystem.h
Go to the documentation of this file.
1#ifndef __GfxTL_HYPERPLANECOORDINATESYSTEM_HEADER__
2#define __GfxTL_HYPERPLANECOORDINATESYSTEM_HEADER__
3#include <GfxTL/MathHelper.h>
4#include <GfxTL/VectorXD.h>
5
6namespace GfxTL
7{
8
9 template <class Scalar, unsigned int D>
11 {
12 public:
13 enum
14 {
15 Dim = D,
16 HDim = Dim - 1
17 };
18 };
19
20 template <class ScalarT>
22 {
23 public:
24 enum
25 {
26 Dim = 2,
27 HDim = Dim - 1
28 };
29
30 typedef ScalarT ScalarType;
32
33 template <class V>
34 void
35 FromNormal(const V& v)
36 {
37 m_axis[0][0] = -v[1];
38 m_axis[0][1] = v[0];
39 }
40
42 operator[](unsigned int i)
43 {
44 return m_axis[i];
45 }
46
47 const PointType&
48 operator[](unsigned int i) const
49 {
50 return m_axis[i];
51 }
52
53 private:
54 PointType m_axis[Dim - 1];
55 };
56
57 template <class Scalar>
59 {
60 public:
61 enum
62 {
63 Dim = 3,
64 HDim = Dim - 1
65 };
66
69
71 {
72 for (unsigned int i = 0; i < Dim - 1; ++i)
73 {
74 _axis[i].Zero();
75 }
76 }
77
82
83 template <class V>
88
89 void
94
95 template <class V>
96 void
97 FromNormal(const V& n)
98 {
99 FromNormal(PointType(n[0], n[1], n[2]));
100 }
101
102 void
104 {
105 // perform arbitrary axis algorithm as
106 // specified by AutoCAD
107 if (Math<ScalarType>::Abs(n[0]) < ScalarType(0.015625f) &&
108 Math<ScalarType>::Abs(n[1]) < ScalarType(0.015625f))
109 {
110 _axis[0] = PointType(0, 1, 0) % n;
111 }
112 else
113 {
114 _axis[0] = PointType(0, 0, 1) % n;
115 }
116 _axis[0].Normalize();
117 _axis[1] = n % _axis[0];
118 _axis[1].Normalize();
119 }
120
121 PointType&
122 operator[](unsigned int i)
123 {
124 return _axis[i];
125 }
126
127 const PointType&
128 operator[](unsigned int i) const
129 {
130 return _axis[i];
131 }
132
133 private:
134 PointType _axis[Dim - 1];
135 };
136
137}; // namespace GfxTL
138
139#endif
float Scalar
Definition basic.h:15
const PointType & operator[](unsigned int i) const
const PointType & operator[](unsigned int i) const
HyperplaneCoordinateSystem(ScalarType x, ScalarType y, ScalarType z)
void FromNormal(ScalarType x, ScalarType y, ScalarType z)
static ScalarT Abs(ScalarT s)
Definition MathHelper.h:15
Definition AABox.h:10
This file offers overloads of toIce() and fromIce() functions for STL container types.