I have created this post -> plot a real world lat lon into different angle still image map
from that, I can successfully mark the given lat&lon given the two (2) coordinates (upper left, lower right) but due to incorrect angle of the still image map compare to real world map angle, my mark was displaced.
Now, I am thinking of using four (4) coordinates (upper left, lower left, upper right, lower right) of the image. So that, I could plot the given lat&lon without considering the angle.
I think, even without Android experience could answer this question. I just kinda slow with Mathematics matter.
It is possible to implement it? if yes, any guidance & code snippets are appreciated.
UPDATES1 Main goal is to mark the given lat&lon into image map which has different angle against to real world map.
UPDATES2 I am using the below codes to compute my angle. Would you check it if it is reliable for getting the angle. Then convert it to pixel. NOTE: this codes are using only two coordinates of the image plus target coordinate.
public static double[] calc_xy (double imageSize, Location target, Location upperLeft, Location upperRight) {
double newAngle = -1;
try {
double angle = calc_radian(upperRight.getLongitude(), upperRight.getLatitude(),
upperLeft.getLongitude(), upperLeft.getLatitude(),
target.getLongitude(), target.getLatitude());
newAngle = 180-angle;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
double upperLeft_Target_dist = upperLeft.distanceTo(target);
double upperLeft_Right_dist = upperLeft.distanceTo(upperRight);
double distancePerPx = imageSize /upperLeft_Right_dist;
double distance = upperLeft_Target_dist * distancePerPx;
double radian = newAngle * Math.PI/180;
double[] result = radToPixel(distance, radian);
return result;
}
public static double[] radToPixel(double distance, double radian) {
double[] result = {-1,-1};
result[Functions.Location.PIXEL_X_LON] = distance * Math.cos(radian);
result[Functions.Location.PIXEL_Y_LAT] = distance * Math.sin(radian);
return result;
}
public static double calc_radian(Double x1, Double y1, Double x2, Double y2, Double x3, Double y3)
throws Exception{
double rad = 0.0;
if((Double.compare(x1, x2) == 0 && Double.compare(y1, y2) == 0) ||
(Double.compare(x3, x2) == 0 && Double.compare(y3, y2) == 0))
{
Log.d(tag, "Same place") ;
return rad;
}
/* compute vector */
double BAx = x2 - x1;
double BAy = y2 - y1;
double BCx = x3 - x2;
double BCy = y3 - y2;
double cosA = BAx / Math.sqrt( BAx * BAx + BAy * BAy ) ;
double cosC = BCx / Math.sqrt( BCx * BCx + BCy * BCy ) ;
double radA = Math.acos( cosA ) * 180.0 / Math.PI ;
double radC = Math.acos( cosC ) * 180.0 / Math.PI ;
if( BAy < 0.0 )
{
radA = radA * -1.0 ;
}
if( BCy < 0.0 )
{
radC = radC * -1.0 ;
}
rad = radC - radA ;
if( rad > 180.0 )
{
rad = rad - 360;
}
if( rad < -180.0 )
{
rad = rad + 360;
}
return rad ;
}