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

📄 isocurve.java

📁 java 作图的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package graph;import java.awt.*;import java.util.*;import java.lang.*;/*******************************************************************************    Class  IsoCurve            ******************************************************************************    Copyright (C) 1996 Leigh Brookshaw****    This program is free software; you can redistribute it and/or modify**    it under the terms of the GNU General Public License as published by**    the Free Software Foundation; either version 2 of the License, or**    (at your option) any later version.****    This program is distributed in the hope that it will be useful,**    but WITHOUT ANY WARRANTY; without even the implied warranty of**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the**    GNU General Public License for more details.****    You should have received a copy of the GNU General Public License**    along with this program; if not, write to the Free Software**    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.******************************************************************************    This class will calculate the curve of a given value passing**    through a grid of values***************************************************************************//** * This class will calculate the constant curve of a given value passing * through a grid of values. * * @version $Revision: 1.6 $, $Date: 1996/07/30 04:52:40 $. * @author Leigh Brookshaw */public class IsoCurve extends Object {/********************** Constants******************/  /**   *  Flag a cell face as a terminal face ie the curve terminates here.   */     static final int TERMINAL  = 0;  /**   *  Flag a cell as having the curve coming through its Left face   */     static final int LEFT      = 1;  /**   *  Flag a cell as having the curve coming through its Right face   */     static final int RIGHT     = 2;  /**   *  Flag a cell as having the curve coming through its Top face   */     static final int TOP       = 3;  /**   *  Flag a cell as having the curve coming through its Bottom face   */     static final int BOTTOM    = 4;  /**   *   Initial size of the array that will hold a contour.   */     static final int ARRAYSIZE    = 100;  /**   *   Maximum size of the array that will hold a contour.   */     static final int MAXARRAYSIZE = 2000;     /******************** Variables****************/  /**   *   Vector of cells that the contour passes through.   */     protected Vector cells;  /**   *   Array holding the data grid.   */     protected double grid[];  /**   *   X Dimension of data grid   */     protected int nx;  /**   *   Y Dimension of data grid   */     protected int ny;  /**   *   Array that holds the points of the contour   */     protected double curve[];  /**   *   Number of points in the contour   */     protected int  size;  /**   *   Contour value to be found   */     protected double value;     /********************** Constructors******************/  /**   * Instantiate the class and initialize all the variables   */     public IsoCurve() {            cells = null;            grid = null;            nx = 0;            ny = 0;            curve = null;            size = 0;            value = 0.0;     }       /**   * Instantiate the class and initialize all the variables.   * @param grid An nx by ny Array containing the grid to contour   * @param nx   X dimension of the grid.   * @param ny   Y dimension of the grid.   */     public IsoCurve(double grid[], int nx, int ny) {        this();     	setGrid(grid,nx,ny);     }     /*********************** Public Methods*******************/  /**   * Set the grid to be contoured   * @param nx   X dimension of the grid.   * @param ny   Y dimension of the grid.   */     public void setGrid(double grid[], int nx, int ny) {           this.grid = grid;           this.nx   = nx;           this.ny   = ny;     }  /**   * Set the value to contour   * @param value the contour level   */      public void setValue(double value) {            this.value = value;                        if( grid == null) return;            //System.out.println("setValue called:" + value);                        createCells();     }  /**   * Return a contour curve. If null   * is returned it means that all the contour curves have been found.   * @return The array containing the (x,y) pairs of the contour curve.   */     public double[] getCurve() {           size = 0;           getcurve();                      if( size == 0 || curve == null ) {                    //System.out.println("getCurve: Nothing found");                    return null;		  }                      double tmp[] = new double[size];                      System.arraycopy(curve,0,tmp,0,size);           return tmp;     }     /*************************** Protected Methods***********************/  /**   * Create the vector of all cells that contain the contour.   */         protected void createCells() {            double bl, br, tl, tr;            boolean bottom, top, right, left;            Cell cell;            int jcell, icell;                        int i, j, count;                 if(cells == null)    cells = new Vector();            else                 cells.removeAllElements();                                    for(j=0; j<ny-1; j++) {                                jcell = j*nx;                                  for(i=0; i<nx-1; i++) {                                icell = i + jcell;                                      bl = grid[icell];                   br = grid[icell+1];                   tl = grid[icell+nx];                   tr = grid[icell+nx+1];                                      bottom = false;                   top    = false;                   left   = false;                   right  = false;                                      if( (bl-value)*(br-value) <= 0.0 )  bottom = true;                   if( (br-value)*(tr-value) <= 0.0 )  right  = true;                   if( (tr-value)*(tl-value) <= 0.0 )  top    = true;                   if( (tl-value)*(bl-value) <= 0.0 )  left   = true;                                      if( top && bottom && left && right ) {                                         if( tr >= tl && bl >= br ) {                                                  cell = new Cell();                            cell.i = i;                            cell.j = j;                            cell.face[0] = TOP;                            cell.face[1] = LEFT;                            cells.addElement(cell);                                                   cell = new Cell();                            cell.i = i;                            cell.j = j;                            cell.face[0] = BOTTOM;                            cell.face[1] = RIGHT;                            cells.addElement(cell);                                                } else                      if ( tl >= tr && br >= bl ) {                                               cell = new Cell();                            cell.i = i;                            cell.j = j;                            cell.face[0] = TOP;                            cell.face[1] = LEFT;                            cells.addElement(cell);                                                   cell = new Cell();                            cell.i = i;                            cell.j = j;                            cell.face[0] = BOTTOM;                            cell.face[1] = RIGHT;                                                  }                   } else                    if( top || bottom || left || right ) {                            cell = new Cell();                            cells.addElement(cell);                            cell.i = i;                            cell.j = j;                            if( bl == value && br == value) bottom = false;                            if( bl == value && tl == value) left   = false;                            if( tr == value && tl == value) top    = false;                            if( tr == value && br == value) right  = false;/***                          Check for pathological cell and to avoid out of bounds

⌨️ 快捷键说明

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