root / tags / v1_1_Build_1003 / libraries / libCq_CMS_praster / src / org / cresques / geo / Orthographic.java @ 12271
History | View | Annotate | Download (12.2 KB)
1 |
/*
|
---|---|
2 |
* OrthographicMapProjection.java
|
3 |
*
|
4 |
* Copyright (c) 2002, 2003, Raben Systems, Inc.
|
5 |
* All rights reserved.
|
6 |
*
|
7 |
* Redistribution and use in source and binary forms, with or without
|
8 |
* modification, are permitted provided that the following conditions are met:
|
9 |
*
|
10 |
* Redistributions of source code must retain the above copyright notice,
|
11 |
* this list of conditions and the following disclaimer.
|
12 |
*
|
13 |
* Redistributions in binary form must reproduce the above copyright notice,
|
14 |
* this list of conditions and the following disclaimer in the documentation
|
15 |
* and/or other materials provided with the distribution.
|
16 |
*
|
17 |
* Neither the name of Raben Systems, Inc. nor the names of its contributors
|
18 |
* may be used to endorse or promote products derived from this software
|
19 |
* without specific prior written permission.
|
20 |
*
|
21 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
22 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
24 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
25 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
26 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31 |
* POSSIBILITY OF SUCH DAMAGE.
|
32 |
*
|
33 |
* Created on June 7, 2002, 4:31 PM
|
34 |
*/
|
35 |
package org.cresques.geo; |
36 |
|
37 |
import java.awt.geom.GeneralPath; |
38 |
|
39 |
//package com.raben.projection.map;
|
40 |
import java.awt.geom.Point2D; |
41 |
|
42 |
|
43 |
/***
|
44 |
* Orthographic Map projection computation
|
45 |
* @author Vern Raben
|
46 |
* @version $Revision: 12271 $ $Date: 2007-06-21 12:50:33 +0200 (Thu, 21 Jun 2007) $
|
47 |
* Copyright (c) Raben Systems, Inc., 2002
|
48 |
* All rights reserved
|
49 |
*/
|
50 |
public final class Orthographic { //extends AbstractMapProjection { |
51 |
|
52 |
/*** Creates new OrthographicMapProjection */
|
53 |
public Orthographic() {
|
54 |
} |
55 |
|
56 |
/***
|
57 |
* Get Screen location for specified coordinate in radians
|
58 |
* @param coordinate Point2D Longitude and latitude of coordinate in radians
|
59 |
* @return Point2D Screen location of the coordinate
|
60 |
*/
|
61 |
public Point2D getLocationForCoordinate(Point2D coordinate) { |
62 |
Point2D.Double loc = new Point2D.Double(Double.NaN, Double.NaN); |
63 |
|
64 |
/* Point2D centerPoint = getCenterPoint();
|
65 |
Point2D centerCoordinate = getCenterCoordinate();
|
66 |
double radius = getRadius();
|
67 |
double cosLatCenter = getCosLatCenter();
|
68 |
double sinLatCenter = getSinLatCenter();
|
69 |
|
70 |
if ((!Double.isNaN(coordinate.getX()))
|
71 |
&& (!Double.isNaN(coordinate.getY()))) {
|
72 |
double latitude = coordinate.getY();
|
73 |
double longitude = coordinate.getX();
|
74 |
|
75 |
double sinLat = Math.sin(normalizeLatitude(latitude));
|
76 |
double cosLat = Math.cos(latitude);
|
77 |
double lonDiff = normalizeLongitude(longitude
|
78 |
- centerCoordinate.getX());
|
79 |
double cosLonDiff = Math.cos(lonDiff);
|
80 |
double cosC = (sinLatCenter * sinLat)
|
81 |
+ (cosLatCenter * cosLat * cosLonDiff);
|
82 |
|
83 |
if (cosC >= 0.0) {
|
84 |
double sinLonDiff = Math.sin(lonDiff);
|
85 |
double x = (radius * cosLat * sinLonDiff) + centerPoint.getX();
|
86 |
double y = (radius * ((cosLatCenter * sinLat)
|
87 |
- (sinLatCenter * cosLat * cosLonDiff)))
|
88 |
+ centerPoint.getY();
|
89 |
loc.setLocation(x, y);
|
90 |
}
|
91 |
}
|
92 |
*/
|
93 |
return loc;
|
94 |
} |
95 |
|
96 |
/***
|
97 |
* Get coordinate for a given point on the screen
|
98 |
* @param loc Point2D Screen location of the point
|
99 |
* @return Point2D Coordinate of the point in radians
|
100 |
*/
|
101 |
public Point2D getCoordinateForLocation(Point2D loc) { |
102 |
Point2D.Double coordinate = new Point2D.Double(Double.NaN, Double.NaN); |
103 |
|
104 |
/* Point2D centerPoint = getCenterPoint();
|
105 |
Point2D centerCoordinate = getCenterCoordinate();
|
106 |
double sinLatCenter = getSinLatCenter();
|
107 |
double cosLatCenter = getCosLatCenter();
|
108 |
double radius = getRadius();
|
109 |
|
110 |
if ((!Double.isNaN(loc.getX()))
|
111 |
&& (!Double.isNaN(loc.getY()))) {
|
112 |
double x = loc.getX() - centerPoint.getX();
|
113 |
double y = loc.getY() - centerPoint.getY();
|
114 |
double rho = Math.sqrt((x * x) + (y * y));
|
115 |
|
116 |
if ((rho > 0.0) & (rho <= radius)) {
|
117 |
double sinC = rho / radius;
|
118 |
double cosC = Math.sqrt(1.0 - (sinC * sinC));
|
119 |
double latitude = Math.asin(cosC * sinLatCenter)
|
120 |
+ (y * sinC * cosLatCenter / rho);
|
121 |
double longitude = Double.NaN;
|
122 |
|
123 |
if (centerCoordinate.getY()
|
124 |
== MapProjectionConstants.PI_OVER_2) {
|
125 |
longitude = centerCoordinate.getX()
|
126 |
+ Math.atan2(x, -y);
|
127 |
} else if (centerCoordinate.getY()
|
128 |
== -MapProjectionConstants.PI_OVER_2) {
|
129 |
longitude = centerCoordinate.getX() + Math.atan2(x, y);
|
130 |
} else {
|
131 |
longitude = centerCoordinate.getX()
|
132 |
+ Math.atan2((x * sinC), (rho * cosLatCenter * cosC)
|
133 |
- (y * sinLatCenter * sinC));
|
134 |
}
|
135 |
|
136 |
longitude = normalizeLongitude(longitude);
|
137 |
latitude = normalizeLatitude(latitude);
|
138 |
coordinate.setLocation(longitude, latitude);
|
139 |
} else if (rho == 0.0) {
|
140 |
coordinate.setLocation(centerCoordinate.getX(),
|
141 |
centerCoordinate.getY());
|
142 |
}
|
143 |
|
144 |
}
|
145 |
*/
|
146 |
return coordinate;
|
147 |
} |
148 |
|
149 |
/***
|
150 |
* Get overlay grid for map as a path
|
151 |
* @return GeneralPath to draw mapOverlay.
|
152 |
*/
|
153 |
public GeneralPath getOverlayGridPath() { |
154 |
GeneralPath overlayGridPath = new GeneralPath(); |
155 |
|
156 |
/* double sinLat = 0.0;
|
157 |
double cosLat = 0.0;
|
158 |
double cosLonDiff = 0.0;
|
159 |
double sinLonDiff = 0.0;
|
160 |
double lonDiff = 0.0;
|
161 |
double cosC = 0.0;
|
162 |
float x, y;
|
163 |
float mark = (float) getRadius() / 360.0F;
|
164 |
Point2D centerPoint = getCenterPoint();
|
165 |
Point2D centerCoordinate = getCenterCoordinate();
|
166 |
double radius = getRadius();
|
167 |
double cosLatCenter = getCosLatCenter();
|
168 |
double sinLatCenter = getSinLatCenter();
|
169 |
double overlayGridIncrement = getOverlayGridIncrement();
|
170 |
double overlayGridLongitudeIncrement
|
171 |
= getOverlayGridLongitudeIncrement();
|
172 |
double overlayGridLatitudeIncrement = getOverlayGridLatitudeIncrement();
|
173 |
|
174 |
// Create latitude lines
|
175 |
for (double lat = -MapProjectionConstants.PI_OVER_2;
|
176 |
lat <= MapProjectionConstants.PI_OVER_2;
|
177 |
lat += overlayGridLatitudeIncrement) {
|
178 |
sinLat = Math.sin(lat);
|
179 |
cosLat = Math.cos(lat);
|
180 |
|
181 |
|
182 |
for (double lon = -Math.PI; lon <= Math.PI;
|
183 |
lon += overlayGridIncrement) {
|
184 |
lonDiff = lon - centerCoordinate.getX();
|
185 |
cosLonDiff = Math.cos(lonDiff);
|
186 |
cosC = (sinLatCenter * sinLat)
|
187 |
+ (cosLatCenter * cosLat * cosLonDiff);
|
188 |
|
189 |
if (cosC >= 0.0) {
|
190 |
sinLonDiff = Math.sin(lonDiff);
|
191 |
x = (float) ((radius * cosLat * sinLonDiff)
|
192 |
+ centerPoint.getX());
|
193 |
y = (float) ((radius * ((cosLatCenter * sinLat)
|
194 |
- (sinLatCenter * cosLat * cosLonDiff)))
|
195 |
+ centerPoint.getY());
|
196 |
overlayGridPath.moveTo(x - mark, y);
|
197 |
overlayGridPath.lineTo(x + mark, y);
|
198 |
overlayGridPath.moveTo(x, y - mark);
|
199 |
overlayGridPath.lineTo(x, y + mark);
|
200 |
}
|
201 |
}
|
202 |
}
|
203 |
|
204 |
// Create longitude lines
|
205 |
for (double lon = -Math.PI; lon <= Math.PI;
|
206 |
lon += overlayGridLongitudeIncrement) {
|
207 |
lonDiff = lon - centerCoordinate.getX();
|
208 |
cosLonDiff = Math.cos(lonDiff);
|
209 |
|
210 |
for (double lat = -MapProjectionConstants.PI_OVER_2;
|
211 |
lat <= MapProjectionConstants.PI_OVER_2;
|
212 |
lat += overlayGridIncrement) {
|
213 |
sinLat = Math.sin(lat);
|
214 |
cosLat = Math.cos(lat);
|
215 |
cosC = (sinLatCenter * sinLat)
|
216 |
+ (cosLatCenter * cosLat * cosLonDiff);
|
217 |
|
218 |
if (cosC >= 0.0) {
|
219 |
sinLonDiff = Math.sin(lonDiff);
|
220 |
x = (float) ((radius * cosLat * sinLonDiff)
|
221 |
+ centerPoint.getX());
|
222 |
y = (float) ((radius * ((cosLatCenter * sinLat)
|
223 |
- (sinLatCenter * cosLat * cosLonDiff)))
|
224 |
+ centerPoint.getY());
|
225 |
overlayGridPath.moveTo(x - mark, y);
|
226 |
overlayGridPath.lineTo(x + mark, y);
|
227 |
overlayGridPath.moveTo(x, y - mark);
|
228 |
overlayGridPath.lineTo(x, y + mark);
|
229 |
}
|
230 |
}
|
231 |
}
|
232 |
*/
|
233 |
return overlayGridPath;
|
234 |
} |
235 |
|
236 |
/***
|
237 |
* Get projection name
|
238 |
* @return ProjectionName
|
239 |
*/
|
240 |
|
241 |
//public ProjectionName getProjectionName() {
|
242 |
// return ProjectionName.ORTHOGRAPHIC;
|
243 |
//}
|
244 |
} |