Class GPVector

java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.extras.GPVector
All Implemented Interfaces:
Cloneable

public class GPVector extends GraphicE
This class represents a vector and it's projections, it's mainly used in physics problems where you need to print how the orthogonal components of a vector changes
Author:
Federico Vera <[email protected]>
  • Constructor Details

    • GPVector

      public GPVector(GPVector e)
    • GPVector

      public GPVector(GVector v)
      Creates a new GPVector based on the GVector passed as argument.
      Note: this constructor uses a COPY of the vector, so if you need to change some parameters of the vector, you'll need to use:
      Parameters:
      v - the vector used as base
      Throws:
      IllegalArgumentException - if v is null
    • GPVector

      public GPVector(int x, int y, double l, double a)
      Creates a new GPVector
      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)
  • Method Details

    • setModulus

      public void setModulus(double m)
      Sets a new modulus to the main vector (that will also change the components)
      Parameters:
      m - modulus
    • setModulus

      public void setModulus(double x, double y)
      Sets a new modulus and argument to the main vector based on the modulus of the orthogonal components
      Parameters:
      x - x component
      y - y component
    • setArgument

      public void setArgument(double a)
      Changes the argument of the main vector
      Parameters:
      a - argument in degrees
    • setPaint

      public void setPaint(Paint paint)
      Sets the Paint for the main vector
      Overrides:
      setPaint in class GraphicE
      Parameters:
      paint - the paint use to render the main vector
      Throws:
      IllegalArgumentException - if paint is null
    • setHCompPaint

      public void setHCompPaint(Paint paint)
      Sets the Paint for the horizontal component of this vector
      Parameters:
      paint - the paint use to render the horizontal component
      Throws:
      IllegalArgumentException - if paint is null
    • setVCompPaint

      public void setVCompPaint(Paint paint)
      Sets the Paint for the vertical component of this vector
      Parameters:
      paint - the paint use to render the vertical component
      Throws:
      IllegalArgumentException - if paint is null
    • move

      public void move(int x, int y)
      Moves the start point of this vector to the selected coordinates
      Parameters:
      x - new x coordinate
      y - new y coordinate
    • clone

      public GPVector clone()
      Specified by:
      clone in class GraphicE
    • traslate

      public void traslate(int x, int y)
      Description copied from class: GraphicE
      Traslates this element on X and Y
      Specified by:
      traslate in class GraphicE
      Parameters:
      x - size in px of the horizontal translation
      y - size in px of the vertical translation
    • draw

      public void draw(Graphics2D g)
      Description copied from class: GraphicE
      Draws the component on the given graphics
      Specified by:
      draw in class GraphicE
      Parameters:
      g - where to draw