Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: alice/util/V2d.java


1   /*
2    *   V2d.java
3    *
4    * Copyright 2000-2001 deis.unibo.it
5    *
6    * This software is the proprietary information of deis.unibo.it
7    * Use is subject to license terms.
8    *
9    */
10  package alice.util;
11  
12  /**
13   *
14   * 2-dimensional vector
15   * objects are completely state-less
16   *
17   */
18  public class V2d implements java.io.Serializable {
19  
20      public float x,y;
21  
22      public V2d(float x,float y){
23          this.x=x;
24          this.y=y;
25      }
26  
27      public V2d sum(V2d v){
28          return new V2d(x+v.x,y+v.y);
29      }
30  
31      public float abs(){
32          return (float)Math.sqrt(x*x+y*y);
33      }
34  
35      public V2d getNormalized(){
36          float module=(float)Math.sqrt(x*x+y*y);
37          return new V2d(x/module,y/module);
38      }
39  
40      public V2d mul(float fact){
41          return new V2d(x*fact,y*fact);
42      }
43  
44      public String toString(){
45          return "V2d("+x+","+y+")";
46      }
47  }