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
-
Method Summary
Modifier and TypeMethodDescriptionAdds a finite number of vectors with no overflow checkdouble
Retrieves the angle between this vector and the one passed as an argumentdouble
argument()
Retrieves the argument of the vector (in degrees)clone()
double
Calculates the module of the orthogonal vector resulting of the cross product between this vector and the one passed as an argument, considering thez
coordinate of both vectors equal to zerodouble
double
Calculates the dot product between this vector and the one passed as an argumentvoid
draw
(Graphics2D g) Draws the component on the given graphicsboolean
int
Retrieves the X projection of this vectorint
Retrieves the Y projection of this vectorint
hashCode()
double
modulus()
Retrieves the modulus of the vectorvoid
move
(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 1double
Retrieves the angle between this vector and the one passed as an argumentdouble
Retrieves the argument of the vector (in radians)void
radRotate
(double a) void
rotate
(double a) void
scalarMultiplication
(double scalar) Multiplies this vector by a scalarvoid
setArgument
(double arg) Changes the argument of this vector (in degrees)void
setArrowTipAngle
(double arrowAngle) Sets the new angle for the tip of the arrow (in degrees).void
setArrowWeight
(int arrowWeight) Changes the arrow weight.void
setModulus
(double modulus) Changes the modulus of this vectorvoid
setRadArgument
(double arg) Changes the argument of this vector (in radians)void
traslate
(int x, int y) Traslates this element on X and Yint
x()
Retrieves the X coordinate of the point of application of the vectorint
xf()
Retrieves the X coordinate of the tip of the vectorint
y()
Retrieves the Y coordinate of the point of application of the vectorint
yf()
Retrieves the Y coordinate of the tip of the vector
-
Constructor Details
-
GVector
Copy constructor- Parameters:
e
-GVector
to copy- Throws:
IllegalArgumentException
- ife
isnull
-
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
- ifline
isnull
-
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
- ifv
isnull
-
cross
Calculates the module of the orthogonal vector resulting of the cross product between this vector and the one passed as an argument, considering thez
coordinate of both vectors equal to zero- Parameters:
v
- other vector- Returns:
- module of the cross product vector
- Throws:
IllegalArgumentException
- ifv
isnull
-
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
- ifv
isnull
-
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
- ifv
isnull
-
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 ifarrowWeight
is 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
GVector
equal to the resultant - Throws:
IllegalArgumentException
- if no vector is passed
-
subtract
-
distance
-
draw
Description copied from class:GraphicE
Draws the component on the given graphics -
traslate
public void traslate(int x, int y) Description copied from class:GraphicE
Traslates 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
-