Vector3D
vmm3d.core3D

Class Vector3D



  • public class Vector3Dextends Object
    A 3D vector with components of type double named x, y, and z.
    • Field Summary

      Fields 
      Modifier and TypeField and Description
      static Vector3DORIGIN
      The origin, (0,0,0).
      static Vector3DUNIT_X
      The unit vector in the x direction, (1,0,0).
      static Vector3DUNIT_Y
      The unit vector in the y direction, (0,1,0).
      static Vector3DUNIT_Z
      The uint vector in the z direction, (0,0,1).
      doublex
      The first component of the vector.
      doubley
      The second component of the vector.
      doublez
      The third component of the vector.
    • Constructor Summary

      Constructors 
      Constructor and Description
      Vector3D()
      Construct a vector with all three components initially equal to zero.
      Vector3D(double x, double y, double z)
      Construct a vector that initially has coordinates (x,y,z).
      Vector3D(Vector3D v)
      Construct a vector that is initially a copy of a specified vector.
    • Field Detail

      • x

        public double x
        The first component of the vector.
      • y

        public double y
        The second component of the vector.
      • z

        public double z
        The third component of the vector.
      • ORIGIN

        public static final Vector3D ORIGIN
        The origin, (0,0,0).
      • UNIT_X

        public static final Vector3D UNIT_X
        The unit vector in the x direction, (1,0,0).
      • UNIT_Y

        public static final Vector3D UNIT_Y
        The unit vector in the y direction, (0,1,0).
      • UNIT_Z

        public static final Vector3D UNIT_Z
        The uint vector in the z direction, (0,0,1).
    • Constructor Detail

      • Vector3D

        public Vector3D()
        Construct a vector with all three components initially equal to zero.
      • Vector3D

        public Vector3D(double x,        double y,        double z)
        Construct a vector that initially has coordinates (x,y,z).
      • Vector3D

        public Vector3D(Vector3D v)
        Construct a vector that is initially a copy of a specified vector.
        Parameters:
        v - the constructed vector is (v.x, v.y, v.z), or is (0,0,0) if v is null.
    • Method Detail

      • equals

        public boolean equals(Object obj)
        Returns true obj is a non-null object whose class in Vector3D and such that the three corrdinates of the vector obj are the same as the coordinates of this vector.
        Overrides:
        equals in class Object
      • norm

        public double norm()
        Returns the length of this vector, computed as Math.sqrt(x*x+y*y+z*z)
      • norm2

        public double norm2()
        Returns the length^2 of this vector, computed as (x*x+y*y+z*z)
      • normalize

        public void normalize()
        Divides each component of the vector by the norm of the vector, giving a vector that has length 1. However, if the vector is zero, or if any of its components are infinite or undefined, then the result of calling this method is to set all the components of the vector to Double.NaN. This method modifies the vector.
        See Also:
        normalized()
      • negate

        public void negate()
        Multiplies each component of this vector by -1. This method modifies the vector.
        See Also:
        negated()
      • normalized

        public Vector3D normalized()
        Returns a new vector that is equal to this vector normalized. This vector is not modified.
        See Also:
        normalize()
      • negated

        public Vector3D negated()
        Returns a new vector that is equal to -1 times this vector. This vector is not modified.
        See Also:
        negate()
      • plus

        public Vector3D plus(Vector3D v)
        Returns the vector sum of this vector and v. A new vector object is constructed to contain the result; neither input vector is modified.
        Parameters:
        v - a non-null vector
      • linComb

        public Vector3D linComb(double c,               double d,               Vector3D v)
        Returns the linear combination c*this + d*v. A new vector object contains the result.
      • assign

        public void assign(Vector3D v)
        this.assign(v) assigns to this the value v.
      • assignPlus

        public void assignPlus(Vector3D v)
        this.assignPlus(v) assigns to this the value this + v.
      • assignSum

        public void assignSum(Vector3D v,             Vector3D w)
        this.assignSum(v,w) assigns to this the value v + w.
      • assignLinComb

        public void assignLinComb(double c,                 double d,                 Vector3D v)
        this.assignLinComb(c,d,v) assigns to this the value c*this + d*v.
      • assignLinComb

        public void assignLinComb(double c,                 Vector3D v,                 double d,                 Vector3D w)
        this.assignLinComb(c,v,d,w) assigns to this the value c*v + d*w.
      • assignPlus_SumTimes

        public void assignPlus_SumTimes(Vector3D u,                       Vector3D v,                       Vector3D w,                       Vector3D ww,                       double d)
        this.assignPlus_SumTimes(u, v, w, ww, d) assigns to this the value: this + (u + v + w + ww)*d.
      • minus

        public Vector3D minus(Vector3D v)
        Returns the vector difference of this vector and v. A new vector object is constructed to contain the result; neither input vector is modified.
        Parameters:
        v - a non-null vector
      • assignMinus

        public void assignMinus(Vector3D v)
        this.assignMinus(v) assigns to this the value this (- v).
      • assignMinus

        public void assignMinus(Vector3D v,               Vector3D w)
        this.assignMinus(v, w) assigns to this the value this (v - w).
      • times

        public Vector3D times(double d)
        Returns the scalar product of this vector times d. A new vector object is constructed to contain the result; the vector is not modified.
        Parameters:
        d - the scalar that is to be multiplied times this vector
      • assignTimes

        public void assignTimes(double d)
        this.assignTimes(d) assigns to this the value d*this.
      • assignTimes

        public void assignTimes(double d,               Vector3D v)
        this.assignTimes(d, v) assigns to this the value d*v.
      • assignSumTimes

        public void assignSumTimes(Vector3D v,                  Vector3D w,                  double d)
        this.assignSumTimes(v, w, d) assigns to this the value (v + w)*d.
      • assignSumTimes

        public void assignSumTimes(Vector3D v,                  Vector3D w,                  Vector3D vv,                  Vector3D ww,                  double d)
        this.assignSumTimes(v, w, vv, ww, d) assigns to this the value (v + w + vv + ww)*d.
      • dot

        public double dot(Vector3D v)
        Returns the dot product of this vector and v. A new vector object is constructed to contain the result; neither input vector is modified.
        Parameters:
        v - a non-null vector
      • cross

        public Vector3D cross(Vector3D v)
        Returns the cross product of this vector and v. A new vector object is constructed to contain the result; neither input vector is modified.
        Parameters:
        v - a non-null vector
      • reflectInAxis

        public Vector3D reflectInAxis(Vector3D axis)
        Rotates this around the unit vector axis by 180 degrees: this to -this + 2*axis. Call as this.reflectInAxis(axis).
      • toString

        public String toString()
        Returns a string representation of this vector of the form "(x,y,z)" where x, y, and z are the numerical components of the vector. The special strings NaN, INF and -INF are used to represent the values Double.NaN, Double.POSITIVE_INFINITY, and Double.NEGATIVE_INFINITY.
        Overrides:
        toString in class Object
      • fromString

        public static Vector3D fromString(String str)                           throws NumberFormatException
        Attempts to convert a string into a value of type Vector3D. The string should be in the format produced by toString(), of the form "(x,y,z)". Will also accept strings that use a space as a separator and are not enclosed in parentheses, of the form "x y z".
        Parameters:
        str - the non-null string that is to be converted
        Throws:
        NumberFormatException - if the string is not of the correct format (or is null)

SCaVis 2.2 © jWork.ORG