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 floating-point vector.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(float x, float y) div(float s) div(float x, float y) floatbooleanfloatgetAngle()floatfloatgetX()floatgetY()inthashCode()floatmax()floatmin()Computes mirrored vector, with respect to specified normal.Computes linear interpolation between two vectors.mul(float s) mul(float x, float y) Computes unit vector of same direction, or (1, 0) if zero.opposite()resized(float length) Resizes vector to specified length, or (length, 0) if zero.rotated(double angle) Computes rotated vector, in a counter-clockwise manner.round()sub(float x, float 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 float x -
y
public final float y
-
-
Constructor Details
-
Vector
public Vector(float x, float y) Creates a new vector.- Parameters:
x- (float): abscissay- (float): ordinate
-
-
Method Details
-
getX
public float getX()- Returns:
- (float): abscissa
-
getY
public float getY()- Returns:
- (float): ordinate
-
getLength
public float getLength()- Returns:
- (float): euclidian length
-
getAngle
public float getAngle()- Returns:
- (float): 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- (float): right-hand abcissay- (float): 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- (float): right-hand abcissay- (float): 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- (float): right-hand abcissay- (float): right-hand ordinate- Returns:
- (Vector): component-wise multiplication, not null
-
mul
- Parameters:
s- (float): 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- (float): right-hand abcissay- (float): right-hand ordinate- Returns:
- (Vector): component-wise division, not null
-
div
- Parameters:
s- (float): 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 float min()- Returns:
- (float): smallest component
-
max
- Parameters:
other- (Vector): right-hand operand, not null- Returns:
- (Vector): component-wise maximum, not null
-
max
public float max()- Returns:
- (float): 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- (float): 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- (float) weight of the second vector- Returns:
- (Vector): interpolated vector, not null
-
hashCode
public int hashCode() -
equals
-
toString
-