Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / util / Point3D.java @ 10590

History | View | Annotate | Download (2.33 KB)

1
/*
2
 *
3
 * Este codigo se distribuye bajo licencia GPL
4
 * de GNU. Para obtener una c?pia integra de esta
5
 * licencia acude a www.gnu.org.
6
 * 
7
 * Este software se distribuye "como es". AGIL
8
 * solo  pretende desarrollar herramientas para
9
 * la promoci?n del GIS Libre.
10
 * AGIL no se responsabiliza de las perdidas econ?micas o de 
11
 * informaci?n derivadas del uso de este software.
12
 */
13

    
14

    
15
package com.iver.cit.jdwglib.util;
16

    
17
/**
18
 *  3dim double point. A point is transformed different than a vector.
19
 *  The class is now declared final to allow a more aggresive optimization.
20
 *
21
 *  @see       dxfviewer.math.Vector3D;
22
 *
23
 *  @version   1.10,?01/13/99
24
 */
25
public final class Point3D {
26
  public double   x, y, z;     // coordinates, allowing direct access
27

    
28
  /**
29
   *
30
   */
31
  public Point3D() {
32
  }
33

    
34
  /**
35
   *  Copy constructor.
36
   *  @param  p    point to copy
37
   */
38
  public Point3D(Point3D p) {
39
        x = p.x;
40
        y = p.y;
41
        z = p.z;
42
  }
43

    
44
  /**
45
   *  @param   xx    x coord
46
   *  @param   yy    y coord
47
   *  @param   zz    z coord
48
   */
49
  public Point3D(double xx, double yy, double zz) {
50
        x = xx;
51
        y = yy;
52
        z = zz;
53
  }
54

    
55
  /**
56
   *  Scale.
57
   *  @param   f     scaling factor
58
   */
59
  public void scale(double f) {
60
        if (f != 1f) {
61
          x *= f;
62
          y *= f;
63
          z *= f;
64
        }
65
  }
66

    
67
  /**
68
   *  Add a vector.
69
   *  @param  v      vector to add
70
   */
71
  public void add(Vector3D v) {
72
        x += v.x;
73
        y += v.y;
74
        z += v.z;
75
  }
76

    
77
  /**
78
   *  Get sum with vector.
79
   *  @param  v     vector to add
80
   *  @return this+v
81
   */
82
  public Point3D plus(Vector3D v) {
83
        Point3D ret = new Point3D(this);
84
        ret.add(v);
85
        return ret;
86
  }
87

    
88
  /**
89
   *  Substract a vector.
90
   *  @param  v     vector to substract
91
   */
92
  public void sub(Vector3D v) {
93
        x -= v.x;
94
        y -= v.y;
95
        z -= v.z;
96
  }
97

    
98
  /**
99
   *  Get difference with vector.
100
   *  @param  v     vector to substract
101
   *  @return this-v
102
   */
103
  public Point3D minus(Vector3D v) {
104
        Point3D ret = new Point3D(this);
105
        ret.sub(v);
106
        return ret;
107
  }
108

    
109
  /**
110
   *  Get difference with point.
111
   *  @param  p     point to substract
112
   *  @return this-p
113
   */
114
  public Vector3D minus(Point3D p) {
115
        Vector3D ret = new Vector3D(this);
116
        ret.sub(new Vector3D(p));
117
        return ret;
118
  }
119

    
120
  /**
121
   *  Output.
122
   *  @return  output string
123
   */
124
  public String toString() {
125
        return new String(new StringBuffer().append("[").append(x).append(",").append(y).append(",").append(z).append("]"));
126
  }
127
}
128

    
129