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 SummaryConstructors
- 
Method SummaryModifier 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- 
GVectorCopy constructor- Parameters:
- e-- GVectorto copy
- Throws:
- IllegalArgumentException- if- eis- null
 
- 
GVectorpublic GVector(int x, int y, double l, double a) Basic Vector constructor- Parameters:
- x- x coordinate of the application point of the vector
- y- y coordinate of the application point of the vector
- l- vector modulus
- a- vector angle (in degrees)
 
- 
GVectorCreates a new vector from a givenGLine, using the start point as the application point.- Parameters:
- line- the line to use as base for this- GVector
- Throws:
- IllegalArgumentException- if- lineis- null
 
- 
GVectorpublic GVector(int x1, int y1, int x2, int y2) Basic Vector constructor- Parameters:
- x1- x coordinate of the application point of the vector
- y1- y coordinate of the application point of the vector
- x2- x coordinate of the end of the vector
- y2- y coordinate of the end of the vector
 
 
- 
- 
Method Details- 
scalarMultiplicationpublic void scalarMultiplication(double scalar) Multiplies this vector by a scalar- Parameters:
- scalar- scale
 
- 
dotCalculates the dot product between this vector and the one passed as an argument- Parameters:
- v- other vector
- Returns:
- dot product
- Throws:
- IllegalArgumentException- if- vis- null
 
- 
crossCalculates 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- if- vis- null
 
- 
angleBetweenRetrieves the angle between this vector and the one passed as an argument- Parameters:
- v- other vector
- Returns:
- Angle between vectors (in degrees)
- Throws:
- IllegalArgumentException- if- vis- null
 
- 
radAngleBetweenRetrieves the angle between this vector and the one passed as an argument- Parameters:
- v- other vector
- Returns:
- Angle between vectors (in radians)
- Throws:
- IllegalArgumentException- if- vis- null
 
- 
normalizedRetrieves a vector with the same direction and application point but with a modulus equal to 1- Returns:
- normalized vector
 
- 
setModuluspublic void setModulus(double modulus) Changes the modulus of this vector- Parameters:
- modulus- new modulus of the vector
 
- 
setRadArgumentpublic void setRadArgument(double arg) Changes the argument of this vector (in radians)- Parameters:
- arg- new argument of the vector
 
- 
setArgumentpublic void setArgument(double arg) Changes the argument of this vector (in degrees)- Parameters:
- arg- new argument of the vector
 
- 
setArrowWeightpublic 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
 
- 
setArrowTipAnglepublic void setArrowTipAngle(double arrowAngle) Sets the new angle for the tip of the arrow (in degrees).- Parameters:
- arrowAngle- angle in degrees.
 
- 
xpublic int x()Retrieves the X coordinate of the point of application of the vector- Returns:
- x coordinate
 
- 
ypublic int y()Retrieves the Y coordinate of the point of application of the vector- Returns:
- y coordinate
 
- 
xfpublic int xf()Retrieves the X coordinate of the tip of the vector- Returns:
- X coordinate
 
- 
yfpublic int yf()Retrieves the Y coordinate of the tip of the vector- Returns:
- Y coordinate
 
- 
getXComponentpublic int getXComponent()Retrieves the X projection of this vector- Returns:
- x component
 
- 
getYComponentpublic int getYComponent()Retrieves the Y projection of this vector- Returns:
- y component
 
- 
moduluspublic double modulus()Retrieves the modulus of the vector- Returns:
- modulus
 
- 
argumentpublic double argument()Retrieves the argument of the vector (in degrees)- Returns:
- argument
 
- 
radArgumentpublic double radArgument()Retrieves the argument of the vector (in radians)- Returns:
- argument
 
- 
rotatepublic void rotate(double a) 
- 
radRotatepublic void radRotate(double a) 
- 
addAdds 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
- 
drawDescription copied from class:GraphicEDraws the component on the given graphics
- 
traslatepublic void traslate(int x, int y) Description copied from class:GraphicETraslates this element on X and Y
- 
movepublic void move(int x, int y) Moves the application point of this vector to the given coordinates- Parameters:
- x- new x coordinate
- y- new y coordinate
 
- 
clone
- 
hashCodepublic int hashCode()
- 
equals
 
-