Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / tin / smoothTinBezier / Bezier.java @ 59

History | View | Annotate | Download (4.75 KB)

1
/**
2
 *    @author              Josef Bezdek, ZCU Plzen
3
 *          @version             1.0
4
 *    @since                 JDK1.5
5
 */
6

    
7
package es.unex.sextante.tin.smoothTinBezier;
8

    
9
import java.awt.geom.GeneralPath;
10

    
11
import com.vividsolutions.jts.geom.Coordinate;
12

    
13
public class Bezier {
14

    
15
   Coordinate  b300;
16
   Coordinate  b030;
17
   Coordinate  b003;
18
   Coordinate  b012         = null;
19
   Coordinate  b021         = null;
20
   Coordinate  b102         = null;
21
   Coordinate  b120         = null;
22
   Coordinate  b210         = null;
23
   Coordinate  b201         = null;
24
   Coordinate  b111         = null;
25
   GeneralPath trianglePath = new GeneralPath();
26

    
27

    
28
   /******************************************************************************************************************************
29
    * Constructor
30
    * 
31
    * @param bxxx -
32
    *                control points of control mesh
33
    */
34
   protected Bezier(final Coordinate b300,
35
                    final Coordinate b030,
36
                    final Coordinate b003,
37
                    final Coordinate b210,
38
                    final Coordinate b120,
39
                    final Coordinate b021,
40
                    final Coordinate b012,
41
                    final Coordinate b102,
42
                    final Coordinate b201,
43
                    final Coordinate b111) {
44
      this.b300 = b300;
45
      this.b030 = b030;
46
      this.b003 = b003;
47
      this.b012 = b012;
48
      this.b021 = b021;
49
      this.b102 = b102;
50
      this.b120 = b120;
51
      this.b210 = b210;
52
      this.b201 = b201;
53
      this.b111 = b111;
54
      trianglePath.moveTo((float) b300.x, (float) b300.y);
55
      trianglePath.lineTo((float) b030.x, (float) b030.y);
56
      trianglePath.lineTo((float) b003.x, (float) b003.y);
57
      trianglePath.lineTo((float) b300.x, (float) b300.y);
58
      trianglePath.closePath();
59

    
60
   }
61

    
62

    
63
   /******************************************************************************************************************************
64
    * Protected method for counting elevation of triangle's point with coordinates u,v
65
    * 
66
    * @param u -
67
    *                barycentric koeficient u
68
    * @param v -
69
    *                barycentric koeficient v
70
    * @return new point
71
    */
72
   protected Coordinate getElevation(final double u,
73
                                     final double v,
74
                                     final double scaleZ) {
75
      final double w = 1 - u - v;
76
      final double x = b300.x * Math.pow(w, 3) + b030.x * Math.pow(u, 3) + b003.x * Math.pow(v, 3) + 3 * b210.x * Math.pow(w, 2)
77
                       * u + 3 * b120.x * Math.pow(u, 2) * w + 3 * b201.x * Math.pow(w, 2) * v + 3 * b021.x * Math.pow(u, 2) * v
78
                       + 3 * b102.x * Math.pow(v, 2) * w + 3 * b012.x * u * Math.pow(v, 2) + 6 * b111.x * u * v * w;
79

    
80
      final double y = b300.y * Math.pow(w, 3) + b030.y * Math.pow(u, 3) + b003.y * Math.pow(v, 3) + 3 * b210.y * Math.pow(w, 2)
81
                       * u + 3 * b120.y * Math.pow(u, 2) * w + 3 * b201.y * Math.pow(w, 2) * v + 3 * b021.y * Math.pow(u, 2) * v
82
                       + 3 * b102.y * Math.pow(v, 2) * w + 3 * b012.y * u * Math.pow(v, 2) + 6 * b111.y * u * v * w;
83

    
84
      final double z = (b300.z * Math.pow(w, 3) + b030.z * Math.pow(u, 3) + b003.z * Math.pow(v, 3) + 3 * b210.z * Math.pow(w, 2)
85
                        * u + 3 * b120.z * Math.pow(u, 2) * w + 3 * b201.z * Math.pow(w, 2) * v + 3 * b021.z * Math.pow(u, 2) * v
86
                        + 3 * b102.z * Math.pow(v, 2) * w + 3 * b012.z * u * Math.pow(v, 2) + 6 * b111.z * u * v * w)
87
                       * scaleZ;
88

    
89
      return new Coordinate(x, y, z);
90
   }
91

    
92

    
93
   protected void printToConsole() {
94
      System.out.println("======================================");
95
      System.out.println(b300.toString());
96
      System.out.println(b030.toString());
97
      System.out.println(b003.toString());
98
      System.out.println("Normals:");
99

    
100
      System.out.println(b210.toString());
101
      System.out.println(b120.toString());
102
      System.out.println(b021.toString());
103
      System.out.println(b012.toString());
104
      System.out.println(b102.toString());
105
      System.out.println(b201.toString());
106
      System.out.println(b111.toString());
107

    
108
      System.out.println("======================================");
109
   }
110

    
111

    
112
   /******************************************************************************************************************************
113
    * The method which testing, if the triangle contains the point
114
    * 
115
    * @param P -
116
    *                point which will be tested
117
    * 
118
    * @return boolean true - the triangle contains the point false - the triangle doesn't contains point
119
    * 
120
    */
121

    
122
   public boolean contains(final Coordinate P) {
123
      return trianglePath.contains(P.x, P.y);
124
   }
125

    
126
}