package math.equation;

import java.util.Scanner;

import math.geometry.Point;
import math.matrix.Vector;
import math.matrix.Vector3D;

public class ParametricPlane {

	private Vector position;
	private Vector directionU;
	private Vector directionV;
	
	public ParametricPlane(double x0, double y0, double x1, double y1, double x2, double y2){
		position = new Vector(x0, y0);
		directionU = new Vector(x1,y1).minus(position);
		directionU = new Vector(x2,y2).minus(position);
	}
	
	public ParametricPlane(Point p0, Point p1, Point p2){
		position = new Vector(p0);
		directionU = new Vector(p1).minus(position);
		directionV = new Vector(p2).minus(position);
	}
	
	public ParametricPlane(Point p0, Vector3D directionU, Vector3D directionV){
		position = new Vector(p0);
		this.directionU = directionU;
		this.directionV = directionV;
	}

	@Override
	public String toString(){
		int i = 0;
		StringBuffer output = new StringBuffer();
		Scanner scannerP = new Scanner(position.toString());
		Scanner scannerDU = new Scanner(directionU.toString());
		Scanner scannerDV = new Scanner(directionV.toString());
		while(scannerP.hasNextLine()) {
			String lineP = scannerP.nextLine();
			String lineDU = scannerDU.nextLine();
			String lineDV = scannerDV.nextLine();
			if(i==((int)(position.n()/2)+2))
				output.append("r = " + lineP + " + λ" + lineDU + " + µ" + lineDV + "\n");
			else output.append("    " + lineP + "    " + lineDU + "    " + lineDV + "\n");
			i++;
		}
		scannerP.close();
		scannerDU.close();
		scannerDV.close();
		return new String(output);
	}

	public static void main(String[] args) {
    	Point p0 = new Point(4,-6,3);
    	Vector3D u = new Vector3D(-1,5,-1);
    	Vector3D v = new Vector3D(-2,-1,1);
    	System.out.println("P0 = " + p0 + ", u = " + u.toStringT() + ", v = " + v.toStringT());
    	ParametricPlane pl3 = new ParametricPlane(p0,u,v);
    	System.out.println("3D" + pl3);
	}

}
