/**
  * sets the vector to new vector
  *
  * @param V Vector to be set
  */
 public void set(Vector3D v) {
   x = v.getX();
   y = v.getY();
   z = v.getZ();
 }
  /**
   * Calculate the unit vector surface normal for the plane represented by the 3 given points
   * (assuming clockwise order).
   *
   * @param aVec1 the first point on the plane.
   * @param aVec2 the second point on the plane.
   * @param aVec3 the third point on the plane.
   * @return aResultVector the vector to store the result in.
   */
  public static Vector3D getSurfaceNormal(Vector3D Vec1, Vector3D Vec2, Vector3D Vec3) {

    // calculate normal for this polygon
    Vector3D edge1 = new Vector3D(Vec2);
    edge1.subtractEq(Vec1);

    Vector3D edge2 = new Vector3D(Vec3);
    edge2.subtractEq(Vec2);

    if (checkCollinear(edge1, edge2)) return null;
    return crossProduct(edge2, edge1).getUnitVector();
  }
 /**
  * checks if vector is Collinear to given vector
  *
  * @return true if vectors are Collinear else false
  */
 public boolean isCollinearTo(Vector3D V) {
   if (Math.abs(this.DotProduct(V)) == this.getLength() * V.getLength()) {
     return true;
   } else {
     return false;
   }
 }
 /**
  * checks if vector is parallel to given vector
  *
  * @return true if vectors are parallel else false
  */
 public boolean isParallel_to(Vector3D V) {
   if (this.DotProduct(V) == this.getLength() * V.getLength()) {
     return true;
   } else {
     return false;
   }
 }
 /**
  * construct a new vector between two points
  *
  * @param point1 : initial vector
  * @param point2 : final vector
  */
 public Vector3D(Vector3D point1, Vector3D point2) {
   this(
       point2.getX() - point1.getX(),
       point2.getY() - point1.getY(),
       point2.getZ() - point1.getZ());
 }
 /**
  * Constructs a new <code>Vector</code> that is the copy of specified object
  *
  * @param v : the <code>Vector</code> object to copy
  */
 public Vector3D(Vector3D v) {
   x = v.getX();
   y = v.getY();
   z = v.getZ();
   edge = v.edge;
 }
 /** @return v1.v3(v2)-v1.v2(v3) */
 public static Vector3D vectorTripleProduct(Vector3D v1, Vector3D v2, Vector3D v3) {
   Vector3D rv;
   rv = v3.scale(v1.DotProduct(v3));
   rv = rv.subtract(v2.scale(v1.DotProduct(v2)));
   return rv;
 }
 /** @return [v1 v2 v3] */
 public static double scalarTripleProduct(Vector3D v1, Vector3D v2, Vector3D v3) {
   return v1.DotProduct(v2.CrossProduct(v3));
 }
 /**
  * Calulates vector which divides v1 and v2 in 1:s
  *
  * @return Vector dividing v1,v2 in 1:s
  */
 public static Vector3D intepolate(Vector3D v1, Vector3D v2, double s) {
   if (s == -1) return null;
   return (v1.scale(s).add(v2)).scale(1 / (s + 1));
 }
 /** @return Component of this vector parallel to given vector */
 public Vector3D Get_Parallel_Component(Vector3D dirVector3D) {
   return dirVector3D.scale(this.DotProduct(dirVector3D.getUnitVector()));
 }
 /**
  * computes angle(in radian) between two vectors
  *
  * @return angle in radians
  */
 public static final double calculateAngle(Vector3D v1, Vector3D v2) {
   return Math.acos(Vector3D.dotProduct(v1.getUnitVector(), v2.getUnitVector()));
 }
 /**
  * test if the two vectors are orthogonal
  *
  * @return true if the vectors are orthogonal
  */
 public static final boolean checkOrthogonal(Vector3D v1, Vector3D v2) {
   return Vector3D.dotProduct(v1.getUnitVector(), v2.getUnitVector()) < EPSILON;
 }
 /**
  * test if the two vectors are collinear
  *
  * @param v1 : first vector to be checked
  * @param v2 : second vector to be checked
  * @return true if the vectors are colinear
  */
 public static final boolean checkCollinear(Vector3D v1, Vector3D v2) {
   return Vector3D.crossProduct(v1, v2).getLengthSq() < EPSILON;
 }
 /**
  * Computes the dot product of the two vectors, defined by :
  *
  * <p><code> x1*x2 + y1*y2 + z1*z2</code>
  *
  * <p>Dot product is zero if the vectors defined by the 2 vectors are orthogonal. It is positive
  * if vectors are in the same direction, and negative if they are in opposite direction.
  */
 public static final double dotProduct(Vector3D v1, Vector3D v2) {
   return v1.getX() * v2.getX() + v1.getY() * v2.getY() + v1.getZ() * v2.getZ();
 }
 /**
  * Computes the difference of the two vectors.
  *
  * @param v1 : left vector
  * @param v2 : right Vector
  * @return new vector obtained by subtracting right vector from left vector
  */
 public Vector3D subtractVectors(Vector3D v1, Vector3D v2) {
   return new Vector3D(v1.getX() - v2.getX(), v1.getY() - v2.getY(), v1.getZ() - v2.getZ());
 }
 /**
  * Computes the sum of the two vectors.
  *
  * @param v1 : left vector
  * @param v1: right Vector
  * @return new vector representing sum of two vectors
  */
 public Vector3D addVectors(Vector3D v1, Vector3D v2) {
   return new Vector3D(v1.getX() + v2.getX(), v1.getY() + v2.getY(), v1.getZ() + v2.getZ());
 }