View Javadoc

1   /*
2    * @(#) CartesianPoint.java Nov 12, 2003
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.language.d3;
11  
12  import java.awt.geom.Point2D;
13  
14  import javax.vecmath.Point3f;
15  import javax.vecmath.Tuple3d;
16  import javax.vecmath.Tuple3f;
17  
18  /***
19   * The Point3D class with utilities to convert to point2D where the z-axis is
20   * neglected <br>
21   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
22   * University of Technology </a>, the Netherlands. <br>
23   * See for project information <a
24   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
25   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
26   * License (GPL) </a>, no warranty <br>
27   * 
28   * @version 1.0 12.11.2003 <br>
29   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
30   *         Jacobs </a>
31   */
32  public class CartesianPoint extends javax.vecmath.Point3d
33  {
34  	/***
35  	 * constructs a new CartesianPoint
36  	 * 
37  	 * @param x x
38  	 * @param y y
39  	 * @param z z
40  	 */
41  	public CartesianPoint(final double x, final double y, final double z)
42  	{
43  		super(x, y, z);
44  	}
45  
46  	/***
47  	 * constructs a new CartesianPoint
48  	 * 
49  	 * @param xyz x,y,z
50  	 */
51  	public CartesianPoint(final double[] xyz)
52  	{
53  		super(xyz);
54  	}
55  
56  	/***
57  	 * constructs a new CartesianPoint
58  	 * 
59  	 * @param point point3d
60  	 */
61  	public CartesianPoint(final javax.vecmath.Point3d point)
62  	{
63  		super(point);
64  	}
65  
66  	/***
67  	 * constructs a new CartesianPoint
68  	 * 
69  	 * @param point point3d
70  	 */
71  	public CartesianPoint(final Point3f point)
72  	{
73  		super(point);
74  	}
75  
76  	/***
77  	 * constructs a new CartesianPoint
78  	 * 
79  	 * @param tuple tuple
80  	 */
81  	public CartesianPoint(final Tuple3f tuple)
82  	{
83  		super(tuple);
84  	}
85  
86  	/***
87  	 * constructs a new CartesianPoint
88  	 * 
89  	 * @param tuple point3d
90  	 */
91  	public CartesianPoint(final Tuple3d tuple)
92  	{
93  		super(tuple);
94  	}
95  
96  	/***
97  	 * constructs a new CartesianPoint
98  	 * 
99  	 * @param point2D a 2D point
100 	 */
101 	public CartesianPoint(final Point2D point2D)
102 	{
103 		this(point2D.getX(), point2D.getY(), 0);
104 	}
105 
106 	/***
107 	 * constructs a new CartesianPoint
108 	 */
109 	public CartesianPoint()
110 	{
111 		super();
112 	}
113 
114 	/***
115 	 * returns the 2D representation of the point
116 	 * 
117 	 * @return Point2D the result
118 	 */
119 	public Point2D to2D()
120 	{
121 		return new Point2D.Double(this.x, this.y);
122 	}
123 
124 	/***
125 	 * converts the point to a sperical point
126 	 * 
127 	 * @return the spherical point
128 	 */
129 	public SphericalPoint toCartesianPoint()
130 	{
131 		return CartesianPoint.toSphericalPoint(this);
132 	}
133 
134 	/***
135 	 * converts a cartesian point to a sperical point
136 	 * 
137 	 * @param point the cartesian point
138 	 * @return the spherical point
139 	 */
140 	public static SphericalPoint toSphericalPoint(final CartesianPoint point)
141 	{
142 		double rho = Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2)
143 				+ Math.pow(point.z, 2));
144 		double s = Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
145 		double phi = Math.acos(point.z / rho);
146 		double theta = Math.asin(point.y / s);
147 		if (point.x >= 0)
148 		{
149 			theta = Math.PI - theta;
150 		}
151 		return new SphericalPoint(phi, rho, theta);
152 	}
153 }