Package ch.epfl.cs107.play.math
Class Vector
java.lang.Object
ch.epfl.cs107.play.math.Vector
- All Implemented Interfaces:
Serializable
Represents an immutable 2D doubleing-point vector.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(double x, double y) div(double s) div(double x, double y) doublebooleandoublegetAngle()doubledoublegetX()doublegetY()inthashCode()doublemax()doublemin()Computes mirrored vector, with respect to specified normal.Computes linear interpolation between two vectors.mul(double s) mul(double x, double y) Computes unit vector of same direction, or (1, 0) if zero.opposite()resized(double length) Resizes vector to specified length, or (length, 0) if zero.rotated(double angle) Computes rotated vector, in a counter-clockwise manner.round()sub(double x, double y) toString()
-
Field Details
-
EPSILON
public static final double EPSILONSmall value for double precision in vector comparison- See Also:
-
ZERO
The zero vector (0, 0) -
X
The unit X vector (1, 0) -
Y
The unit Y vector (0, 1) -
x
public final double x -
y
public final double y
-
-
Constructor Details
-
Vector
public Vector(double x, double y) Creates a new vector.- Parameters:
x- (double): abscissay- (double): ordinate
-
-
Method Details
-
getX
public double getX()- Returns:
- (double): abscissa
-
getY
public double getY()- Returns:
- (double): ordinate
-
getLength
public double getLength()- Returns:
- (double): euclidian length
-
getAngle
public double getAngle()- Returns:
- (double): angle in standard trigonometrical system, in radians
-
opposite
- Returns:
- (Vector): negated vector
-
add
- Parameters:
other- (Vector): right-hand operand, not null- Returns:
- (Vector): sum, not null
-
add
- Parameters:
x- (double): right-hand abcissay- (double): right-hand ordinate- Returns:
- (Vector): sum, not null
-
sub
- Parameters:
other- (Vector): right-hand operand, not null- Returns:
- (Vector): difference, not null
-
sub
- Parameters:
x- (double): right-hand abcissay- (double): right-hand ordinate- Returns:
- (Vector): difference, not null
-
mul
- Parameters:
other- (Vector): right-hand operand, not null- Returns:
- (Vector): component-wise multiplication, not null
-
mul
- Parameters:
x- (double): right-hand abcissay- (double): right-hand ordinate- Returns:
- (Vector): component-wise multiplication, not null
-
mul
- Parameters:
s- (double): right-hand operand- Returns:
- (Vector): scaled vector, not null
-
div
- Parameters:
other- (Vector): right-hand operand, not null- Returns:
- (Vector): component-wise division, not null
-
div
- Parameters:
x- (double): right-hand abcissay- (double): right-hand ordinate- Returns:
- (Vector): component-wise division, not null
-
div
- Parameters:
s- (double): right-hand operand- Returns:
- (Vector):scaled vector, not null
-
dot
- Parameters:
other- (Vector): right-hand operand, not null- Returns:
- (Vector): dot product
-
min
- Parameters:
other- (Vector): right-hand operand, not null- Returns:
- (Vector): component-wise minimum, not null
-
min
public double min()- Returns:
- (double): smallest component
-
max
- Parameters:
other- (Vector): right-hand operand, not null- Returns:
- (Vector): component-wise maximum, not null
-
max
public double max()- Returns:
- (double): largest component
-
normalized
Computes unit vector of same direction, or (1, 0) if zero.- Returns:
- (Vector): rescaled vector, not null
-
resized
Resizes vector to specified length, or (length, 0) if zero.- Parameters:
length- (double): new length- Returns:
- (Vector): rescaled vector, not null
-
mirrored
Computes mirrored vector, with respect to specified normal.- Parameters:
normal- (Vector): vector perpendicular to the symmetry plane, not null- Returns:
- (Vector): rotated vector, not null
-
rotated
Computes rotated vector, in a counter-clockwise manner.- Parameters:
angle- (double): rotation, in radians- Returns:
- (Vector): rotated vector, not null
-
clockwise
- Returns:
- (Vector): vector rotated by -90°, not null
-
counterClockwise
- Returns:
- (Vector): vector rotated by 90°, not null
-
round
- Returns:
- (Vector): a rounded vector (x and y rounded to the closest int)
-
mixed
Computes linear interpolation between two vectors.- Parameters:
other- (Vector): second vector, not nullfactor- (double) weight of the second vector- Returns:
- (Vector): interpolated vector, not null
-
hashCode
public int hashCode() -
equals
-
toString
-