Class Vector

java.lang.Object
org.shredzone.commons.suncalc.util.Vector

public class Vector extends Object
A three dimensional vector.

Objects are is immutable and threadsafe.

  • Constructor Details

    • Vector

      public Vector(double x, double y, double z)
      Creates a new Vector of the given cartesian coordinates.
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
    • Vector

      public Vector(double[] d)
      Creates a new Vector of the given cartesian coordinates.
      Parameters:
      d - Array of coordinates, must have 3 elements
  • Method Details

    • ofPolar

      public static Vector ofPolar(double φ, double θ)
      Creates a new Vector of the given polar coordinates, with a radial distance of 1.
      Parameters:
      \u03c6 - Azimuthal Angle
      \u03b8 - Polar Angle
      Returns:
      Created Vector
    • ofPolar

      public static Vector ofPolar(double φ, double θ, double r)
      Creates a new Vector of the given polar coordinates.
      Parameters:
      \u03c6 - Azimuthal Angle
      \u03b8 - Polar Angle
      r - Radial Distance
      Returns:
      Created Vector
    • getX

      public double getX()
      Returns the cartesian X coordinate.
    • getY

      public double getY()
      Returns the cartesian Y coordinate.
    • getZ

      public double getZ()
      Returns the cartesian Z coordinate.
    • getPhi

      public double getPhi()
      Returns the azimuthal angle (φ) in radians.
    • getTheta

      public double getTheta()
      Returns the polar angle (θ) in radians.
    • getR

      public double getR()
      Returns the polar radial distance (r).
    • add

      public Vector add(Vector vec)
      Returns a Vector that is the sum of this Vector and the given Vector.
      Parameters:
      vec - Vector to add
      Returns:
      Resulting Vector
    • subtract

      public Vector subtract(Vector vec)
      Returns a Vector that is the difference of this Vector and the given Vector.
      Parameters:
      vec - Vector to subtract
      Returns:
      Resulting Vector
    • multiply

      public Vector multiply(double scalar)
      Returns a Vector that is the scalar product of this Vector and the given scalar.
      Parameters:
      scalar - Scalar to multiply
      Returns:
      Resulting Vector
    • negate

      public Vector negate()
      Returns the negation of this Vector.
      Returns:
      Resulting Vector
    • cross

      public Vector cross(Vector right)
      Returns a Vector that is the cross product of this Vector and the given Vector.
      Parameters:
      right - Vector to multiply
      Returns:
      Resulting Vector
    • dot

      public double dot(Vector right)
      Returns the dot product of this Vector and the given Vector.
      Parameters:
      right - Vector to multiply
      Returns:
      Resulting dot product
    • norm

      public double norm()
      Returns the norm of this Vector.
      Returns:
      Norm of this vector
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object