import Point3D;
import Vertex3D;

public class Vector3D {
    public float x, y, z;           // vector
  

    public Vector3D()
    {
       
    }

    public Vector3D(float xval, float yval, float zval)
    {
        x = xval;
        y = yval;
        z = zval;
      
    }
    
	public Vector3D(Vector3D v)
    {
        x = v.x;
        y = v.y;
        z = v.z;
     
    }
	
	public Vector3D(Point3D p)
    {
        x = p.x;
        y = p.y;
        z = p.z;
     
    }
	
    public void copy(Vector3D v)
    {
        x = v.x;        y = v.y;        z = v.z;   
       
    }

	public Vector3D(Vertex3D v)
    {
        x = v.x;
        y = v.y;
        z = v.z;
     
    }
    public void setVector(float xval, float yval, float zval) {
        x=xval;
        x=yval;
        x=zval;
       
    }

    public void normalize( )
    {
        float l = (float) (1 / Math.sqrt(x*x + y*y+ z*z));
        x *= l;
        y *= l;
        z *= l;
           
       
    }
    public void subtractVector(Vector3D a){
		x-=a.x;
		y-=a.y;
		z-=a.z;
	}
	
	public  void scaleVector(float scale){
		x*=scale;
		y*=scale;
		z*=scale;
		
	}
	
	
	public static float dot(Vector3D a, Vector3D b){
		float ans=a.x*b.x + a.y*b.y +a.z*b.z;
		return ans;
	}
	
	/** takes cross product of a and b and returns in a
	 */
	
	public static void cross(Vector3D a, Vector3D b){
		float tmp[]=new float[3];
		tmp[0]=-a.z*b.y+a.y*b.z;
		tmp[1]=a.z*b.x-a.x*b.z;
		tmp[2]=-a.y*b.x+a.x*b.y;
		
		a.x=tmp[0];
		a.y=tmp[1];
		a.z=tmp[2];
	}
	
	public static void scaleVector(Vector3D a, float scale){
		a.x*=scale;
		a.y*=scale;
		a.z*=scale;
		
	}
	
	//subtract b from a and store in a
	public static void subtractVector(Vector3D a, Vector3D b){
		a.x-=b.x;
		a.y-=b.y;
		a.z-=b.z;
	}
}
    