⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isocurve.java

📁 java 作图的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
**                          errors!*/                            count = 0;                            if( bottom ) count++;                            if( top )    count++;                            if( left )   count++;                            if( right )  count++;                            if( count > 2 ) {                                System.out.println("IsoCurve: Pathological Cell");                                System.out.println("          value="+value);                                System.out.println("          i="+i+", j="+j);                                System.out.println("          tl="+tl+", tr="+tr);                                System.out.println("          bl="+bl+", br="+br);		            } else {                                count = 0;                                if( bottom ) { cell.face[count] = BOTTOM; count++; }                                if( top    ) { cell.face[count] = TOP;    count++; }                                if( left   ) { cell.face[count] = LEFT;   count++; }                                if( right  ) { cell.face[count] = RIGHT;  count++; }                            }                    }                                                           }            }	  }              /**   * Traverse the cells and find One connect countour.   */      protected void getcurve() {            Cell current;            int face = TERMINAL;            int ifcell = -1;            int jfcell = -1;            int icell,jcell;            double bl, br, tl, tr;            int index;            int i;            double d[] = new double[2];                             size = 0;            //System.out.println("getcurve: Number of cells "+cells.size());            if( cells == null || cells.isEmpty() ) return;                        current = (Cell)(cells.firstElement());            if(current.face[0] == TERMINAL && current.face[1] == TERMINAL) {                cells.removeElement(current);                System.out.println("getcurve: Terminal cell removed!");                return;            }/***          Calculate the first point in the new curve*/            icell = current.i;            jcell = current.j;                        ifcell = -1;            jfcell = -1;/***          Check to see if we can loop back on ourselves. ie we have partially**          resolved this curve or we are against a wall.**          Use the terminating wall to start the curve.*/            if( search(icell-1,jcell) == null &&                 ( current.face[0] == LEFT || current.face[1] == LEFT ) ) {                                    	 addDataPoint(LEFT,icell,jcell);                     face = LEFT;                                 } else            if( search(icell+1,jcell) == null &&                 ( current.face[0] == RIGHT || current.face[1] == RIGHT ) ) {                                         addDataPoint(RIGHT,icell,jcell);                     face = RIGHT;            } else            if( search(icell,jcell-nx) == null &&                 ( current.face[0] == BOTTOM || current.face[1] == BOTTOM ) ) {                                         addDataPoint(BOTTOM,icell,jcell);                     face = BOTTOM;                                 } else            if( search(icell,jcell+nx) == null &&                 ( current.face[0] == TOP || current.face[1] == TOP ) ) {                     addDataPoint(TOP,icell,jcell);                     face = TOP;            } else {            	/***          No terminating wall so it does not matter where we start as**          long as it is not a terminal face. Remember the position**          of the cell behind us just in case we loop back as the curve**          must be closed.*/                index = 0;                if( current.face[0] == TERMINAL ) index = 1;                                addDataPoint(current.face[index],icell,jcell);                face = current.face[index];                                if( face == TOP ) {                     ifcell = current.i;                     jfcell = current.j+1;                } else                 if( face == BOTTOM ) {                     ifcell = current.i;                     jfcell = current.j-1;                } else                 if( face == LEFT ) {                     ifcell = current.i-1;                     jfcell = current.j;                } else                 if( face == RIGHT ) {                     ifcell = current.i+1;                     jfcell = current.j;               }            }                        while( current != null ) {                               icell = current.i;               jcell = current.j;                              if( current.face[0] == face )  face = current.face[1];               else                           face = current.face[0];                                         if(face != TERMINAL) addDataPoint(face,icell,jcell);                              if(face == TOP ) {                     jcell++;                     face = BOTTOM;                } else               if(face == BOTTOM ) {                     jcell--;                     face = TOP;                } else               if(face == LEFT ) {                     icell--;                     face = RIGHT;                } else               if(face == RIGHT ) {                     icell++;                     face = LEFT;                }                                cells.removeElement(current);                if( icell == ifcell && jcell == jfcell ) {                     addDataPoint(curve[0], curve[1]);                     current = null;                } else {                     current = search(icell,jcell);                }            }     }  /**   * Return the (x,y) position where the contour cross the cell wall.   * @param wall The cell wall the contour crosses.   * @param icell The x index of the cell position.   * @param jcell The y index of the cell position.   */     protected double[] getPoint(int wall, int icell, int jcell)  {     	double d[] = new double[2];        double bl, br, tl, tr;        int index = icell + jcell*nx;                if(wall == TOP ) {                     tl = grid[index+nx];                     tr = grid[index+nx+1];                     d[1] = (double)(jcell+1);                     d[0] = (double)icell + (value-tl)/(tr-tl);         } else         if(wall == BOTTOM ) {                     bl = grid[index];                     br = grid[index+1];                     d[1] = (double)jcell;                     d[0] = (double)icell + (value-bl)/(br-bl);         } else         if(wall == LEFT ) {                     bl = grid[index];                     tl = grid[index+nx];                     d[1] = (double)jcell + (value-bl)/(tl-bl);                     d[0] = (double)icell;         } else         if(wall == RIGHT ) {                     br = grid[index+1];                     tr = grid[index+1+nx];                     d[1] = (double)jcell + (value-br)/(tr-br);                     d[0] = (double)(icell + 1);         }     	         return  d;         }           /**   * Add a data point to the contour curve.   * @param wall The cell wall the contour crosses.   * @param icell The x index of the cell position.   * @param jcell The y index of the cell position.   */      protected void addDataPoint(int wall, int icell, int jcell)  {     	  double d[];     	       	  d = getPoint(wall,icell,jcell);     	       	  addDataPoint(d[0], d[1]);     }                /**   * Add a data point to the contour curve.   * @param x The x position of the point.   * @param y The y position of the point.   */      protected void addDataPoint(double x,double y) {            if(size >= MAXARRAYSIZE-2) return;            if( curve == null)  {            	curve = new double[ARRAYSIZE];            } else            if(size == curve.length-2 ) {               double tmp[] = new double[2*size];               System.arraycopy(curve,0,tmp,0,size);               curve = tmp;            }                        curve[size] = x;            size++;            curve[size] = y;            size++;     }  /**   * Search for a cell in the contour cell list   * @param icell the x index of the cell   * @param jcell the y index of the cell   */     protected Cell search(int icell, int jcell) {           int i;           Cell current = null;                      if( cells.isEmpty() ) return null;                      for(i=0; i<cells.size(); i++) {               current = (Cell)(cells.elementAt(i));                              if(current.i == icell && current.j == jcell) return current;           }                      return null;          }}/*** This class is a structure class holding information about the* cells that the contour line passes through. Used only with IsoCurve class*/class Cell extends Object {        int i;        int j;        int face[] = new int[2];        boolean visited;        public Cell() {                       i = -1;                       j = -1;                       face[0] = IsoCurve.TERMINAL;                       face[1] = IsoCurve.TERMINAL;		     }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -