Package com.xebisco.yield
Class Vector2D
java.lang.Object
com.xebisco.yield.Vector2D
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ImmutableVector2D
Represents a 2D vector, points and sizes.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabsolute()This method returns a new Vector2D object with absolute values of x and y coordinates.The function returns the absolute value of the x and y coordinates of a Vector2D object.doubleangle()This Java function calculates the angle in degrees between the positive x-axis and a point represented by its x and y coordinates using the Math.atan2() and Math.toDegrees() methods.divide(double value) This Java function returns a new Vector2D object that is the result of dividing the current object by the input object.divideLocal(double value) Divide the x and y values of this object by the x and y values of the given object.doubleheight()doubleThis Java function calculates the intensity of a vector using the Pythagorean theorem.invert()The function inverts a Vector2D object by multiplying it with a new object with negative values.This function inverts a Vector2D object locally by multiplying it with -1.multiply(double value) This method returns the result of multiplying two instances of the Vector2D class.multiplyLocal(double value) This method multiplies the x and y values of a Vector2D object by a given value and returns the object.Multiply the x and y values of this object by the x and y values of the given object.reset()Resets thisVector2Dinstance to the origin(0, 0).set(double x, double y) Sets the x and y coordinates of thisVector2Dinstance.setX(double x) This function sets the value of the x variable to the value of the x parameter.setY(double y) This function sets the y coordinate of the point to the value of the parameter y.toString()static Vector2Dvector2D(int degrees, double intensity) The function returns a 2D vector with a given angle in degrees and intensity.doublewidth()doublex()This function returns the value of the x variable.doubley()This function returns the y coordinate of the point.
-
Constructor Details
-
Vector2D
public Vector2D(double x, double y) Constructs a newVector2Dinstance with the specified x and y coordinates.- Parameters:
x- the x coordinate of the vectory- the y coordinate of the vector
-
Vector2D
public Vector2D()Constructs a newVector2Dinstance. -
Vector2D
- Parameters:
a- theVector2Dobject to copy
-
-
Method Details
-
set
Sets the x and y coordinates of thisVector2Dinstance.- Parameters:
x- the new x coordinatey- the new y coordinate- Returns:
- this
Vector2Dinstance for method chaining
-
reset
Resets thisVector2Dinstance to the origin(0, 0).- Returns:
- this
Vector2Dinstance for method chaining
-
set
-
sumLocal
-
sum
-
subtractLocal
-
subtract
-
multiplyLocal
Multiply the x and y values of this object by the x and y values of the given object.- Parameters:
a- The Vector2D to multiply this Vector2D by.
-
multiplyLocal
This method multiplies the x and y values of a Vector2D object by a given value and returns the object.- Parameters:
value- The parameter "value" is a double type variable that represents the value by which the x and y coordinates of the Vector2D object are multiplied.- Returns:
- The method is returning this instance of the `Vector2D`.
-
multiply
This method returns the result of multiplying two instances of the Vector2D class.- Parameters:
a- The parameter "a" is a Vector2D object that is being passed as an argument to the "multiply" method.- Returns:
- A new instance of the `Vector2D` class is being returned. The new instance is created by calling the `multiplyLocal` method on the current instance of `Vector2D` with the argument `a`.
-
multiply
-
divideLocal
Divide the x and y values of this object by the x and y values of the given object.- Parameters:
a- The Vector2D to divide by.
-
divideLocal
-
divide
This Java function returns a new Vector2D object that is the result of dividing the current object by the input object.- Parameters:
a- The parameter "a" is a Vector2D object that is being passed as an argument to the "divide" method.- Returns:
- A new instance of the `Vector2D` class is being returned, which is the result of dividing the current instance by the `a` parameter using the `divideLocal` method.
-
divide
-
absoluteLocal
The function returns the absolute value of the x and y coordinates of a Vector2D object.- Returns:
- The method is returning this instance of the `Vector2D` class.
-
absolute
This method returns a new Vector2D object with absolute values of x and y coordinates.- Returns:
- A new instance of the `Vector2D` class is being returned, which is created using the `x` and `y` values of the current instance. The `absoluteLocal()` method is then called on the new instance to modify its values, but the modified instance is not returned.
-
invertLocal
This function inverts a Vector2D object locally by multiplying it with -1.- Returns:
- The method is returning this `Vector2D` object.
-
invert
The function inverts a Vector2D object by multiplying it with a new object with negative values.- Returns:
- The method is returning a new instance of the `Vector2D` class that is the result of multiplying the current instance with a new instance of `Vector2D` that has the values `-1` for both anchors. This new instance is effectively the inverse of the current instance.
-
x
public double x()This function returns the value of the x variable.- Returns:
- The value of the x variable.
-
setX
This function sets the value of the x variable to the value of the x parameter.- Parameters:
x- The x coordinate of the point.
-
y
public double y()This function returns the y coordinate of the point.- Returns:
- The y coordinate of the point.
-
setY
This function sets the y coordinate of the point to the value of the parameter y.- Parameters:
y- The y coordinate of the point.
-
toString
-
vector2D
The function returns a 2D vector with a given angle in degrees and intensity.- Parameters:
degrees- The angle in degrees that the vector makes with the positive x-axis.intensity- The intensity parameter represents the magnitude or length of the vector. It determines how long the vector will be.- Returns:
- A new instance of the Vector2D class with x and y components calculated based on the input degrees and intensity values.
-
angle
public double angle()This Java function calculates the angle in degrees between the positive x-axis and a point represented by its x and y coordinates using the Math.atan2() and Math.toDegrees() methods.- Returns:
- The method `calculateDegrees()` returns the angle in degrees between the positive x-axis and the vector represented by the point (x,y) in the Cartesian coordinate system. It uses the `Math.atan2()` method to calculate the angle in radians and then converts it to degrees using the `Math.toDegrees()` method.
-
intensity
public double intensity()This Java function calculates the intensity of a vector using the Pythagorean theorem.- Returns:
- The method `calculateIntensity` is returning the intensity of a vector, which is calculated as the square root of the sum of the squares of its components (x and y).
-
width
public double width() -
height
public double height()
-