Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libDXF / src / org / cresques / geo / Orthographic.java @ 21930

History | View | Annotate | Download (12.4 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
import java.awt.geom.Point2D;
39

    
40

    
41
/***
42
 * Orthographic Map projection computation
43
 * @author  Vern Raben
44
 * @version $Revision$ $Date$
45
 * Copyright (c) Raben Systems, Inc., 2002
46
 * All rights reserved
47
 */
48
public final class Orthographic { //extends AbstractMapProjection { 
49

    
50
    /*** Creates new OrthographicMapProjection */
51
    public Orthographic() {
52
    }
53

    
54
    /***
55
     * Get Screen location for specified coordinate in radians
56
     * @param coordinate Point2D Longitude and latitude of coordinate in radians
57
     * @return Point2D Screen location of the coordinate
58
     */
59
    public Point2D getLocationForCoordinate(Point2D coordinate) {
60
        Point2D.Double loc = new Point2D.Double(Double.NaN, Double.NaN);
61

    
62
        /*                Point2D centerPoint = getCenterPoint();
63
                        Point2D centerCoordinate = getCenterCoordinate();
64
                        double radius = getRadius();
65
                        double cosLatCenter = getCosLatCenter();
66
                        double sinLatCenter = getSinLatCenter();
67

68
                        if ((!Double.isNaN(coordinate.getX()))
69
                                && (!Double.isNaN(coordinate.getY()))) {
70
                                double latitude = coordinate.getY();
71
                                double longitude = coordinate.getX();
72

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

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

    
94
    /***
95
     * Get coordinate for a given point on the screen
96
     * @param loc Point2D Screen location of the point
97
     * @return Point2D Coordinate of the point in radians
98
     */
99
    public Point2D getCoordinateForLocation(Point2D loc) {
100
        Point2D.Double coordinate = new Point2D.Double(Double.NaN, Double.NaN);
101

    
102
        /*                Point2D centerPoint = getCenterPoint();
103
                        Point2D centerCoordinate = getCenterCoordinate();
104
                        double sinLatCenter = getSinLatCenter();
105
                        double cosLatCenter = getCosLatCenter();
106
                        double radius = getRadius();
107

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

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

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

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

142
                        }
143
        */
144
        return coordinate;
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

    
154
        /*                double sinLat = 0.0;
155
                        double cosLat = 0.0;
156
                        double cosLonDiff = 0.0;
157
                        double sinLonDiff = 0.0;
158
                        double lonDiff = 0.0;
159
                        double cosC = 0.0;
160
                        float x, y;
161
                        float mark = (float) getRadius() / 360.0F;
162
                        Point2D centerPoint = getCenterPoint();
163
                        Point2D centerCoordinate = getCenterCoordinate();
164
                        double radius = getRadius();
165
                        double cosLatCenter = getCosLatCenter();
166
                        double sinLatCenter = getSinLatCenter();
167
                        double overlayGridIncrement = getOverlayGridIncrement();
168
                        double overlayGridLongitudeIncrement
169
                                = getOverlayGridLongitudeIncrement();
170
                        double overlayGridLatitudeIncrement = getOverlayGridLatitudeIncrement();
171

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

179

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

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

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

208
                                for (double lat = -MapProjectionConstants.PI_OVER_2;
209
                                                lat <= MapProjectionConstants.PI_OVER_2;
210
                                                lat += overlayGridIncrement) {
211
                                        sinLat = Math.sin(lat);
212
                                        cosLat = Math.cos(lat);
213
                                        cosC = (sinLatCenter * sinLat)
214
                                                + (cosLatCenter * cosLat * cosLonDiff);
215

216
                                        if (cosC >= 0.0) {
217
                                                sinLonDiff = Math.sin(lonDiff);
218
                                                x = (float) ((radius * cosLat * sinLonDiff)
219
                                                        + centerPoint.getX());
220
                                                y = (float) ((radius * ((cosLatCenter * sinLat)
221
                                                        - (sinLatCenter * cosLat * cosLonDiff)))
222
                                                        + centerPoint.getY());
223
                                                overlayGridPath.moveTo(x - mark, y);
224
                                                overlayGridPath.lineTo(x + mark, y);
225
                                                overlayGridPath.moveTo(x, y - mark);
226
                                                overlayGridPath.lineTo(x, y + mark);
227
                                        }
228
                                }
229
                        }
230
        */
231
        return overlayGridPath;
232
    }
233

    
234
    /***
235
     * Get projection name
236
     * @return ProjectionName
237
     */
238

    
239
    //public ProjectionName getProjectionName() {
240
    //        return ProjectionName.ORTHOGRAPHIC;
241
    //}
242
}