Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / render / SurfaceEllipse.java
blobd4d5029373a9e7a8434d567a2fd1fbe5a67001d1
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
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;
13 import java.awt.*;
14 import java.util.ArrayList;
16 /**
17 * @author tag
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,
29 int intervals)
31 super(makePositions(globe, center, majorAxisLength, minorAxisLength, orientation, intervals), null, null);
32 this.globe = globe;
33 this.center = center;
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,
44 borderColor);
45 this.globe = globe;
46 this.center = center;
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);
58 this.globe = globe;
59 this.center = center;
60 this.majorAxisLength = majorAxisLength;
61 this.minorAxisLength = minorAxisLength;
62 this.orientation = orientation;
63 this.intervals = intervals;
66 public LatLon getCenter()
68 return this.center;
71 public void setCenter(LatLon center)
73 this.center = center;
74 this.setPositions(
75 makePositions(this.globe, this.center, this.majorAxisLength, this.majorAxisLength, this.orientation,
76 this.intervals));
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;
93 this.setPositions(
94 makePositions(this.globe, this.center, this.majorAxisLength, this.majorAxisLength, this.orientation,
95 this.intervals));
98 public Angle getOrientation()
100 return orientation;
103 public void setOrientation(Angle orientation)
105 this.orientation = orientation;
106 this.setPositions(
107 makePositions(this.globe, this.center, this.majorAxisLength, this.majorAxisLength, this.orientation,
108 this.intervals));
111 public int getIntervals()
113 return intervals;
116 public void setIntervals(int intervals)
118 this.intervals = intervals;
119 this.setPositions(
120 makePositions(this.globe, this.center, this.majorAxisLength, this.majorAxisLength, this.orientation,
121 this.intervals));
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;
130 if (globe == null)
132 String message = Logging.getMessage("nullValue.GlobeIsNull");
133 Logging.logger().severe(message);
134 throw new IllegalArgumentException(message);
137 if (center == null)
139 String message = Logging.getMessage("nullValue.CenterIsNull");
140 Logging.logger().severe(message);
141 throw new IllegalArgumentException(message);
144 if (majorAxis <= 0)
146 String message = Logging.getMessage("Geom.MajorAxisInvalid", majorAxis);
147 Logging.logger().severe(message);
148 throw new IllegalArgumentException(message);
151 if (minorAxis <= 0)
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);
172 positions.add(p);
175 return positions;