/* * InfinityPointFuzzySet.java * * Created on 03 October 2002, 18:13 */ package uk.ac.leeds.ccg.projects.MedAction.FuzzyInference; /** * the fuzzy set extends the AbstractFuzzySet. could have any number of fuzzy points * more 3. to construct any shape of fuzzy membership. * @author jianhui jin */ import java.awt.Color; import java.awt.geom.Point2D; public class FuzzySet extends AbstractFuzzySet { /** Creates a new instance of InfinityPointFuzzySet */ public FuzzySet() { } /** * * @param pointNumber how many point you want in this fuzzy set, could be anything * >= 3 * @param topPointX where is the X position of the top point in this fuzzy set * @param setWidth the width of this set */ public FuzzySet(int pointNumber, double topPointX, double setWidth) { this.setFuzzySetWidth( setWidth ); // at least has three point. if( pointNumber < 3 ) { pointNumber = 3; } FuzzyPoint[] ps = new FuzzyPoint[ pointNumber ]; ps[ 0 ] = new FuzzyPoint( 0.0, 0.0 ); // initialse the start point, always in the same position ps[ pointNumber - 1 ] = new FuzzyPoint( 1.0, 0.0 ); // initialse the end point, always in the same position // those point in the middle of the start and end ones will // share the setWidth and the height of Y 1.0, which means // x will be setWidth / n * m, and y will be 1.0 / n * m // here n, m just means an integer value, could be any. // the construction process will start from the topPoint // down to the two sides of the set. // the case is two top point. if ( ( pointNumber % 2 ) == 0 ) { // initialise the top points for ( int i = 0; i < pointNumber / 2 - 1; i++ ) { ps[ pointNumber / 2 - 1 - i ] = new FuzzyPoint( topPointX - setWidth * ( i + 1 ) / ( pointNumber / 2 - 2 ), 1.0 - 1.0 * i / ( pointNumber / 2 - 2 ) ); ps[ pointNumber / 2 + i ] = new FuzzyPoint( topPointX + setWidth * ( i + 1 ) / ( pointNumber / 2 - 2 ), 1.0 - 1.0 * i / ( pointNumber / 2 - 2 ) ); } } else { // initialise the top point ps[ pointNumber / 2 ] = new FuzzyPoint( topPointX, 1.0 ); // initialise those points in the middle of the top points and the start or end point. for ( int i = 0; i < pointNumber / 2 - 1; i++ ) { ps[ pointNumber / 2 - i - 1 ] = new FuzzyPoint( topPointX - setWidth * ( i + 1 ) / ( pointNumber / 2 - 2 ), 1.0 - 1.0 * ( i + 1 ) / ( pointNumber / 2 - 2 ) ); ps[ pointNumber / 2 + i + 1 ] = new FuzzyPoint( topPointX + setWidth * ( i + 1 ) / ( pointNumber / 2 - 2 ), 1.0 - 1.0 * ( i + 1 ) / ( pointNumber / 2 - 2 ) ); } } this.setFuzzyPoint(ps); } /** * * @param index the index of the selected point which you want to move * @param newPosition the new position the point is goint to move to. */ public void movePoint(int index, Point2D newPosition) { FuzzyPoint[] ps = this.getFuzzyPoint(); if( (index < 0)||(index >= ps.length)){return;} else{ ps[index] = new FuzzyPoint(newPosition.getX(),newPosition.getY()); } this.setFuzzyPoint(ps); } /** * * @param color all fuzzy set's color which you want to set into */ public void setAllFuzzyPointColor(Color color) { FuzzyPoint[] ps = this.getFuzzyPoint(); for( int i = 0; i < ps.length; i++ ) { ps[i].setColor( color ); } } }