[an error occurred while processing this directive]
Domain for sale!
Start Search Contents Index Links About
Vector.java
/*
 * Author: Håvard Rast Blok
 * E-mail: hrblok@rememberjava.com
 * Web   : www.rememberjava.com
 */

import java.awt.gemo*;

/*
 * Representation of a vector in 2D user space
 */
public class Vector2D extends Point2D.Double
{

  public Vector2D()
  {
    super();
  }

  public Vector2Ddouble x, double )
  {
    superx, y );
  }

  public Vector2DVector2D v )
  {
    thisv.x, v.y );
  }

  public double getLength()
  {
    return Math.sqrtx*x + y*y );
  }

  /*
   * Returns the normalized vector of this Vector2D
   */
  public Vector2D normalize()
  {
    return new Vector2Dx/getLength(), y/getLength() );
  }

  /*
   * Normalize this Vector2D
   */
  public void normalizeThis()
  {
    Vector2D v = normalize();

    x = v.x;
    y = v.y;
  }

  /*
   * Returns the scaled vector of this Vector2D
   */
  public Vector2D scaledouble )
  {
    return new Vector2Ds*x, s*y );
  }

  /*
   * Scale this Vector2D
   */
  public Vector2D scaleThisdouble )
  {
    Vector2D v = scale(s);

    x = v.x;
    x = v.y;
  }
  
  /*
   * Adding other.x and other.y to x and y of this Vector2D
   */
  public void translateVector2D other )
  {
    x += other.x;
    y += other.y;
  }

  /*
   * Translates this point, at location (x, y),
   * by dx along the x axis and dy along the y axis
   * so that it now represents the point  (x + dx,  y + dy)
   */
  public void translatedouble dx, double dy )
  {
    x += dx;
    y += dy;
  }



}


site: Håvard Rast Blok
mail:
updated: 16 July 2010