Package renderer.scene
Class Vector
- java.lang.Object
-
- renderer.scene.Vector
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector
crossProduct(Vector v)
The cross-product of twoVector
s returns a (new)Vector
.double
dotProduct(Vector v)
The dot-product of twoVector
s returns a scalar.Vector
minus(Vector v)
AVector
minus aVector
returns a (new)Vector
.Vector
normalize()
Return the normalized version of thisVector
.Vector
plus(Vector v)
AVector
plus aVector
returns a (new)Vector
.Vertex
plus(Vertex v)
Vector
times(double s)
A scalar times aVector
returns a (new)Vector
.String
toString()
For debugging.String
toString(int precision)
For debugging.String
toString(int precision, int iWidth)
For debugging.
-
-
-
Constructor Detail
-
Vector
public Vector(double x, double y, double z)
Construct a newVector
using the given x, y, and z coordinates.- Parameters:
x
- x-coordinate of the newVector
y
- y-coordinate of the newVector
z
- z-coordinate of the newVector
-
-
Method Detail
-
dotProduct
public double dotProduct(Vector v)
The dot-product of twoVector
s returns a scalar.- Parameters:
v
-Vector
object to multiply with thisVector
- Returns:
- a double that is the dot-product of this
Vector
andv
-
crossProduct
public Vector crossProduct(Vector v)
The cross-product of twoVector
s returns a (new)Vector
.- Parameters:
v
-Vector
object to multiply with thisVector
- Returns:
- a new
Vector
object that is the cross-product of thisVector
andv
-
times
public Vector times(double s)
A scalar times aVector
returns a (new)Vector
.- Parameters:
s
- number to multiply thisVector
by- Returns:
- a new
Vector
object that is the scalar times thisVector
-
plus
public Vector plus(Vector v)
AVector
plus aVector
returns a (new)Vector
.- Parameters:
v
-Vector
object to add to thisVector
- Returns:
- a new
Vector
object that is the sum of thisVector
andv
-
minus
public Vector minus(Vector v)
AVector
minus aVector
returns a (new)Vector
.- Parameters:
v
-Vector
object to subtract from thisVector
- Returns:
- a new
Vector
object that is thisVector
minusv
-
normalize
public Vector normalize()
Return the normalized version of thisVector
.That is, return the
Vector
with length 1 that points in the same direction as thisVector
.- Returns:
- a new
Vector
that 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:
String
representation of thisVector
object
-
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:
String
representation of thisVector
object
-
-