Package renderer.scene
Class Vector
- java.lang.Object
-
- renderer.scene.Vector
-
public final class Vector extends Object
AVectorobject holds four doubles, which makes it a vector in 4-dimensional space.In computer graphics, we use 4-dimensional homogeneous coordinates to represent vectors (and points) in 3-dimensional space.
Unlike a homogeneous
Vertex, a homogeneousVectorusually has its fourth coordinate set to 0.
-
-
Constructor Summary
Constructors Constructor Description Vector(double x, double y, double z)Construct a newVectorusing the given x, y, and z coordinates.Vector(double x, double y, double z, double w)Construct a newVectorusing the given x, y, z, and w coordinates.Vector(Vertex v)Construct a newVectorfrom aVertex.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description VectorcrossProduct(Vector v)The cross-product of twoVectors returns a (new)Vector.doubledotProduct(Vector v)The dot-product of twoVectors returns a scalar.Vectorminus(Vector v)AVectorminus aVectorreturns a (new)Vector.Vectornormalize()Return the normalized version of thisVector.Vectorplus(Vector v)AVectorplus aVectorreturns a (new)Vector.Vertexplus(Vertex v)Vectortimes(double s)A scalar times aVectorreturns a (new)Vector.StringtoString()For debugging.StringtoString(int precision)For debugging.StringtoString(int precision, int iWidth)For debugging.
-
-
-
Constructor Detail
-
Vector
public Vector(double x, double y, double z)
Construct a newVectorusing the given x, y, and z coordinates.- Parameters:
x- x-coordinate of the newVectory- y-coordinate of the newVectorz- z-coordinate of the newVector
-
Vector
public Vector(double x, double y, double z, double w)
Construct a newVectorusing the given x, y, z, and w coordinates.This constructor is used to create the column vectors in a 4-by-4 homogeneous
Matrix.- Parameters:
x- x-coordinate of the newVectory- y-coordinate of the newVectorz- z-coordinate of the newVectorw- w-coordinate of the newVector
-
-
Method Detail
-
dotProduct
public double dotProduct(Vector v)
The dot-product of twoVectors returns a scalar.- Parameters:
v-Vectorobject to multiply with thisVector- Returns:
- a double that is the dot-product of this
Vectorandv
-
crossProduct
public Vector crossProduct(Vector v)
The cross-product of twoVectors returns a (new)Vector.- Parameters:
v-Vectorobject to multiply with thisVector- Returns:
- a new
Vectorobject that is the cross-product of thisVectorandv
-
times
public Vector times(double s)
A scalar times aVectorreturns a (new)Vector.- Parameters:
s- number to multiply thisVectorby- Returns:
- a new
Vectorobject that is the scalar times thisVector
-
plus
public Vector plus(Vector v)
AVectorplus aVectorreturns a (new)Vector.- Parameters:
v-Vectorobject to add to thisVector- Returns:
- a new
Vectorobject that is the sum of thisVectorandv
-
minus
public Vector minus(Vector v)
AVectorminus aVectorreturns a (new)Vector.- Parameters:
v-Vectorobject to subtract from thisVector- Returns:
- a new
Vectorobject that is thisVectorminusv
-
normalize
public Vector normalize()
Return the normalized version of thisVector.That is, return the
Vectorwith length 1 that points in the same direction as thisVector.- Returns:
- a new
Vectorthat has length one and has the same direction as thisVector
-
toString
public String toString(int precision)
For debugging.Allow the precision of the formatted output to be specified.
- Parameters:
precision- precision value for the format string- Returns:
Stringrepresentation of thisVectorobject
-
toString
public String toString(int precision, int iWidth)
For debugging.Allow the precision and width of the formatted output to be specified. By width, we mean the width of the integer part of each number.
- Parameters:
precision- precision value for the format stringiWidth- width of the integer part of the format string- Returns:
Stringrepresentation of thisVectorobject
-
-