public boolean intersect(IntersectionRecord outRecord, Ray rayIn) {
    // TODO: fill in this function.
    // Hint: This object can be transformed by a transformation matrix,
    // so the rayIn needs to be processed so that it is in the same coordinate as the object.
		
	    Ray ray = rayIn;
	    ray = this.untransformRay(ray);
	    
	    Point3 v0 = owner.getVertex(index[0]);
		double g = ray.direction.x;
		double h = ray.direction.y;
		double i = ray.direction.z;
		double j = v0.x-ray.origin.x;
		double k = v0.y-ray.origin.y;
		double l = v0.z-ray.origin.z;
		
		double eihf = e*i-h*f;
		double gfdi = g*f-d*i;
		double dheg = d*h-e*g;
		double akjb = a*k-j*b;
		double jcal = j*c-a*l;
		double blkc = b*l-k*c;
		
		double m = a*(eihf) + b*(gfdi) + c*(dheg);

	    double t = -(f*(akjb) + e*(jcal) + d*(blkc))/m;
	    if (t<ray.start || t>ray.end) return false;
	    
	    double gamma = (i*(akjb) + h*(jcal) + g*(blkc))/m;
	    if (gamma<0 || gamma>1) return false;
	    	
	    double beta = (j*(eihf) + k*(gfdi) + l*(dheg))/m;
	    if (beta<0 || beta>(1-gamma)) return false;
		
	    if (outRecord != null) {
	        outRecord.t = t;
	        ray.evaluate(outRecord.location, t);
	        outRecord.surface = this;
	        
	        if (owner.existsNormals()) {
	        	Vector3 norm1 = owner.getNormal(index[0]);
	        	Vector3 norm2 = owner.getNormal(index[1]);
	        	Vector3 norm3 = owner.getNormal(index[2]);
	        	
	        	norm1.scale(1-beta-gamma);
	        	norm2.scale(beta);
	        	norm3.scale(gamma);
	        	
	        	Vector3 n = new Vector3();
	        	n.add(norm1,norm2);
	        	n.add(n,norm3);
	        	n.normalize();
	        	
	        	outRecord.normal.set(n);
	        } else {
	        	outRecord.normal.set(norm);
	        }
	        
	        tMat.rightMultiply(outRecord.location, outRecord.location);
	        tMatTInv.rightMultiply(outRecord.normal, outRecord.normal);
	        
	        outRecord.normal.normalize();

	      }
	    
	    return true;

  }