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//import android.graphics.Point; 010import android.graphics.PointF; 011//import armyc2.c2sd.graphics2d.Point2D; 012//import armyc2.c2sd.graphics2d.Point2D; 013import armyc2.c2sd.graphics2d.*; 014/** 015 * 016 * @author Michael Deutch 017 */ 018public class PointConverter3D implements IPointConversion 019{ 020 private double _controlLat=0; 021 private double _controlLong=0; 022 private double _scale=0; 023 private double _metersPerPixel=0; 024 public PointConverter3D(double controlLong, double controlLat, double scale) 025 { 026 try 027 { 028 this._controlLat=controlLat; 029 this._controlLong=controlLong; 030 this._scale=scale; 031 _metersPerPixel=GeoPixelConversion3D.metersPerPixel(scale); 032 } 033 catch(Error e) 034 { 035 throw e; 036 } 037 } 038 public PointF PixelsToGeo(PointF pixel) 039 { 040 PointF pt2dGeo=null; 041 try 042 { 043 double y=GeoPixelConversion3D.y2lat(pixel.y, _scale, _controlLat, _metersPerPixel); 044 double x=GeoPixelConversion3D.x2long(pixel.x, _scale, _controlLong, y, _metersPerPixel); 045 pt2dGeo=new PointF((float)x,(float)y); 046 } 047 catch(Error e) 048 { 049 throw e; 050 } 051 return pt2dGeo; 052 } 053 054 public PointF GeoToPixels(PointF coord) 055 { 056 PointF ptPixels=null; 057 try 058 { 059 double y=GeoPixelConversion3D.lat2y(coord.y, _scale, _controlLat, _metersPerPixel); 060 double x=GeoPixelConversion3D.long2x(coord.x, _scale, _controlLong, coord.y, _metersPerPixel); 061 ptPixels=new PointF((float)x,(float)y); 062 } 063 catch(Error e) 064 { 065 throw e; 066 } 067 return ptPixels; 068 } 069// @Override 070// public Point2D PixelsToGeo(Point pixel) { 071// 072// return (Point2D)PixelsToGeo(new Point2D.Double(pixel.x, pixel.y)); 073// } 074// @Override 075// public Point GeoToPixels(Point2D coord) { 076 077// Point2D temp = PixelsToGeo(coord); 078// return new Point((int)temp.getX(),(int)temp.getY()); 079// } 080 @Override 081 public Point2D PixelsToGeo(Point2D pixel) { 082 083 Point2D pt2dGeo=null; 084 try 085 { 086 double y=GeoPixelConversion3D.y2lat(pixel.getY(), _scale, _controlLat, _metersPerPixel); 087 double x=GeoPixelConversion3D.x2long(pixel.getX(), _scale, _controlLong, y, _metersPerPixel); 088 pt2dGeo=new Point2D.Double(x,y); 089 } 090 catch(Error e) 091 { 092 throw e; 093 } 094 return pt2dGeo; 095 } 096 //@Override 097 public Point2D GeoToPixels(Point2D coord) { 098 Point2D ptPixels=null; 099 try 100 { 101 double y=GeoPixelConversion3D.lat2y(coord.getY(), _scale, _controlLat, _metersPerPixel); 102 double x=GeoPixelConversion3D.long2x(coord.getX(), _scale, _controlLong, coord.getY(), _metersPerPixel); 103 ptPixels=new Point2D.Double(x,y); 104 } 105 catch(Error e) 106 { 107 throw e; 108 } 109 return ptPixels; 110 } 111 112}