1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package math.geom3d;
28
29 import javax.vecmath.Tuple3d;
30
31 import math.geom3d.transform.AffineTransform3D;
32
33
34
35
36 public class Point3D implements Shape3D {
37
38 private double x = 0;
39 private double y = 0;
40 private double z = 0;
41
42
43
44
45 public Point3D() {
46 this(0, 0, 0);
47 }
48
49 public Point3D(double x, double y, double z) {
50 this.x = x;
51 this.y = y;
52 this.z = z;
53 }
54
55 public Point3D(Tuple3d point) {
56 this.x = point.getX();
57 this.y = point.getY();
58 this.z = point.getZ();
59 }
60
61 public double getX() {
62 return x;
63 }
64
65 public double getY() {
66 return y;
67 }
68
69 public double getZ() {
70 return z;
71 }
72
73 public void setX(double x) {
74 this.x = x;
75 }
76
77 public void setY(double y) {
78 this.y = y;
79 }
80
81 public void setZ(double z) {
82 this.z = z;
83 }
84
85 public void setLocation(Point3D point) {
86 x = point.getX();
87 y = point.getY();
88 z = point.getZ();
89 }
90
91 public void setLocation(double x, double y, double z) {
92 this.x = x;
93 this.y = y;
94 this.z = z;
95 }
96
97 public double getDistance(Point3D point) {
98 double dx = point.x-x;
99 double dy = point.y-y;
100 double dz = point.z-z;
101
102 return Math.hypot(Math.hypot(dx, dy), dz);
103 }
104
105
106
107
108
109 public boolean contains(Point3D point) {
110 if (getDistance(point)>ACCURACY)
111 return false;
112 return true;
113 }
114
115 public boolean isEmpty() {
116 return false;
117 }
118
119 public boolean isBounded() {
120 return true;
121 }
122
123 public Box3D getBoundingBox() {
124 return new Box3D(x, x, y, y, z, z);
125 }
126
127 public Shape3D clip(Box3D box) {
128 if (x<box.getMinX()||x>box.getMaxX())
129 return Shape3D.EMPTY_SET;
130 if (y<box.getMinY()||y>box.getMaxY())
131 return Shape3D.EMPTY_SET;
132 if (z<box.getMinZ()||z>box.getMaxZ())
133 return Shape3D.EMPTY_SET;
134 return this;
135 }
136
137 public Point3D transform(AffineTransform3D trans) {
138 Point3D res = new Point3D();
139 trans.transformPoint(this, res);
140 return res;
141 }
142
143
144
145
146 @Override
147 public boolean equals(Object obj) {
148 if (!(obj instanceof Point3D))
149 return false;
150 Point3D point = (Point3D) obj;
151
152 if (Math.abs(point.x-this.x)>Shape3D.ACCURACY)
153 return false;
154 if (Math.abs(point.y-this.y)>Shape3D.ACCURACY)
155 return false;
156 if (Math.abs(point.z-this.z)>Shape3D.ACCURACY)
157 return false;
158 return true;
159 }
160 }