Package com.dkt.graphics.elements
Class GVector
java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.elements.GVector
- All Implemented Interfaces:
Cloneable
This class represents a Vector, basically a line with a triangular tip.
If the modulus of the vector is
If the modulus of the vector is
0 then not even the triangle is
drawn.- Author:
- Federico Vera <[email protected]>
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a finite number of vectors with no overflow checkdoubleRetrieves the angle between this vector and the one passed as an argumentdoubleargument()Retrieves the argument of the vector (in degrees)clone()doubleCalculates the module of the orthogonal vector resulting of the cross product between this vector and the one passed as an argument, considering thezcoordinate of both vectors equal to zerodoubledoubleCalculates the dot product between this vector and the one passed as an argumentvoiddraw(Graphics2D g) Draws the component on the given graphicsbooleanintRetrieves the X projection of this vectorintRetrieves the Y projection of this vectorinthashCode()doublemodulus()Retrieves the modulus of the vectorvoidmove(int x, int y) Moves the application point of this vector to the given coordinatesRetrieves a vector with the same direction and application point but with a modulus equal to 1doubleRetrieves the angle between this vector and the one passed as an argumentdoubleRetrieves the argument of the vector (in radians)voidradRotate(double a) voidrotate(double a) voidscalarMultiplication(double scalar) Multiplies this vector by a scalarvoidsetArgument(double arg) Changes the argument of this vector (in degrees)voidsetArrowTipAngle(double arrowAngle) Sets the new angle for the tip of the arrow (in degrees).voidsetArrowWeight(int arrowWeight) Changes the arrow weight.voidsetModulus(double modulus) Changes the modulus of this vectorvoidsetRadArgument(double arg) Changes the argument of this vector (in radians)voidtraslate(int x, int y) Traslates this element on X and Yintx()Retrieves the X coordinate of the point of application of the vectorintxf()Retrieves the X coordinate of the tip of the vectorinty()Retrieves the Y coordinate of the point of application of the vectorintyf()Retrieves the Y coordinate of the tip of the vector
-
Constructor Details
-
GVector
Copy constructor- Parameters:
e-GVectorto copy- Throws:
IllegalArgumentException- ifeisnull
-
GVector
public GVector(int x, int y, double l, double a) Basic Vector constructor- Parameters:
x- x coordinate of the application point of the vectory- y coordinate of the application point of the vectorl- vector modulusa- vector angle (in degrees)
-
GVector
Creates a new vector from a givenGLine, using the start point as the application point.- Parameters:
line- the line to use as base for thisGVector- Throws:
IllegalArgumentException- iflineisnull
-
GVector
public GVector(int x1, int y1, int x2, int y2) Basic Vector constructor- Parameters:
x1- x coordinate of the application point of the vectory1- y coordinate of the application point of the vectorx2- x coordinate of the end of the vectory2- y coordinate of the end of the vector
-
-
Method Details
-
scalarMultiplication
public void scalarMultiplication(double scalar) Multiplies this vector by a scalar- Parameters:
scalar- scale
-
dot
Calculates the dot product between this vector and the one passed as an argument- Parameters:
v- other vector- Returns:
- dot product
- Throws:
IllegalArgumentException- ifvisnull
-
cross
Calculates the module of the orthogonal vector resulting of the cross product between this vector and the one passed as an argument, considering thezcoordinate of both vectors equal to zero- Parameters:
v- other vector- Returns:
- module of the cross product vector
- Throws:
IllegalArgumentException- ifvisnull
-
angleBetween
Retrieves the angle between this vector and the one passed as an argument- Parameters:
v- other vector- Returns:
- Angle between vectors (in degrees)
- Throws:
IllegalArgumentException- ifvisnull
-
radAngleBetween
Retrieves the angle between this vector and the one passed as an argument- Parameters:
v- other vector- Returns:
- Angle between vectors (in radians)
- Throws:
IllegalArgumentException- ifvisnull
-
normalized
Retrieves a vector with the same direction and application point but with a modulus equal to 1- Returns:
- normalized vector
-
setModulus
public void setModulus(double modulus) Changes the modulus of this vector- Parameters:
modulus- new modulus of the vector
-
setRadArgument
public void setRadArgument(double arg) Changes the argument of this vector (in radians)- Parameters:
arg- new argument of the vector
-
setArgument
public void setArgument(double arg) Changes the argument of this vector (in degrees)- Parameters:
arg- new argument of the vector
-
setArrowWeight
public void setArrowWeight(int arrowWeight) Changes the arrow weight.
The arrow weight is defined as the length of the arrow, by default the arrow will be appended to the line, but ifarrowWeightis negative then the arrow will end at the end of the line.- Parameters:
arrowWeight- new arrow weight
-
setArrowTipAngle
public void setArrowTipAngle(double arrowAngle) Sets the new angle for the tip of the arrow (in degrees).- Parameters:
arrowAngle- angle in degrees.
-
x
public int x()Retrieves the X coordinate of the point of application of the vector- Returns:
- x coordinate
-
y
public int y()Retrieves the Y coordinate of the point of application of the vector- Returns:
- y coordinate
-
xf
public int xf()Retrieves the X coordinate of the tip of the vector- Returns:
- X coordinate
-
yf
public int yf()Retrieves the Y coordinate of the tip of the vector- Returns:
- Y coordinate
-
getXComponent
public int getXComponent()Retrieves the X projection of this vector- Returns:
- x component
-
getYComponent
public int getYComponent()Retrieves the Y projection of this vector- Returns:
- y component
-
modulus
public double modulus()Retrieves the modulus of the vector- Returns:
- modulus
-
argument
public double argument()Retrieves the argument of the vector (in degrees)- Returns:
- argument
-
radArgument
public double radArgument()Retrieves the argument of the vector (in radians)- Returns:
- argument
-
rotate
public void rotate(double a) -
radRotate
public void radRotate(double a) -
add
Adds a finite number of vectors with no overflow check- Parameters:
vectors- the vectors to add- Returns:
- A new
GVectorequal to the resultant - Throws:
IllegalArgumentException- if no vector is passed
-
subtract
-
distance
-
draw
Description copied from class:GraphicEDraws the component on the given graphics -
traslate
public void traslate(int x, int y) Description copied from class:GraphicETraslates this element on X and Y -
move
public void move(int x, int y) Moves the application point of this vector to the given coordinates- Parameters:
x- new x coordinatey- new y coordinate
-
clone
-
hashCode
public int hashCode() -
equals
-