Class Vector3d

java.lang.Object
com.ijurnove.cpu3d.Vector3d

public class Vector3d extends Object
A Vector3d represents a direction in 3D space. Vector3ds do not have an origin, and only represent a direction.
  • Field Details

    • NEUTRAL_VEC

      protected static final Vector3d NEUTRAL_VEC
    • UP

      protected static final Vector3d UP
  • Constructor Details

    • Vector3d

      public Vector3d(double x, double y, double z)
      Constructs a new Vector3d with the given values.
      Parameters:
      x - the X value
      y - the Y value
      z - the Z value
    • Vector3d

      protected Vector3d(double[] xyz)
    • Vector3d

      public Vector3d(Point3d start, Point3d end)
      Constructs a Vector3d between two Point3ds.
      Parameters:
      start - the starting Point3d
      end - the ending Point3d
  • Method Details

    • x

      public double x()
      Returns the X value.
      Returns:
      the X value
    • y

      public double y()
      Returns the Y value.
      Returns:
      the Y value
    • z

      public double z()
      Returns the Z value.
      Returns:
      the Z value
    • setX

      public void setX(double x)
      Sets the X value.
      Parameters:
      x - the value to set
    • setY

      public void setY(double y)
      Sets the Y value.
      Parameters:
      y - the value to set
    • setZ

      public void setZ(double z)
      Sets the Z value.
      Parameters:
      z - the value to set
    • copy

      public Vector3d copy()
      Returns a copy of this Vector3d.
      Returns:
      a copy of this Vector3d
    • isEqual

      public boolean isEqual(Vector3d v)
      Returns true if the X, Y, and Z values of a given Vector3d are equal to those of this Vector3d.
      Parameters:
      v - the Vector3d to compare
      Returns:
      true if both Vector3ds have the same X, Y, and Z values
    • magnitude

      public double magnitude()
      Returns the magnitude.
      Returns:
      magnitude
    • normalize

      public void normalize()
      Sets the length of this Vector3d to 1.
    • rotate

      public void rotate(int axis, double theta)
      Rotates this Vector3d.
      Parameters:
      axis - the axis to rotate around
      theta - the amount to rotate by
    • crossProduct

      public static Vector3d crossProduct(Vector3d v1, Vector3d v2)
      Returns a Vector3d perpendicular to two given Vector3ds.
      Parameters:
      v1 - the first Vector3d
      v2 - the second Vector3d
      Returns:
      a Vector3d perpendicular to v1 and v2
    • cross

      public Vector3d cross(Vector3d v2)
      Returns a Vector3d perpendicular to this Vector3d and another.
      Parameters:
      v2 - the second Vector3d
      Returns:
      a Vector3d perpendicular to this and v2
    • dotProduct

      public static double dotProduct(Vector3d v1, Vector3d v2)
      Returns the dot product of two Vector3ds.
      Parameters:
      v1 - the first Vector3d
      v2 - the second Vector3d
      Returns:
      the dot product of v1 and v2
    • dotProduct

      public double dotProduct(Vector3d v2)
      Returns the dot product of this Vector3d and another.
      Parameters:
      v2 - the second Vector3d
      Returns:
      the dot product of this and v2
    • multiplyByNum

      public static Vector3d multiplyByNum(Vector3d vec, double num)
      Returns a new Vector3d with the values of a given Vector3d multiplied by a number.
      Parameters:
      vec - the Vector3d to be altered
      num - the number to multiply by
      Returns:
      a new Vector3d with the values of the given Vector3d multiplied by the given number
    • subtract

      public static Vector3d subtract(Vector3d v1, Vector3d v2)
      Subtracts one Vector3d from another.
      Parameters:
      v1 - the first Vector3d
      v2 - the second Vector3d
      Returns:
      v1 minus v2
    • add

      public static Vector3d add(Vector3d v1, Vector3d v2)
      Adds one Vector3d to another.
      Parameters:
      v1 - the first Vector3d
      v2 - the second Vector3d
      Returns:
      v1 plus v2
    • absVal

      protected void absVal()
    • invert

      public void invert()
      Reverses the direction of this Vector3d.
    • average

      protected static Vector3d average(Vector3d[] vectors)
    • fromBary

      protected static Vector3d fromBary(Vector3d[] vectors, double[] bary)
    • swapXY

      protected void swapXY()
    • toString

      public String toString()
      Overrides:
      toString in class Object