public double costOfPointToCenter(Point centre){
		if(this.weight == 0.0){
			return 0.0;
		}

		//stores the distance between p and centre
		double distance = 0.0;

		//loop counter
		for(int l=0; l<this.dimension; l++){
			//Centroid coordinate of the point
			double centroidCoordinatePoint;
			if(this.weight != 0.0){
				centroidCoordinatePoint = this.coordinates[l] / this.weight;
			} else {
				centroidCoordinatePoint = this.coordinates[l];
			}
			//Centroid coordinate of the centre
			double centroidCoordinateCentre;
			if(centre.weight != 0.0){
				centroidCoordinateCentre = centre.coordinates[l] / centre.weight;
			} else {
				centroidCoordinateCentre = centre.coordinates[l];
			}
			distance += (centroidCoordinatePoint-centroidCoordinateCentre) * 
					(centroidCoordinatePoint-centroidCoordinateCentre) ;
					
		}
		return distance * this.weight;
	}
public double costOfPointToCenter ( Point centre ) { if ( this . weight == 0.0 ) { return 0.0 ; } double distance = 0.0 ; for ( int l = 0 ; l < this . dimension ; l ++ ) { double centroidCoordinatePoint ; if ( this . weight != 0.0 ) { centroidCoordinatePoint = this . coordinates [ l ] / this . weight ; } else { centroidCoordinatePoint = this . coordinates [ l ] ; } double centroidCoordinateCentre ; if ( centre . weight != 0.0 ) { centroidCoordinateCentre = centre . coordinates [ l ] / centre . weight ; } else { centroidCoordinateCentre = centre . coordinates [ l ] ; } distance += ( centroidCoordinatePoint - centroidCoordinateCentre ) * ( centroidCoordinatePoint - centroidCoordinateCentre ) ; } return distance * this . weight ; }
Computes the cost of this point with centre centre