2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.render
;
9 import gov
.nasa
.worldwind
.geom
.*;
10 import gov
.nasa
.worldwind
.globes
.Globe
;
11 import gov
.nasa
.worldwind
.util
.Logging
;
14 import java
.util
.ArrayList
;
18 * @version $Id: SurfaceEllipse.java 2570 2007-08-16 22:31:33Z tgaskins $
20 public class SurfaceEllipse
extends SurfacePolygon
22 private LatLon center
;
23 private double majorAxisLength
;
24 private double minorAxisLength
;
25 private Angle orientation
;
26 private int intervals
;
28 public SurfaceEllipse(Globe globe
, LatLon center
, double majorAxisLength
, double minorAxisLength
, Angle orientation
,
31 super(makePositions(globe
, center
, majorAxisLength
, minorAxisLength
, orientation
, intervals
), null, null);
34 this.majorAxisLength
= majorAxisLength
;
35 this.minorAxisLength
= minorAxisLength
;
36 this.orientation
= orientation
;
37 this.intervals
= intervals
;
40 public SurfaceEllipse(Globe globe
, LatLon center
, double majorAxisLength
, double minorAxisLength
, Angle orientation
,
41 int intervals
, Color interiorColor
, Color borderColor
)
43 super(makePositions(globe
, center
, majorAxisLength
, minorAxisLength
, orientation
, intervals
), interiorColor
,
47 this.majorAxisLength
= majorAxisLength
;
48 this.minorAxisLength
= minorAxisLength
;
49 this.orientation
= orientation
;
50 this.intervals
= intervals
;
53 public SurfaceEllipse(Globe globe
, LatLon center
, double majorAxisLength
, double minorAxisLength
, Angle orientation
,
54 int intervals
, Color interiorColor
, Color borderColor
, Dimension textureSize
)
56 super(makePositions(globe
, center
, majorAxisLength
, minorAxisLength
, orientation
, intervals
), interiorColor
,
57 borderColor
, textureSize
);
60 this.majorAxisLength
= majorAxisLength
;
61 this.minorAxisLength
= minorAxisLength
;
62 this.orientation
= orientation
;
63 this.intervals
= intervals
;
66 public LatLon
getCenter()
71 public void setCenter(LatLon center
)
75 makePositions(this.globe
, this.center
, this.majorAxisLength
, this.majorAxisLength
, this.orientation
,
79 public double getMajorAxisLength()
81 return majorAxisLength
;
84 public double getMinorAxisLength()
86 return minorAxisLength
;
89 public void setAxisLengths(double majorAxisLength
, double minorAxisLength
)
91 this.majorAxisLength
= majorAxisLength
;
92 this.minorAxisLength
= minorAxisLength
;
94 makePositions(this.globe
, this.center
, this.majorAxisLength
, this.majorAxisLength
, this.orientation
,
98 public Angle
getOrientation()
103 public void setOrientation(Angle orientation
)
105 this.orientation
= orientation
;
107 makePositions(this.globe
, this.center
, this.majorAxisLength
, this.majorAxisLength
, this.orientation
,
111 public int getIntervals()
116 public void setIntervals(int intervals
)
118 this.intervals
= intervals
;
120 makePositions(this.globe
, this.center
, this.majorAxisLength
, this.majorAxisLength
, this.orientation
,
124 private static Iterable
<LatLon
> makePositions(Globe globe
, LatLon center
, double majorAxis
, double minorAxis
,
125 Angle orientation
, int intervals
)
127 if (orientation
== null)
128 orientation
= Angle
.ZERO
;
132 String message
= Logging
.getMessage("nullValue.GlobeIsNull");
133 Logging
.logger().severe(message
);
134 throw new IllegalArgumentException(message
);
139 String message
= Logging
.getMessage("nullValue.CenterIsNull");
140 Logging
.logger().severe(message
);
141 throw new IllegalArgumentException(message
);
146 String message
= Logging
.getMessage("Geom.MajorAxisInvalid", majorAxis
);
147 Logging
.logger().severe(message
);
148 throw new IllegalArgumentException(message
);
153 String message
= Logging
.getMessage("Geom.MajorAxisInvalid", minorAxis
);
154 Logging
.logger().severe(message
);
155 throw new IllegalArgumentException(message
);
158 int numPositions
= 1 + Math
.max(intervals
, 4);
159 final ArrayList
<LatLon
> positions
= new ArrayList
<LatLon
>();
161 double radius
= globe
.getRadiusAt(center
.getLatitude(), center
.getLongitude());
162 double da
= 2 * Math
.PI
/ (numPositions
- 1);
163 for (int i
= 0; i
< numPositions
; i
++)
165 // azimuth runs positive clockwise from north and through 360ยก.
166 double angle
= (i
!= numPositions
- 1) ? i
* da
: 0;
167 double azimuth
= Math
.PI
/ 2 - (angle
+ orientation
.radians
);
168 double xLength
= majorAxis
* Math
.cos(angle
);
169 double yLength
= minorAxis
* Math
.sin(angle
);
170 double distance
= Math
.sqrt(xLength
* xLength
+ yLength
* yLength
);
171 LatLon p
= LatLon
.endPosition(center
, azimuth
, distance
/ radius
);