package extractors.hog;

/**
 * This class represents a gradient in spherical coordinates.
 * 
 */
public class Gradient {

	// the spherical coordinates
	private double phi, theta, magnitude;

	/**
	 * Constructs a gradient from the specified cartesian coordinates.
	 * 
	 * @param x
	 * @param y
	 * @param z
	 */
	public Gradient(double x, double y, double z) {
		magnitude = Math.sqrt(x * x + y * y + z * z);
		phi = Math.atan2(y, x) * 180 / Math.PI;
		theta = magnitude != 0 ? Math.acos(z / magnitude) * 180 / Math.PI : 0;
	}

	public double getPhi() {
		return phi;
	}

	public double getTheta() {
		return theta;
	}

	public double getMagnitude() {
		return magnitude;
	}

	@Override
	public String toString() {
		return "phi=" + getPhi() + ", theta=" + getTheta() + ", magnitude=" + getMagnitude();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Gradient) {
			Gradient o = (Gradient) obj;
			return getPhi() == o.getPhi() && getTheta() == o.getTheta() && getMagnitude() == o.getMagnitude();
		}

		return false;
	}
}
