Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / geo / Orthographic.java @ 1733

History | View | Annotate | Download (7.94 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
  
36
package org.cresques.geo;
37
//package com.raben.projection.map;
38
import java.awt.geom.Point2D;
39
import java.awt.geom.GeneralPath;
40
/***
41
 * Orthographic Map projection computation
42
 * @author  Vern Raben
43
 * @version $Revision: 1733 $ $Date: 2005-03-22 17:46:22 +0100 (Tue, 22 Mar 2005) $
44
 * Copyright (c) Raben Systems, Inc., 2002
45
 * All rights reserved 
46
 */
47
public final class Orthographic { //extends AbstractMapProjection { 
48
        /*** Creates new OrthographicMapProjection */
49
        public Orthographic() { 
50
        }
51
 
52
        /***
53
         * Get Screen location for specified coordinate in radians
54
         * @param coordinate Point2D Longitude and latitude of coordinate in radians
55
         * @return Point2D Screen location of the coordinate
56
         */
57
        public Point2D getLocationForCoordinate(Point2D coordinate) {
58
                Point2D.Double loc = new Point2D.Double(Double.NaN, Double.NaN);
59
/*                Point2D centerPoint = getCenterPoint();
60
                Point2D centerCoordinate = getCenterCoordinate();        
61
                double radius = getRadius();
62
                double cosLatCenter = getCosLatCenter();
63
                double sinLatCenter = getSinLatCenter();
64

65
                if ((!Double.isNaN(coordinate.getX())) 
66
                        && (!Double.isNaN(coordinate.getY()))) {
67
                        double latitude = coordinate.getY();
68
                        double longitude = coordinate.getX();
69

70
                        double sinLat = Math.sin(normalizeLatitude(latitude));
71
                        double cosLat = Math.cos(latitude);
72
                        double lonDiff = normalizeLongitude(longitude 
73
                                - centerCoordinate.getX());
74
                        double cosLonDiff = Math.cos(lonDiff);
75
                        double cosC = (sinLatCenter * sinLat) 
76
                                + (cosLatCenter * cosLat * cosLonDiff);
77

78
                        if (cosC >= 0.0) {
79
                                double sinLonDiff = Math.sin(lonDiff);
80
                                double x = (radius * cosLat * sinLonDiff) + centerPoint.getX();
81
                                double y = (radius * ((cosLatCenter * sinLat)
82
                                        - (sinLatCenter * cosLat * cosLonDiff))) 
83
                                        + centerPoint.getY();
84
                                loc.setLocation(x, y);
85
                        }
86
                }
87
*/
88
                return loc;
89
        }
90

    
91

    
92

    
93
        /***
94
         * Get coordinate for a given point on the screen
95
         * @param loc Point2D Screen location of the point
96
         * @return Point2D Coordinate of the point in radians
97
         */
98
        public Point2D getCoordinateForLocation(Point2D loc) {
99
                Point2D.Double coordinate 
100
                        = new Point2D.Double(Double.NaN, Double.NaN);
101
/*                Point2D centerPoint = getCenterPoint();
102
                Point2D centerCoordinate = getCenterCoordinate();
103
                double sinLatCenter = getSinLatCenter();
104
                double cosLatCenter = getCosLatCenter();
105
                double radius = getRadius();
106

107
                if ((!Double.isNaN(loc.getX())) 
108
                        && (!Double.isNaN(loc.getY()))) {
109
                        double x = loc.getX() - centerPoint.getX();
110
                        double y = loc.getY() - centerPoint.getY();
111
                        double rho = Math.sqrt((x * x) + (y * y));
112

113
                        if ((rho > 0.0) & (rho <= radius)) {
114
                                double sinC = rho / radius;
115
                                double cosC = Math.sqrt(1.0 - (sinC * sinC));        
116
                                double latitude = Math.asin(cosC * sinLatCenter)
117
                                        + (y * sinC * cosLatCenter / rho);
118
                                double longitude = Double.NaN;        
119

120
                                if (centerCoordinate.getY() 
121
                                                == MapProjectionConstants.PI_OVER_2) {
122
                                        longitude = centerCoordinate.getX()
123
                                                + Math.atan2(x, -y);
124
                                } else if (centerCoordinate.getY() 
125
                                                == -MapProjectionConstants.PI_OVER_2) {
126
                                        longitude = centerCoordinate.getX() + Math.atan2(x, y);
127
                                } else {
128
                                        longitude = centerCoordinate.getX()
129
                                                + Math.atan2((x * sinC), (rho * cosLatCenter * cosC)
130
                                                - (y * sinLatCenter * sinC));
131
                                }
132

133
                                longitude = normalizeLongitude(longitude);
134
                                latitude = normalizeLatitude(latitude);
135
                                coordinate.setLocation(longitude, latitude);                
136
                        } else if (rho == 0.0) {
137
                                coordinate.setLocation(centerCoordinate.getX(),
138
                                        centerCoordinate.getY());
139
                        }
140

141
                }
142
*/ 
143
                return coordinate;
144
        }
145

    
146

    
147
        /***
148
         * Get overlay grid for map as a path
149
         * @return GeneralPath to draw mapOverlay.
150
         */
151
        public GeneralPath getOverlayGridPath() {
152
                GeneralPath overlayGridPath = new GeneralPath();
153
/*                double sinLat = 0.0;
154
                double cosLat = 0.0;
155
                double cosLonDiff = 0.0;
156
                double sinLonDiff = 0.0;
157
                double lonDiff = 0.0;
158
                double cosC = 0.0;
159
                float x, y;
160
                float mark = (float) getRadius() / 360.0F;
161
                Point2D centerPoint = getCenterPoint();
162
                Point2D centerCoordinate = getCenterCoordinate();
163
                double radius = getRadius();
164
                double cosLatCenter = getCosLatCenter();
165
                double sinLatCenter = getSinLatCenter();
166
                double overlayGridIncrement = getOverlayGridIncrement();
167
                double overlayGridLongitudeIncrement 
168
                        = getOverlayGridLongitudeIncrement();
169
                double overlayGridLatitudeIncrement = getOverlayGridLatitudeIncrement();
170

171
                // Create latitude lines
172
                for (double lat = -MapProjectionConstants.PI_OVER_2; 
173
                                lat <= MapProjectionConstants.PI_OVER_2; 
174
                                lat += overlayGridLatitudeIncrement) {
175
                        sinLat = Math.sin(lat);
176
                        cosLat = Math.cos(lat);
177

178

179
                        for (double lon = -Math.PI; lon <= Math.PI; 
180
                                        lon += overlayGridIncrement) {
181
                                lonDiff = lon - centerCoordinate.getX();
182
                                cosLonDiff = Math.cos(lonDiff);
183
                                cosC = (sinLatCenter * sinLat) 
184
                                        + (cosLatCenter * cosLat * cosLonDiff);
185

186
                                if (cosC >= 0.0) {
187
                                        sinLonDiff = Math.sin(lonDiff);
188
                                        x = (float) ((radius * cosLat * sinLonDiff)
189
                                                + centerPoint.getX());
190
                                        y = (float) ((radius * ((cosLatCenter * sinLat)
191
                                                - (sinLatCenter * cosLat * cosLonDiff))) 
192
                                                + centerPoint.getY());
193
                                        overlayGridPath.moveTo(x - mark, y);
194
                                        overlayGridPath.lineTo(x + mark, y);
195
                                        overlayGridPath.moveTo(x, y - mark);
196
                                        overlayGridPath.lineTo(x, y + mark); 
197
                                }
198
                        }
199
                }       
200

201
                // Create longitude lines
202
                for (double lon = -Math.PI; lon <= Math.PI; 
203
                                lon += overlayGridLongitudeIncrement) {
204
                        lonDiff = lon - centerCoordinate.getX();
205
                        cosLonDiff = Math.cos(lonDiff);
206

207
                        for (double lat = -MapProjectionConstants.PI_OVER_2; 
208
                                        lat <= MapProjectionConstants.PI_OVER_2;
209
                                        lat += overlayGridIncrement) {
210
                                sinLat = Math.sin(lat);
211
                                cosLat = Math.cos(lat);                
212
                                cosC = (sinLatCenter * sinLat) 
213
                                        + (cosLatCenter * cosLat * cosLonDiff);
214
        
215
                                if (cosC >= 0.0) {
216
                                        sinLonDiff = Math.sin(lonDiff);
217
                                        x = (float) ((radius * cosLat * sinLonDiff) 
218
                                                + centerPoint.getX());
219
                                        y = (float) ((radius * ((cosLatCenter * sinLat)
220
                                                - (sinLatCenter * cosLat * cosLonDiff)))
221
                                                + centerPoint.getY());                  
222
                                        overlayGridPath.moveTo(x - mark, y);
223
                                        overlayGridPath.lineTo(x + mark, y);
224
                                        overlayGridPath.moveTo(x, y - mark);
225
                                        overlayGridPath.lineTo(x, y + mark);
226
                                }
227
                        }
228
                }        
229
*/
230
                return overlayGridPath;
231
        }
232

    
233
        /***
234
         * Get projection name
235
         * @return ProjectionName
236
         */
237
        //public ProjectionName getProjectionName() {
238
        //        return ProjectionName.ORTHOGRAPHIC;
239
        //}
240
}