1 package nl.tudelft.simulation.language.d3;
2
3 import java.awt.geom.Point2D;
4
5 import org.djutils.draw.point.Point3d;
6
7
8
9
10
11
12
13
14
15
16
17
18 public class CartesianPoint extends Point3d
19 {
20
21 private static final long serialVersionUID = 20191116L;
22
23
24
25
26
27
28
29 public CartesianPoint(final double x, final double y, final double z)
30 {
31 super(x, y, z);
32 }
33
34
35
36
37
38 public CartesianPoint(final double[] xyz)
39 {
40 super(xyz);
41 }
42
43
44
45
46
47 public CartesianPoint(final Point2D point2D)
48 {
49 this(point2D.getX(), point2D.getY(), 0);
50 }
51
52
53
54
55
56 public Point2D to2D()
57 {
58 return new Point2D.Double(this.getX(), this.getY());
59 }
60
61
62
63
64
65 public SphericalPoint toSphericalPoint()
66 {
67 return CartesianPoint.toSphericalPoint(this);
68 }
69
70
71
72
73
74
75 public static SphericalPoint toSphericalPoint(final CartesianPoint point)
76 {
77 double rho = Math.sqrt(Math.pow(point.getX(), 2) + Math.pow(point.getY(), 2) + Math.pow(point.getZ(), 2));
78 double theta = Math.atan2(point.getY(), point.getX());
79 double phi = Math.acos(point.getZ() / rho);
80 return new SphericalPoint(rho, theta, phi);
81 }
82
83
84 @Override
85 public String toString()
86 {
87 return "CartesianPoint [x=" + this.getX() + ", y=" + this.getY() + ", z=" + this.getZ() + "]";
88 }
89
90 }