# Calculating geodetic ellipse

**800343**Aug 6, 2009 1:48 PM

Hi

In a geographic program I have the following problem:

I have an ellipse given as ellipse(longitude,latitude,semiMajor,semiMinor,angle)

The semiMajor/Minor are in

Now I need to plot this shape acurately onto a map .In order to do this I need to create a whole lot of points on the perimeter of this ellipse and plot each one.

I have a function (see below) which does this .

The problem is that this function does not take into acount the curvature of the earth.

I have another funtion (opensource from http://www.gavaghan.org/blog/free-source-code/geodesy-library-vincentys-formula/)

which takes a starting point ,bearing and distance in meters and evaluates the destination coordinates reached on the earth.

I have tried in the code below to use these two functions together in order to produce an ellipse correct for the earths curvature however for some reason I get a peanut shape instead of an ellipse!

Could someone maybe see where I've gone wrong?

Thanks!

In a geographic program I have the following problem:

I have an ellipse given as ellipse(longitude,latitude,semiMajor,semiMinor,angle)

The semiMajor/Minor are in

**meters**.Now I need to plot this shape acurately onto a map .In order to do this I need to create a whole lot of points on the perimeter of this ellipse and plot each one.

I have a function (see below) which does this .

The problem is that this function does not take into acount the curvature of the earth.

I have another funtion (opensource from http://www.gavaghan.org/blog/free-source-code/geodesy-library-vincentys-formula/)

which takes a starting point ,bearing and distance in meters and evaluates the destination coordinates reached on the earth.

I have tried in the code below to use these two functions together in order to produce an ellipse correct for the earths curvature however for some reason I get a peanut shape instead of an ellipse!

Could someone maybe see where I've gone wrong?

Thanks!

```
protected void buildEllipse(double centerX,double centerY,
double semiMajor,double semiMinor,double angleOfEllipse)
{
//the amount of points on the perimeter to calculate
double angleStepSize = 0.5;
//the array of normal points (using classes from the JTS library)
Coordinate[] coords1 = new Coordinate[(int)(360/angleStepSize)];
//the array of geodetically corrected points
Coordinate[] coords2 = new Coordinate[(int)(360/angleStepSize)];
double beta = -angleOfEllipse * (Math.PI / 180);
double sinbeta = Math.sin(beta);
double cosbeta = Math.cos(beta);
int i = 0;
for (double angleOffset = 0; angleOffset < 360; angleOffset += angleStepSize)
{
double alpha = angleOffset * (Math.PI / 180) ;
double sinalpha = Math.sin(alpha);
double cosalpha = Math.cos(alpha);
double xDiff =
(semiMajor * cosalpha * cosbeta - semiMinor * sinalpha * sinbeta);
double x = centerX + xDiff;
double yDiff =
(semiMajor * cosalpha * sinbeta + semiMinor * sinalpha * cosbeta);
double y = centerY + yDiff;
coords1[i] = new Coordinate(x,y);
//here I find the distance in meters from the center of the ellipse
//to the new x y point found (I hope?)
double hyp = Math.sqrt((xDiff*xDiff)+(yDiff*yDiff));
double bearing = angleOfEllipse + angleOffset;
//This function finds the destination coordinates on the surface
//of the earth (I'm sure it works, used it elswhere)
GlobalCoordinates dest = calculateEndingCoords(centerX,centerY,hyp,bearing);
coords2[i++] = new Coordinate(dest.getLongitude(),dest.getLatitude());
}
//At this stage coords1 draws an ellipse,
//coords2 draws a peanut!
}
```

- 168 Views
- Tags: none (add)