Class Vector3d

java.lang.Object
eu.mihosoft.vrl.v3d.Vector3d

public class Vector3d extends Object
3D Vector3d.
Author:
Michael Hoffer <info@michaelhoffer.de>
  • Field Details

    • x

      public double x
    • y

      public double y
    • z

      public double z
    • ZERO

      public static final Vector3d ZERO
    • UNITY

      public static final Vector3d UNITY
    • X_ONE

      public static final Vector3d X_ONE
    • Y_ONE

      public static final Vector3d Y_ONE
    • Z_ONE

      public static final Vector3d Z_ONE
  • Constructor Details

    • Vector3d

      public Vector3d(double x, double y, double z)
      Creates a new vector.
      Parameters:
      x - x value
      y - y value
      z - z value
    • Vector3d

      public Vector3d(Vector3d vec)
      Creates a new vector based on provided vector (copy constructor)
      Parameters:
      vec - vector for copy constructor
    • Vector3d

      public Vector3d(double x, double y)
      Creates a new vector with specified x, y and z = 0.
      Parameters:
      x - x value
      y - y value
  • Method Details

    • set

      public void set(double x, double y, double z)
    • set

      public void set(double x, double y)
    • set

      public void set(Vector3d vec)
    • sub

      public Vector3d sub(Vector3d vector)
      Subtracts the given vector from this vector
      Parameters:
      vector - the vector to subtract from this vector
      Returns:
      Vector3d
    • clone

      public Vector3d clone()
      Overrides:
      clone in class Object
    • negated

      public Vector3d negated()
      Returns a negated copy of this vector. Note: this vector is not modified.
      Returns:
      a negated copy of this vector
    • plus

      public Vector3d plus(Vector3d v)
      Returns the sum of this vector and the specified vector.
      Parameters:
      v - the vector to add Note: this vector is not modified.
      Returns:
      the sum of this vector and the specified vector
    • minus

      public Vector3d minus(Vector3d v)
      Returns the difference of this vector and the specified vector.
      Parameters:
      v - the vector to subtract Note: this vector is not modified.
      Returns:
      the difference of this vector and the specified vector
    • times

      public Vector3d times(double a)
      Returns the product of this vector and the specified value.
      Parameters:
      a - the value Note: this vector is not modified.
      Returns:
      the product of this vector and the specified value
    • times

      public Vector3d times(Vector3d a)
      Returns the product of this vector and the specified vector.
      Parameters:
      a - the vector Note: this vector is not modified.
      Returns:
      the product of this vector and the specified vector
    • dividedBy

      public Vector3d dividedBy(double a)
      Returns this vector devided by the specified value.
      Parameters:
      a - the value Note: this vector is not modified.
      Returns:
      this vector devided by the specified value
    • dot

      public double dot(Vector3d a)
      Returns the dot product of this vector and the specified vector. Note: this vector is not modified.
      Parameters:
      a - the second vector
      Returns:
      the dot product of this vector and the specified vector
    • lerp

      public Vector3d lerp(Vector3d a, double t)
      Linearly interpolates between this and the specified vector. Note: this vector is not modified.
      Parameters:
      a - vector
      t - interpolation value
      Returns:
      copy of this vector if t = 0; copy of a if t = 1; the point midway between this and the specified vector if t = 0.5
    • magnitude

      public double magnitude()
      Returns the magnitude of this vector. Note: this vector is not modified.
      Returns:
      the magnitude of this vector
    • magnitudeSq

      public double magnitudeSq()
      Returns the squared magnitude of this vector (this.dot(this)). Note: this vector is not modified.
      Returns:
      the squared magnitude of this vector
    • normalized

      public Vector3d normalized()
      Returns a normalized copy of this vector with length 1. Note: this vector is not modified.
      Returns:
      a normalized copy of this vector with length 1
    • cross

      public Vector3d cross(Vector3d a)
      Returns the cross product of this vector and the specified vector. Note: this vector is not modified.
      Parameters:
      a - the vector
      Returns:
      the cross product of this vector and the specified vector.
    • toStlString

      public String toStlString()
      Returns this vector in STL string format.
      Returns:
      this vector in STL string format
    • toStlString

      public StringBuilder toStlString(StringBuilder sb)
      Returns this vector in STL string format.
      Parameters:
      sb - string builder
      Returns:
      the specified string builder
    • toObjString

      public String toObjString()
      Returns this vector in OBJ string format.
      Returns:
      this vector in OBJ string format
    • toObjString

      public StringBuilder toObjString(StringBuilder sb)
      Returns this vector in OBJ string format.
      Parameters:
      sb - string builder
      Returns:
      the specified string builder
    • transform

      public Vector3d transform(Transform transform)
      Applies the specified transformation to this vector.
      Parameters:
      transform - the transform to apply
      Returns:
      this vector
    • transformed

      public Vector3d transformed(Transform transform)
      Returns a transformed copy of this vector.
      Parameters:
      transform - the transform to apply Note: this vector is not modified.
      Returns:
      a transformed copy of this vector
    • transform

      public Vector3d transform(Transform transform, double amount)
      Applies the specified transformation to this vector.
      Parameters:
      transform - the transform to apply
      Returns:
      this vector
    • transformed

      public Vector3d transformed(Transform transform, double amount)
      Returns a transformed copy of this vector.
      Parameters:
      transform - the transform to apply Note: this vector is not modified.
      Returns:
      a transformed copy of this vector
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • angle

      public double angle(Vector3d v)
      Returns the angle between this and the specified vector.
      Parameters:
      v - vector
      Returns:
      angle in radians
    • distance

      public double distance(Vector3d v)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • x

      public static Vector3d x(double x)
      Creates a new vector with specified x
      Parameters:
      x - x value
      Returns:
      a new vector [x,0,0]
    • y

      public static Vector3d y(double y)
      Creates a new vector with specified y
      Parameters:
      y - y value
      Returns:
      a new vector [0,y,0]
    • z

      public static Vector3d z(double z)
      Creates a new vector with specified z
      Parameters:
      z - z value
      Returns:
      a new vector [0,0,z]
    • orthogonal

      public Vector3d orthogonal()
      Creates a new vector which is orthogonal to this. this_i , this_j , this_k => i,j,k € {1,2,3} permutation looking for orthogonal vector o to vector this: this_i * o_i + this_j * o_j + this_k * o_k = 0
      Returns:
      a new vector which is orthogonal to this
    • add

      public Vector3d add(double x, double y, double z)
    • add

      public Vector3d add(Vector3d vec)
    • rotateX

      public Vector3d rotateX(double angle)
    • rotateY

      public Vector3d rotateY(double angle)
    • rotateZ

      public Vector3d rotateZ(double angle)
    • rotate

      public void rotate(Vector3d vector, double angle)
      Rotates the given vector clockwise around the axis produced by this vector by the given angle.
      Parameters:
      vector - the vector to rotate
      angle - the angle of rotation
    • midpoint

      public Vector3d midpoint(Vector3d point)
      Constructs a new Point3D at the geometric mean of this point and the given point. This function behaves identically to lerp(point, 0.5).
      Parameters:
      point - the other point
      Returns:
      a point at the geometric mean of the two given points
    • theta

      public double theta()
      Returns:
      theta elevation (angle between vector and z axis)
    • phi

      public double phi()
      Returns:
      phi azimuth (angle between projection onto xy plane and x axis)