Class R3

All Implemented Interfaces:
Serializable, IArchive

public class R3 extends BaseVector<R3> implements Serializable
Represents an element of R^3, the three-dimensional cartesian real space.
Author:
Christopher Allen
See Also:
  • Field Details

    • INT_SIZE

      public static final int INT_SIZE
      number of dimensions (DIM=3)
      See Also:
  • Constructor Details

    • R3

      public R3()
      Creates a new instance of R3, the zero element.
    • R3

      public R3(double x1, double x2, double x3)
      Creates a new instance of R3 initialized to arguments.
      Parameters:
      x1 - first coordinate value
      x2 - first coordinate value
      x3 - first coordinate value
    • R3

      public R3(double[] arrVals) throws IllegalArgumentException
      Creates a new instance of R3 initialized to argument. If the initializing array has length greater than 3 the first three values are taken, if it has length less than three then the remain coordinates of the new R3 object are zero.
      Parameters:
      arrVals - double array of initializing values
      Throws:
      IllegalArgumentException - the argument must have the same length as this vector
    • R3

      public R3(R3 vecPt)
      Creates a new instance of R3 initialized to argument.
      Parameters:
      vecPt - deep copies this value
    • R3

      Create a new instance of R3 with specified initial value specified by the formatted string argument.

      The string should be formatted as

      "(x,y,z)"

      where x, y, z are floating point representations.

      Parameters:
      strTokens - token string representing values phase coordinates
      Throws:
      IllegalArgumentException - wrong number of tokens in argument (must be 6 or 7)
      NumberFormatException - bad numeric value, unparseable
    • R3

      public R3(DataAdaptor daSource)
      Initializing constructor for R3. Initial values are taken from the data source provided. The values are parsed from a numeric string and identified by the tag BaseVector#ATTR_Data.
      Parameters:
      daSource - interface to data source containing initialization data
      Since:
      Nov 5, 2013
  • Method Details

    • zero

      public static R3 zero()
      Create a new instance of the zero vector.
      Returns:
      zero vector
    • parse

      public static R3 parse(String strTokens) throws NumberFormatException, IllegalArgumentException
      Create a new instance of R3 with initial value determined by the formatted string argument. The string should be formatted as "(x,y,z)" where x, y, z are floating point representations.
      Parameters:
      strTokens - six-token string representing values phase coordinates
      Returns:
      3-vector built from the given string representation
      Throws:
      IllegalArgumentException - wrong number of tokens in argument (must be 6)
      NumberFormatException - bad numeric value, unparseable
    • copy

      public R3 copy()
      Performs a deep copy operation.
      Returns:
      cloned R3 object
    • set

      public void set(int i, double val) throws ArrayIndexOutOfBoundsException
      Set index to value.
      Parameters:
      i - element index 0<=i<=2
      val - new element value
      Throws:
      ArrayIndexOutOfBoundsException - the index i was greater than 2
    • set1

      public void set1(double x1)
      Set first coordinate value.
      Parameters:
      x1 - first coordinate of 3-vector
    • set2

      public void set2(double x2)
      Set second coordinate value.
      Parameters:
      x2 - second coordinate of 3-vector
    • set3

      public void set3(double x3)
      Set third coordinate value.
      Parameters:
      x3 - third coordinate of 3-vector
    • setx

      public void setx(double x)
      Set first coordinate value.
      Parameters:
      x - first coordinate of 3-vector
    • sety

      public void sety(double y)
      Set second coordinate value.
      Parameters:
      y - second coordinate of 3-vector
    • setz

      public void setz(double z)
      Set third coordinate value.
      Parameters:
      z - first coordinate of 3-vector
    • setAll

      public void setAll(double s)
      Set all coordinates to value
      Parameters:
      s - new value of all vector coordinates
    • toArray

      public double[] toArray()
      Get all the vector values as a 3-array.
      Returns:
      the array {x1, x2, x3}.
    • get1

      public double get1()
      Return first coordinate value.
      Returns:
      the first vector coordinate
    • get2

      public double get2()
      Return second coordinate value.
      Returns:
      the second coordinate vector
    • get3

      public double get3()
      Return third coordinate value.
      Returns:
      the third coordinate vector
    • getx

      public double getx()
      Return first coordinate value.
      Returns:
      the first coordinate vector
    • gety

      public double gety()
      Return second coordinate value.
      Returns:
      the second coordinate vector
    • getz

      public double getz()
      Return third coordinate value.
      Returns:
      the third coordinate vector
    • clone

      public R3 clone()
      Creates and returns a deep copy of this vector.
      Specified by:
      clone in class BaseVector<R3>
      Since:
      Jul 3, 2014
      See Also:
    • toString

      public String toString()
      Convert the vector contents to a string.
      Overrides:
      toString in class BaseVector<R3>
      Returns:
      vector value as a string (x, y, z)
    • cartesian2Cylindrical

      public R3 cartesian2Cylindrical()
      Apply coordinate transform from cartesian to cylindrical coordinates.
      Returns:
      polar coordinates (r,phi,z) of this cartesian point
    • cartesian2Spherical

      public R3 cartesian2Spherical()
      Apply coordinate transform from cartesian to spherical coordinates.
      Returns:
      polar coordinates (r, theta, phi) of this cartesian point
    • cylindrical2Cartesian

      public R3 cylindrical2Cartesian()
      Apply coordinate transform from cylindrical to cartesian coordinates
      Returns:
      cartesian coordinates (x,y,z) of this cylindrical point
    • spherical2Cartesian

      public R3 spherical2Cartesian()
      Apply coordinate tranform from spherical to cartesian coordinates
      Returns:
      cartesian coordinates (x,y,z) of this sphereical point
    • times

      public R3 times(R3 r)
      Vector multiplication using three-dimensional cross product.
      Parameters:
      r - second (right) operand in cross-product (this is first operand)
      Returns:
      result of vector cross product in three space
    • squared

      public R3 squared()
      Returns the vector of squared elements.
      Returns:
      the vector (x12, x22, x32)
      Since:
      Aug 25, 2011
    • newInstance

      protected R3 newInstance(int size)
      Handles object creation required by the base class.
      Specified by:
      newInstance in class BaseVector<R3>
      Returns:
      uninitialized vector object of type V
      Since:
      Jun 17, 2014
      See Also:
      • xal.tools.math.BaseVector#newInstance()
    • newInstance

      protected R3 newInstance(double[] arrVecInt)
      Description copied from class: BaseVector
      Creates a new instance of this vector type with the given Java array as the internal representation.
      Specified by:
      newInstance in class BaseVector<R3>
      Parameters:
      arrVecInt - new vector's guts
      Returns:
      new instance of this vector type with the internal representation
      Since:
      Jul 24, 2015 by Christopher K. Allen
      See Also: