/**
 * An objective function that illustrates the use of multidimensional
 * minimization algorithms to solve a triangulation problem
 *
 * The problem is to find the intersection of two circles.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class TriangulationObjective extends Objective
{

    private double[]     ci, cj;
    private double       ri, rj;
    

    /**
     * Default Constructor
     */
     public TriangulationObjective()
     {
          super(2);

          ci = new double[2];
          cj = new double[2];

          // Attributes of one circle
          ci[0] = 4.0;    // x of center
          ci[1] = 8.0;    // y of center
          ri    = 0.5;    // radius

          // Attributes of the other circle
          cj[0] = 3.0;    // x of center
          cj[1] = 9.0;    // y of center
          rj    = 1.5;    // radius
          
     }

    /**
     * Evaluate the objective function
     *
     * @param xx    A guess at an intersection point
     * @return      An indication of the extent of the error
     */
     public double evaluate(double[] xx)
     {
        double   di, dj;
        
        // The estimated radii
        di = Math.sqrt(Math.pow(ci[0]-xx[0],2.0)+Math.pow(ci[1]-xx[1],2.0));
        dj = Math.sqrt(Math.pow(cj[0]-xx[0],2.0)+Math.pow(cj[1]-xx[1],2.0));
        
        // Return the sum of the square of the differences between the
        // estimated and actual radii
        return Math.pow((di - ri),2.0)+Math.pow((dj - rj),2.0);
     }



}
