
/*
// uncomment this to do an interpolation on x and the weight

class MMmnormal {

    // increments

    // between 0 and 2*pi
    private double x0, x;
    private double weight0, weight;

    // constructor from two points
    MMmnormal (MMnormal vec1, MMnormal vec2) {
	x0 = vec1.x;
	weight0 = vec1.getWeight();
//	System.out.println(vec1.getAngle()+" -> "+vec2.getAngle()+" == "+angle0+" -> "+(angle0+100*angle));
	x = (.01*(vec2.x - x0));
//	y = (.01*(vec2.y - y0));
	weight = (.01*(vec2.getWeight() - weight0));
    }

    // when the percentage is p the normal is...
    MMnormal normalWhen(float p) {
	double xcur = x0 + p*x;
	double wcur = w0 + p*w;
	// Pythagora
	ycur = Math.sqrt(wcur*wcur-xcur*xcur);
	double a = Math.acos(xcur/wcur);
	if (a > 2*Math.PI) {
	    a =  (a - 2*Math.PI);
//	    System.out.println("Changed angle from "+(angle0+p*angle)+" to "+a);
	}
	else if (a < 0) {
	    a =  (a + 2*Math.PI);
//	    System.out.println("Changed angle from "+(angle0+p*angle)+" to "+a);
	}
	if (a > 2*Math.PI || a < 0) System.out.println("ALERT!! angle a is not in [0; 2*pi]");
	double cosa =  Math.cos(a);
	double sina =  Math.sin(a);
	double w = weight0+p*weight;
	return new MMnormal((float)(w*cosa), (float)(w*sina), w, a, cosa, sina);
    }
}
*/



 // uncomment the following for interpolation on x,y

class MMmnormal {

    // increments

    // between 0 and 2*pi
    private double angle0, angle;
    private double weight0, weight;
    // the x y components
    public double x0, x, y0, y; 

    // constructor from two points
    MMmnormal (MMnormal vec1, MMnormal vec2) {
	x0 = vec1.x;
	y0 = vec1.y;
	weight0 = vec1.getWeight();
//	System.out.println(vec1.getAngle()+" -> "+vec2.getAngle()+" == "+angle0+" -> "+(angle0+100*angle));
	x = (.01*(vec2.x - x0));
	y = (.01*(vec2.y - y0));
	weight = (.01*(vec2.getWeight() - weight0));
    }

    // when the percentage is p the normal is...
    MMnormal normalWhen(float p) {
	return new MMnormal(new MMpoint((float) (y0+y*p), -(float) (x0+p*x)), new MMpoint(0,0));
    }
}

/*


// uncomment this to do an interpolation linear to the angle and weight

class MMmnormal {

    // increments

    // between 0 and 2*pi
    private double angle0, angle;
    private double weight0, weight;
    // the x y components
//    public float x0, x, y0, y; 

    // constructor from two points
    MMmnormal (MMnormal vec1, MMnormal vec2) {
//	x0 = vec1.x;
//	y0 = vec1.y;
	weight0 = vec1.getWeight();
	if (vec1.getAngle()>=vec2.getAngle()) {
	    if (vec1.getAngle()-vec2.getAngle() <= 2*Math.PI+vec2.getAngle()-vec1.getAngle()) {
		angle0 = vec1.getAngle();
		angle = (.01*(vec2.getAngle() - angle0));
	    } else {
		angle0 = vec1.getAngle();
		angle = (.01*(Math.PI * 2 + vec2.getAngle() - angle0));
	    }
	} else { 
	    if (vec2.getAngle()-vec1.getAngle() <= 2*(Math.PI)+vec1.getAngle()-vec2.getAngle()) {
		angle0 = vec1.getAngle();
		angle = (.01*(vec2.getAngle() - angle0));
	    } else {
		angle0 = vec1.getAngle();
		angle =  (.01*(-Math.PI * 2 + vec2.getAngle() - angle0));
	    }
	}
//	System.out.println(vec1.getAngle()+" -> "+vec2.getAngle()+" == "+angle0+" -> "+(angle0+100*angle));
//	x = (.01*(vec2.x - x0));
//	y = (.01*(vec2.y - y0));
	weight = (.01*(vec2.getWeight() - weight0));
    }

    // when the percentage is p the normal is...
    MMnormal normalWhen(float p) {
	double a = angle0 + p * angle;
	if (a > 2*Math.PI) {
	    a =  (a - 2*Math.PI);
//	    System.out.println("Changed angle from "+(angle0+p*angle)+" to "+a);
	}
	else if (a < 0) {
	    a =  (a + 2*Math.PI);
//	    System.out.println("Changed angle from "+(angle0+p*angle)+" to "+a);
	}
	if (a > 2*Math.PI || a < 0) System.out.println("ALERT!! angle a is not in [0; 2*pi]");
	double cosa =  Math.cos(a);
	double sina =  Math.sin(a);
	double w = weight0+p*weight;
	return new MMnormal((float)(w*cosa), (float)(w*sina), w, a, cosa, sina);
    }
}
*/
