Package util
Class Vector3D
java.lang.Object
util.Vector3D
-
Field Summary
Modifier and TypeFieldDescriptionprotected double[]
The 3 components of the vector in an array -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds a vector to the current vector Returns a new Vectorvoid
Adds a vector to the current vector Modifies the current vectordouble
Get the distance from the current vector to another vectordouble
Returns the scalar product of this and another vectorboolean
double
getMag()
Gets the magnitude of the vectordouble
getX()
Return the x component of the vectordouble
getY()
Return the y component of the vectordouble
getZ()
Return the z component of the vectorint
hashCode()
void
multLocal
(double scalar) Scalar multiply the current vector with a number Changes the current vectorvoid
set
(int i, double num) Method to set the vectors componentsvoid
setMag
(double new_mag) Sets the magnitude of the vectorSubtracts the other vector from this one Returns a new VecotrtoString()
Helper function to show the vector on the consolestatic Vector3D
zero()
Returns a zero vector (identity operation)
-
Field Details
-
vector
protected double[] vectorThe 3 components of the vector in an array
-
-
Constructor Details
-
Vector3D
public Vector3D()Create a vector where all components are set to zero -
Vector3D
public Vector3D(double x, double y, double z) Create a vector where the components are set to the parameters- Parameters:
x
- the desired x component of the vectory
- the desired y component of the vectorz
- the desired z component of the vector
-
Vector3D
public Vector3D(double[] arr) Create a vector where the components are set to a 3-dimensional array- Parameters:
arr
- the vector as a 3d array
-
-
Method Details
-
zero
Returns a zero vector (identity operation)- Returns:
- the zero vector
-
set
public void set(int i, double num) Method to set the vectors components- Parameters:
i
- the position of the componentnum
- the desired value of the component
-
getX
public double getX()Return the x component of the vector- Returns:
- the x component of the vector
-
getY
public double getY()Return the y component of the vector- Returns:
- the y component of the vector
-
getZ
public double getZ()Return the z component of the vector- Returns:
- the z component of the vector
-
getMag
public double getMag()Gets the magnitude of the vector- Returns:
- the magnitude of the vector
-
setMag
public void setMag(double new_mag) Sets the magnitude of the vector- Parameters:
new_mag
- the desired magnitude
-
addLocal
Adds a vector to the current vector Modifies the current vector- Parameters:
other
- the other vector to be added to this one
-
add
Adds a vector to the current vector Returns a new Vector- Parameters:
other
- the other vector to be added to this one- Returns:
- the new vector
-
sub
Subtracts the other vector from this one Returns a new Vecotr- Parameters:
other
- the other vector- Returns:
- the new vector
-
dot
Returns the scalar product of this and another vector- Parameters:
other
- the other vector- Returns:
- the scalar
-
multLocal
public void multLocal(double scalar) Scalar multiply the current vector with a number Changes the current vector- Parameters:
scalar
- the scalar
-
distTo
Get the distance from the current vector to another vector- Parameters:
other
- the other vector- Returns:
- the distance from the current to the other vector
-
toString
Helper function to show the vector on the console -
equals
-
hashCode
public int hashCode()
-