Re: Ellipses

From: Jamie Oldham <joldham@modusoperandi.com>
Date: Thu Sep 26 2002 - 15:20:36 EDT

Here's how i calculate the width and height, it is in the layer so it is
called when appropriate..

// Project the lower right lat/lon coordinates to screen coordinates
Point lowerPoint = proj.forward(
                (float)box.lowerRightCorner.latitude,
                (float)box.lowerRightCorner.longitude);

// Project the upper left lat/lon coordinates to screen coordinates
Point upperPoint = proj.forward(
                (float)box.upperLeftCorner.latitude,
                (float)box.upperLeftCorner.longitude);

 // Calculate the diameter of the fix ellipse
 diameterX = (int)Math.abs(upperPoint.getX() - lowerPoint.getX());
 diameterY = (int)Math.abs(upperPoint.getY() - lowerPoint.getY());

----------------------------------------------------------------------------

----
The bounds of the ellipse box can be calulated with the following ;
public  Box CalculateEllipseBox (Location ellipseCenter,
                               double majorAxis,
                               double minorAxis,
                               double orientation)
                                throws MathError, LocationTooCloseToPole {
  Box box = new Box();
   Location upperMajorAxisEndpoint = new Location();
  Location lowerMajorAxisEndpoint = new Location();
  Location leftBoxPoint = new Location();
   Location rightBoxPoint = new Location();
    Location highestBoxPoint = new Location();
  Location lowestBoxPoint = new Location();
   double majorAxisBearing;
  double minorAxisBearing;
  double majorAxisLength;
   double minorAxisLength;
  majorAxisLength = Math.abs (majorAxis);
  minorAxisLength = Math.abs (minorAxis);
  if (Math.abs (orientation) <= 90.0)
   majorAxisBearing = orientation;
  else
   majorAxisBearing = orientation + 180.0;
  upperMajorAxisEndpoint = CalculateDestination (ellipseCenter,
                (majorAxisLength / 2.0), majorAxisBearing);
  lowerMajorAxisEndpoint = CalculateDestination (ellipseCenter,
           (majorAxisLength / 2.0), (majorAxisBearing + 180.0));
    if (majorAxisBearing >= 0.0) {
   minorAxisBearing = NormalizeBearing( majorAxisBearing + 270.0);
   rightBoxPoint = CalculateDestination (upperMajorAxisEndpoint,
       (minorAxisLength / 2.0), (minorAxisBearing + 180.0));
   leftBoxPoint = CalculateDestination (lowerMajorAxisEndpoint,
       (minorAxisLength / 2.0), minorAxisBearing);
  } else {
   minorAxisBearing = majorAxisBearing + 90.0;
   rightBoxPoint = CalculateDestination (lowerMajorAxisEndpoint,
                                   (minorAxisLength / 2.0),
                                   minorAxisBearing);
   leftBoxPoint = CalculateDestination (upperMajorAxisEndpoint,
                                 (minorAxisLength / 2.0),
                                 (minorAxisBearing + 180.0));
  }
  highestBoxPoint = CalculateDestination (upperMajorAxisEndpoint,
                               (minorAxisLength / 2.0),
                               minorAxisBearing);
  lowestBoxPoint = CalculateDestination (lowerMajorAxisEndpoint,
                                (minorAxisLength / 2.0),
                                (minorAxisBearing + 180.0));
  Location northPole = new Location();
  northPole.latitude = NORTH_POLE_LATITUDE;
  northPole.longitude = NORTH_POLE_LONGITUDE;
  Location southPole = new Location();
  southPole.latitude = SOUTH_POLE_LATITUDE;
  southPole.longitude = SOUTH_POLE_LONGITUDE;
  if (DistanceBetween (ellipseCenter, northPole) <= (majorAxisLength / 2.0))
{
   box.upperLeftCorner.latitude = MAX_LATITUDE;
     box.upperLeftCorner.longitude = MIN_LONGITUDE;
   box.lowerRightCorner.longitude = MAX_LONGITUDE;
   box.lowerRightCorner.latitude = lowestBoxPoint.latitude;
  } else if (DistanceBetween ( ellipseCenter, southPole) <=
                   (majorAxisLength / 2.0)) {
   box.upperLeftCorner.latitude = highestBoxPoint.latitude;
   box.upperLeftCorner.longitude = MIN_LONGITUDE;
   box.lowerRightCorner.longitude = MAX_LONGITUDE;
   box.lowerRightCorner.latitude = MIN_LATITUDE;
  } else {
   box.upperLeftCorner.longitude = leftBoxPoint.longitude;
   box.upperLeftCorner.latitude = highestBoxPoint.latitude;
   box.lowerRightCorner.longitude = rightBoxPoint.longitude;
   box.lowerRightCorner.latitude = lowestBoxPoint.latitude;
  }
  return box;
 }
