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