versor  3.0
C++11 library for Geometric algebra
vsr_cyclide.h
1 /*
2  * =====================================================================================
3  *
4  * Filename: vsr_cyclide.h
5  *
6  * Description: cyclidic nets
7  *
8  * Version: 1.0
9  * Created: 07/07/2015 12:48:32
10  * Revision: none
11  * Compiler: gcc
12  *
13  * Author: Pablo Colapinto (), gmail->wolftype
14  * Organization: wolftype
15  *
16  * =====================================================================================
17  */
18 
19 #ifndef vsr_cyclide_INC
20 #define vsr_cyclide_INC
21 
22 #include "vsr_cga3D_frame.h"
23 
24 namespace vsr { namespace cga {
25 
26 
28 struct TangentFrame{
29 
30  Frame frame;
33  Pair tan[3];
34  Circle bitan[3];
35 
36  // Calculate Edges as intersections of constant coordinates
37  void calcCurves(){
38  circle[0] = (sphere[1].dual() ^ sphere[2].dual()).dual();
39  circle[1] = (sphere[0].dual() ^ sphere[2].dual()).dual();
40  circle[2] = (sphere[0].dual() ^ sphere[1].dual()).dual();
41  }
42 };
43 
45 struct CyclideQuad{
46 
48 
49  void pos( const Point& a, const Point& b, const Point& c, const Point& d){
50  tframe[0].frame.pos() = a;
51  tframe[1].frame.pos() = b;
52  tframe[2].frame.pos() = c;
53  tframe[3].frame.pos() = d;
54  }
55 
56  Pair mLogU, mLogV;
57  Pair mLogNu, mLogNv;
58 
59  // Calculate frame positions
60  void frame(){
61 
62  //FIRST ONE
63  tframe[0].bitan[0] = tframe[0].frame.tx().dual();
64  tframe[0].bitan[1] = tframe[0].frame.ty().dual();
65  tframe[0].bitan[2] = tframe[0].frame.tz().dual();
66 
67  for (int j=0;j<3;++j){
68  tframe[0].sphere[j] = tframe[0].bitan[j] ^ tframe[1].frame.pos();
69  }
70 
71  // Subsequent
72  for (int i=1;i<4;++i){
73  int next = ( i < 3 ) ? i+1 : 0;
74  for (int j=0;j<3;++j){
75  tframe[i].bitan[j] = Tangent::at( tframe[i-1].sphere[j], tframe[i].frame.pos() );
76  tframe[i].sphere[j] = tframe[i].bitan[j] ^ tframe[next].frame.pos();
77  tframe[i].tan[j] = tframe[i].bitan[j].undual();
78  }
79  }
80 
81  // edges
82  for (int i=0;i<4;++i) tframe[i].calcCurves();
83  }
84 
85  // Which direction to interpolate
86  bool altU(){
87  auto dotU = ( tframe[0].frame.pos() <= tframe[2].sphere[0].dual() )[0];
88  return dotU < 0;
89  }
90 
91  // Which direction to interpolate
92  bool altV(){
93  auto dotV = ( tframe[0].frame.pos() <= tframe[1].sphere[1].dual() )[0];
94  return dotV < 0;
95  }
96 
97  // Calculate logs
98  void log(){
99  mLogU = Gen::log( Gen::ratio(tframe[0].sphere[0].dual(), tframe[2].sphere[0].dual(), true ), altU() );
100  mLogV = Gen::log( Gen::ratio(tframe[3].sphere[1].dual(), tframe[1].sphere[1].dual(), true ), altV() );
101  }
102 
103  void logZ(){
104  mLogNu = Gen::log( Gen::ratio( tframe[0].sphere[2].dual(), tframe[2].sphere[2].dual(),true ), false );
105  mLogNv = Gen::log( Gen::ratio( tframe[3].sphere[2].dual(), tframe[1].sphere[2].dual(),true ), false );
106  }
107 
108 
109  Bst xfu( VSR_PRECISION u ){ return Gen::bst(mLogU * -u ); }
110  Bst xfv( VSR_PRECISION v ){ return Gen::bst(mLogV * -v ); }
111 
112  // Evaluate conformal rotor at u,v
113  Con xf( VSR_PRECISION u, VSR_PRECISION v) { return xfv(v) * xfu(u); }
114 
115  Circle cirU( VSR_PRECISION u) { return tframe[0].circle[1].spin( xfu(u) ); }
116  Circle cirV( VSR_PRECISION v) { return tframe[3].circle[0].spin( xfv(v) ); }
117 
119  template<class T>
120  T apply( const T& t, VSR_PRECISION u, VSR_PRECISION v) {
121  return t.spin( xf(u,v) );
122  }
123 
124  Vec evalNormal( VSR_PRECISION u, VSR_PRECISION v){
125  auto tan = apply( tframe[0].frame.tz(), u,v);
126  return -Round::direction( tan ).copy<Vec>().unit();
127  }
128 
129 
131  Point eval( VSR_PRECISION u, VSR_PRECISION v) {
132  return Round::loc( tframe[0].frame.pos().spin( xf(u,v) ) );
133  }
134 
135 
136 };
137 
138 
139 //experiments with other numbers of frames (six and 3...)
140 struct NCyclide{
141 
142 // tframe[0].frame = control;
143 //
144 // //SET FRAME POSITIONS ALONG CIRCLE
145 // for (int i=0;i<num;++i){
146 // tframe[i].frame.pos() = point( net.cxy(), (float)i/num*TWOPI);
147 // }
148 //
149 // //SET FRAME POSITIONS ALONG CIRCLE
150 // for (int i=0;i<4;++i){
151 // tframe[i].frame.pos() = point( net.cxy(), ((float)i/num + pos[i] )*TWOPI);
152 // }
153 //
154 // //FIRST ONE
155 // tframe[0].bitan[0] = tframe[0].frame.tx().dual();
156 // tframe[0].bitan[1] = tframe[0].frame.ty().dual();
157 // tframe[0].bitan[2] = tframe[0].frame.tz().dual();
158 //
159 // for (int j=0;j<3;++j){
160 // tframe[0].sphere[j] = tframe[0].bitan[j] ^ tframe[1].frame.pos();
161 // }
162 //
163 //
164 // //SUBSEQUENT
165 // for (int i=1;i<num;++i){
166 // int next = ( i < (num-1) ) ? i+1 : 0;
167 // for (int j=0;j<3;++j){
168 // tframe[i].bitan[j] = Tangent::at( tframe[i-1].sphere[j], tframe[i].frame.pos() );
169 // tframe[i].sphere[j] = tframe[i].bitan[j] ^ tframe[next].frame.pos();
170 // tframe[i].tan[j] = tframe[i].bitan[j].undual();
171 // }
172 // }
173 //
174 // for (int i=0;i<num;++i) tframe[i].calcCurves();
175 
176 
177 };
178 
179 
180 }} //vsr::cga::
181 
182 #endif /* ----- #ifndef vsr_cyclide_INC ----- */
static Bst bst(const Pair &p)
vsr::cga::Boost from vsr::cga::Pair
Par tx() const
Null Point Pair in local x direction.
NCon< 5 > Con
ConformalRotor
Definition: vsr_cga3D_types.h:95
static DirectionVector direction(const Pair &p)
Direction of a Pair.
Point eval(VSR_PRECISION u, VSR_PRECISION v)
Apply conformal rotor to a point at u,v.
Definition: vsr_cyclide.h:131
Point pos() const
Get Position.
Definition: vsr_cga3D_frame.h:138
Multivector spin(const MultivectorB< B > &b) const
Rotor (even) transformation \(RA\tilde{R}\)
Definition: vsr_multivector.h:178
Generic Geometric Number Types (templated on an algebra and a basis )
Definition: vsr_algebra.h:69
Circle circle[3]
circle through next point
Definition: vsr_cyclide.h:32
static Point loc(const A &s)
Location (normalizd) of a Round Element (shorthand)
Definition: vsr_cga3D_round.h:146
TangentFrame tframe[4]
– four frames
Definition: vsr_cyclide.h:47
T apply(const T &t, VSR_PRECISION u, VSR_PRECISION v)
Apply conformal rotor to a type T at u,v.
Definition: vsr_cyclide.h:120
NBst< 5 > Bst
Boost
Definition: vsr_cga3D_types.h:94
Cir Circle
Direct Circle 3-blade \(\kappa=p_a \wedge p_b \wedge p_c\)
Definition: vsr_cga3D_types.h:130
static Pair at(const Circle &r, const Point &p)
Tangent Element of A Circle at Point p.
Cylclidic Net (four tangent frames)
Definition: vsr_cyclide.h:45
static Rot ratio(const Vec &v, const Vec &v2)
vsr::cga::Rotor that takes one vec to another
the versor library namespace
Definition: vsr_algebra.h:29
B copy() const
Copying to type B.
Par ty() const
Null Point Pair in local y direction.
static Biv log(const Rot &r)
vsr::cga::Bivector log of vsr::cga::Rotor
Orthonormal Frame composed from a Position and Orientation.
Definition: vsr_cga3D_frame.h:47
Sphere sphere[3]
sphere through next point
Definition: vsr_cyclide.h:31
3D CGA Orthonormal Frame
Frame Tangent to Surface.
Definition: vsr_cyclide.h:28
Pair mLogV
– two bivectors
Definition: vsr_cyclide.h:56
Pair mLogNv
– two more (normals)
Definition: vsr_cyclide.h:57
Par tz() const
Null Point Pair in local z direction.
Definition: vsr_cyclide.h:140