jo
----- Original Message -----
From: "Oscarson Erik" <eoscarson@rayva.org>
To: "Jamie Oldham" <joldham@modusoperandi.com>; <openmap-users@bbn.com>
Sent: Thursday, September 26, 2002 2:05 PM
Subject: RE: Ellipses
> Hi Jamie,
>
> I'm not sure this will help.  Does whatever calls this method keep track
> of the georeferenced points and then call projection.forward(...) to get
> the appropriate Height & Width?
>
> This uses the same constructor that I mentioned.  The width & height are
> X/Y window coordinates, so the ellipse is always the same size
> regardless of map scale or projection, unless the width & height that
> are passed in have been 'generated' in some way.
>
> If you want to see some real OpenMap 'magic,' create a LatLon OMCircle
> using straight lines and then use the gestures mode to drag it around
> the map window that uses CADRG-projection.  The circle projects
> correctly in real-time.  If you were able to try the same thing with an
> ellipse, the size/shape wouldn't change, no matter where it was moved
> to.
>
> Erik
>
>
> -----Original Message-----
> From: Jamie Oldham [mailto:joldham@modusoperandi.com]
> Sent: Thursday, September 26, 2002 12:40 PM
> Subject: Re: Ellipses
>
> Hey,
>
> I currently use the following code to create ellipses using OpenMap, it
> works great!
>
> /**
>      * Create the ellipse
>      * @return OMCircle
>      *  The fix ellipse
>      */
>     public OMCircle createCircle(float centerLat, float centerLon,
>       int width, int height, double angle, Color color) {
>         OMCircle circle = new OMCircle(centerLat, centerLon,
>           width, height);
>         circle.setRotationAngle(angle);
>         circle.setLinePaint(color);
>  return circle;
>     }
>
>
> jamie oldham
>
>
> ----- Original Message -----
> From: "Pearson John T Jr GG-13 453 EWS/EWR"
> <John.Pearson@LACKLAND.AF.MIL>
> To: "'Oscarson Erik'" <eoscarson@rayva.org>; <openmap-users@bbn.com>
> Sent: Thursday, September 26, 2002 11:42 AM
> Subject: RE: Ellipses
>
>
> Classification: UNCLASSIFIED
>
> On Thursday, September 26, 2002 10:14 AM, Erik Oscarson wrote
>
> >There is a good possibility that I've missed something that already
> exists
> within the API.
>
> Perhaps someone else has developed what you need, and would be willing
> to
> share it with all of us OpenMap users/developers.
>
> Regards
>
> John pearson
>
>
> -----Original Message-----
> From: Oscarson Erik [mailto:eoscarson@rayva.org]
> Sent: Thursday, September 26, 2002 10:14 AM
> To: openmap-users@bbn.com
> Subject: Ellipses
>
>
> Hi All,
>
> I'm trying to use OMCircle to create ellipses that have major and minor
> axes
> that use Length, like the
> OMCircle constructor [OMCircle(float latPoint, float lonPoint, float
> radius,
> Length units)] uses for radius.
>
> I'm not sure if this is a good approach or not, but I am planning on
> extending the OMCircle class (OMEllispe maybe?) and setting something up
> that would simply derive the H/W from the projection during generation
> and
> then use that to rebuild itself as necessary.  This approach is
> geographically unsound, but at smaller zoom levels it might work well
> enough.
>
> I do not have knowledge of the math necessary to do this correctly, but
> I'm
> still going to play around with it.
>
> There is a good possibility that I've missed something that already
> exists
> within the API.
>
>
> Erik Oscarson
> Raytheon
> eoscarson@rayva.org
>
>
> --
> [To unsubscribe to this list send an email to "majdart@bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]
>
> Classification: UNCLASSIFIED
>
> --
> [To unsubscribe to this list send an email to "majdart@bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]
>
>
> --
> [To unsubscribe to this list send an email to "majdart@bbn.com"
> with the following text in the BODY of the message "unsubscribe
openmap-users"]
--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Sep 26 15:22:15 2002

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:33 EDT