import java.io.Serializable;
import DE.*;

/**
 * A parameter that represents a location in 3D space using polar coordinates.
 * Only the angles elevation and rotation are represented here.  It is assumed
 * that the radial distance is stored or computed elsewhere.
 * Written by Chris Studholme
 * Licenced for redistribution under the GNU General Public Licence
 */
public class AngleParameter implements Parameter, Serializable {

    /** Elevation angle in the range -PI/2 to PI/2.
     */
    public double elevation;

    /** Angle of rotation in the range -PI to PI.
     */
    public double rotation;
 
    /**
     * Construct new parameter with specified angles.
     * @param elevation elevation angle
     * @param rotation rotation angle
     */
    public AngleParameter(double elevation, double rotation) {
	this.elevation=elevation;
	this.rotation=rotation;
    }

    /**
     * Scale this parameter by factor and then add to scaled version of
     * other parameter.  The other parameter may be null and is treated
     * as zero in such case.
     * @param factor factor to multiply this by
     * @param other other parameter to add (may be null)
     * @param otherfactor factor to scale other by
     * @return new AngleParameter representing the result
     */
    public Parameter scaleadd(double factor,
			      Parameter other, 
			      double otherfactor) {
	double r1 = factor*elevation;
	double r2 = factor*rotation;
	if (other instanceof AngleParameter) {
	    r1 += otherfactor*((AngleParameter)other).elevation;
	    r2 += otherfactor*((AngleParameter)other).rotation;
	}
	return new AngleParameter(r1,r2);
    }

    /**
     * Return string representation of parameter in the form:
     * "(elevation,rotation)"
     * @return String object
     */
    public String toString() {
	return "("+elevation+","+rotation+")";
    }
}
