←to practical programming

Homework "Vec"

Build a class to represent Euclidian 3D vectors.
  1. (6 points) Build a class called "vec" (we reserve the name "vector" for n-dimensional vectors) to represent 3D vectors.
  2. (3 points) Implement methods for dot-product, vector-product, and norm; override ToString method. Something like

    public double dot(vec other){return this.x*other.x+this.y*other.y+this.z*other.z;}
    /* and/or */
    public static double dot(vec v,vec w){return v.x*w.x+v.y*w.y+v.z*w.z;}
    
  3. (1 point) Make an "approx" method to compare two vec's with absolute precision τ and relative precision ε. Something like

    static bool approx(double a,double b,double tau=1e-9,double eps=1e-9){
    	if(Abs(a-b)<tau)return true;
    	if(Abs(a-b)/(Abs(a)+Abs(b))<eps)return true;
    	return false;
    	}
    public bool approx(vec other){
    	if(!approx(this.x,other.x)return false;
    	if(!approx(this.y,other.y)return false;
    	if(!approx(this.z,other.z)return false;
    	return true;
    	}
    public static bool approx(vec u, vec v){ return u.approx(v); }
    
    and run extensive tests of your implementation in the Main function (see [../matlib/complex/main.cs] for inspiration).