chiark / gitweb /
cin.get(buf,100,'\n') fails on blank lines nowadays, bah - use getline
[moebius.git] / moebius.cc
index 148ce0c3da9c34772abc28d1a1a59f0d685438dd..f169ab52520866f81c40703ce1c87dab3255504d 100644 (file)
@@ -46,7 +46,7 @@ void Bezier::debug() {
 // The first end is oriented towards [0,cos(theta),sin(theta)]
 // The second end is oriented towards [0,-1,0]
 
-Point MoebiusEnfoldment::edgepoint(double t) {
+Point MoebiusEnfoldmentAny::edgepoint(double t) {
   double theta= t*2.0*M_PI;
   return Point(sin(theta),cos(theta),0);
 }
@@ -74,3 +74,37 @@ Point MoebiusEnfoldment::middlepoint(double t, double u) {
     return Point( bx(t), by(t), thickness * bz(t) );
   }
 }    
+
+Point MoebiusEnfoldmentNew::middlepoint(double t, double u) {
+  if (u <= 0.5) {
+    if (t <= 0.5) {
+      double sin_pi_t= sin(M_PI*t);
+      double cos_pi_t= cos(M_PI*t);
+      double sin_2pi_t= sin(2.0*M_PI*t);
+      double cos_2pi_t= cos(2.0*M_PI*t);
+
+      double prop_circ= 0.5+0.5*cos(2.0*M_PI*u);
+      //      double prop_circ= 1.0-2.0*u;
+
+      Point p_edge(-sin_pi_t,cos_pi_t,0);
+
+      double alpha_circ= (2.0*M_PI)*(2.0*t)*(2.0*u);
+      Point v_edge1(cos_2pi_t*sin_pi_t,-cos_2pi_t*cos_pi_t,sin_2pi_t);
+      Point v_edge2(sin_2pi_t*cos_pi_t,-sin_2pi_t*sin_pi_t,-cos_2pi_t);
+      Point p_circ_cent= p_edge + v_edge2*(2.0*t);
+      Point p_circ_pt= p_circ_cent + (v_edge1*sin(alpha_circ) + v_edge2*-cos(alpha_circ))*(2.0*t);
+      p_circ_pt[1]= p_edge[1];
+
+      Point v_line(-cos_pi_t,0,sin_pi_t);
+      Point p_line_start(0,1.0-2.0*t,0);
+      Point p_line_pt= p_line_start + v_line*(1.0-2.0*u)*(M_PI*t);
+
+      return p_circ_pt*prop_circ + p_line_pt*(1.0-prop_circ);
+    } else {
+      return middlepoint(0.5,u) + Point(0,0.5-t,0);
+    }
+  } else {
+    Point p_mirror= middlepoint(t,1.0-u);
+    return Point(-p_mirror[0], p_mirror[1], -p_mirror[2]);
+  }
+}