001/*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005
006package armyc2.c2sd.renderer.utilities;
007
008
009/**
010 *
011 * 
012 */
013public class GeoPixelConversion3D
014{
015    private static double inchPerMeter = 39.3700787;
016    private static double pixelsPerInch = 96 ;
017    private static double METERS_PER_DEG = 111319.49079327357264771338267056;
018
019    public static double metersPerPixel(double scale)
020    {
021        double step1 = scale/pixelsPerInch;
022        return step1/inchPerMeter;
023    }
024
025    public static double lat2y(double latitude, double scale, double latOrigin, double metPerPix)
026    {
027        
028        double latRem = Math.abs(latitude-latOrigin);
029        double pixDis = 0;
030        if(latRem > 0)
031        {
032        pixDis = (latRem*METERS_PER_DEG)/metPerPix;
033                if(latitude > latOrigin)//was < M. Deutch 6-20-11
034                {
035                    pixDis = -pixDis;
036                }
037        }
038        return pixDis;
039    }
040
041    public static double y2lat(double yPosition, double scale, double latOrigin, double metPerPix)
042    {
043       
044        double latitude  = latOrigin;
045        if(yPosition != 0)
046        {
047                latitude  = latOrigin - ((yPosition * metPerPix)/METERS_PER_DEG) ;//was + M. Deutch 6-18-11
048        }
049        return latitude;
050    }
051
052    public static double long2x(double longitude,double scale,double longOrigin,double latitude, double metPerPix)
053    {
054        
055        double longRem = Math.abs(longitude-longOrigin);
056        double metersPerDeg = GetMetersPerDegAtLat(latitude);
057        double pixDis = 0;
058        if(longRem > 0)
059        {
060            pixDis = (longRem*metersPerDeg)/metPerPix;
061            if(longitude < longOrigin)
062            {
063                    pixDis = -pixDis;
064            }
065        }
066        return pixDis;
067    }
068
069    public static double x2long(double xPosition,double scale,double longOrigin,double latitude, double metPerPix)
070    {
071        
072        double metersPerDeg = GetMetersPerDegAtLat(latitude);
073        double longitude  = longOrigin;
074        if(xPosition != 0)
075        {
076            longitude  = longOrigin + ((xPosition * metPerPix)/metersPerDeg) ;
077        }
078        return longitude;
079    }
080
081    
082    public static double Deg2Rad(double deg)
083    {
084                double conv_factor = (2.0 * Math.PI)/360.0;
085                return(deg * conv_factor);
086    }
087
088    public static double GetMetersPerDegAtLat(double lat)
089    {
090        // Convert latitude to radians
091        lat = Deg2Rad(lat);
092        // Set up "Constants"
093        double p1 = 111412.84;          // longitude calculation term 1
094
095        double p2 = -93.5;                      // longitude calculation term 2
096
097        double p3 = 0.118;                      // longitude calculation term 3
098
099        // Calculate the length of a degree of longitude in meters at given latitude
100        double longlen = (p1 * Math.cos(lat)) + (p2 * Math.cos(3 * lat)) + (p3 * Math.cos(5 * lat));
101
102        return longlen;
103    }
104
105    
106}