~seh999/jcog/proto3

« back to all changes in this revision

Viewing changes to spacetime/src.tutorial/opencog/spacetime/tutorial/projects/ksurfaces/KSurfaces.java

  • Committer: SeH
  • Date: 2009-09-19 22:59:48 UTC
  • Revision ID: seh999@gmail.com-20090919225948-q3ab80xa57i74mm6
start of major jReality refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package opencog.spacetime.tutorial.projects.ksurfaces;
2
 
 
3
 
 
4
 
/**  The algorithms to generate the Gauss map of a K-surface and the surface. The arrays are in xt--coordinates, 
5
 
 * where the first index is time t and the second is the position x.  
6
 
 * 
7
 
 * @author Ulrich Pinkall, adapted for the tutorial by G. Paul Peters, 24.07.2009
8
 
 * @see Ulrich Pinkall: "Designing Cylinders with Constant Negative Curvature", in 
9
 
 * Discrete Differential Geometry, pages 57-66. Springer 2008.
10
 
 *
11
 
 */
12
 
public class KSurfaces {
13
 
        /** Computes the Gauss map of a K-surface from initial Cauchy data, i.e., two closed curves. Assums that the points of
14
 
         * the initial data lie on the 2-sphere this method generates more points so that the quadrilaterals 
15
 
         * (i-1,j-1), (i-1,j), (i,j),(i-2,j-1) form spherical parallelograms. 
16
 
         * 
17
 
         * @param initialAnnulus the initial data, i.e., a double array double[2][n][3] containing 2 polygons with n vertices,
18
 
         *  which are both interpreted as closed curves connecting that last and the first one. 
19
 
         * @param target a double array that will be filled with the result, i.e., an array double[m][n][3], where m>1 is the number of
20
 
         *      time steps to be calculated.
21
 
         */
22
 
        public static void gaussMapFromInitialAnnulus(double[][][] initialAnnulus, double[][][] target) {
23
 
                final int m = target.length;
24
 
                final int n = target[0].length;
25
 
                final double[] a = new double[3];
26
 
                
27
 
                // copy first two rows
28
 
                for (int i=0; i<2; i++) {
29
 
                        for (int j=0; j<n; j++) {
30
 
                                R3.copy(initialAnnulus[i][j], target[i][j]);
31
 
                        }
32
 
                }
33
 
                
34
 
                // compute the other rows
35
 
                for (int i=2; i<m; i++) {
36
 
                        for (int j=0; j<n; j++) {
37
 
                                int k = j==0 ? n-1 : j-1;
38
 
                                R3.plus(target[i-1][k], target[i-1][j], a);
39
 
                                double[] w = target[i-2][k];
40
 
                                double s = 2 * R3.dot(a,w) / R3.dot(a,a);
41
 
                                R3.times(s, a, a);
42
 
                                R3.minus(a, w, target[i][j]);
43
 
                        }
44
 
                }
45
 
        }
46
 
        
47
 
        /** Calculates the K-surface from the given Gauss map, assuming that the Gauss map consists
48
 
         * of spherical parallelograms as described in {@link #gaussMapFromInitialAnnulus(double[][][], double[][][])}. 
49
 
         * 
50
 
         * @param gaussMap the given Gauss map.
51
 
         * @param target a double array with enough space to hold the resulting surface. A quad mesh where the
52
 
         * quadrilaterals consist of (i-1,j-1), (i-1,j), (i,j),(i-2,j-1).
53
 
         */
54
 
        public static void kSurfaceFromGaussMap(double[][][] gaussMap, double[][][] target) {
55
 
                final int m = gaussMap.length;
56
 
                final int n = gaussMap[0].length;
57
 
                final double[] a = new double[3];
58
 
 
59
 
                // compute first row
60
 
                R3.zero(target[0][0]);
61
 
                for (int j=0; j<n-1; j++) {
62
 
                        int k = (j+1)%n;
63
 
                        R3.plus(gaussMap[0][j], gaussMap[0][k], a);
64
 
                        R3.cross(gaussMap[1][k], a, a);
65
 
                        R3.plus(target[0][j], a, target[0][k]);
66
 
                }
67
 
                        
68
 
                // compute the other rows
69
 
                for (int i=1; i<m; i++) {
70
 
                        for (int j=0; j<n; j++) {
71
 
                                R3.cross(gaussMap[i-1][j], gaussMap[i][j], a);
72
 
                                R3.plus(target[i-1][j], a, target[i][j]);
73
 
                        }
74
 
                }
75
 
        }
76
 
}