Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/geo/Orthographic.java

View differences:

Orthographic.java
32 32
 *
33 33
 * Created on June 7, 2002, 4:31 PM
34 34
*/
35
  
36 35
package org.cresques.geo;
36

  
37
import java.awt.geom.GeneralPath;
38

  
37 39
//package com.raben.projection.map;
38 40
import java.awt.geom.Point2D;
39
import java.awt.geom.GeneralPath;
41

  
42

  
40 43
/***
41 44
 * Orthographic Map projection computation
42 45
 * @author  Vern Raben
43 46
 * @version $Revision$ $Date$
44 47
 * Copyright (c) Raben Systems, Inc., 2002
45
 * All rights reserved 
48
 * All rights reserved
46 49
 */
47 50
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 51

  
65
		if ((!Double.isNaN(coordinate.getX())) 
66
			&& (!Double.isNaN(coordinate.getY()))) {
67
			double latitude = coordinate.getY();
68
			double longitude = coordinate.getX();
52
    /*** Creates new OrthographicMapProjection */
53
    public Orthographic() {
54
    }
69 55

  
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);
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);
77 63

  
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
	}
64
        /*                Point2D centerPoint = getCenterPoint();
65
                        Point2D centerCoordinate = getCenterCoordinate();
66
                        double radius = getRadius();
67
                        double cosLatCenter = getCosLatCenter();
68
                        double sinLatCenter = getSinLatCenter();
90 69

  
70
                        if ((!Double.isNaN(coordinate.getX()))
71
                                && (!Double.isNaN(coordinate.getY()))) {
72
                                double latitude = coordinate.getY();
73
                                double longitude = coordinate.getX();
91 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);
92 82

  
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();
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
    }
106 95

  
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));
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);
112 103

  
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;        
104
        /*                Point2D centerPoint = getCenterPoint();
105
                        Point2D centerCoordinate = getCenterCoordinate();
106
                        double sinLatCenter = getSinLatCenter();
107
                        double cosLatCenter = getCosLatCenter();
108
                        double radius = getRadius();
119 109

  
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
				}
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));
132 115

  
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
			}
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;
140 122

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

  
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();
144
                        }
145
        */
146
        return coordinate;
147
    }
170 148

  
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);
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();
177 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();
178 173

  
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);
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);
185 180

  
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 181

  
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);
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);
206 188

  
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
	}
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
                        }
232 203

  
233
	/***
234
	 * Get projection name
235
	 * @return ProjectionName
236
	 */
237
	//public ProjectionName getProjectionName() {
238
	//	return ProjectionName.ORTHOGRAPHIC;
239
	//}
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
    //}
240 244
}

Also available in: Unified diff