地球儀上でISS(国際宇宙ステーション)の位置を表示するプログラム(その3)
public Image resizeImage(Image jpg, int resizeHeight) //画像サイズ変換
{
int resizeWidth = (int)(jpg.Width * ((double)resizeHeight / (double)jpg.Height));
Bitmap resizeBmp = new Bitmap(resizeWidth, resizeHeight);
Graphics g = Graphics.FromImage(resizeBmp);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(jpg, 0, 0, resizeWidth, resizeHeight);
g.Dispose();
return resizeBmp;
}
public int[] matY(int imageHeight) //平面→球面投影座標変換Y配列
{
int[] ymat = new int[imageHeight - 1];
for (int i = 0; i < imageHeight - 1; i++)
{
ymat[i] = (int)((double)imageHeight / Math.PI * Math.Acos(1 - 2 * i / (double)imageHeight));
}
return ymat;
}
public int[,] matX(int[] ymat, int iH) //平面→球面投影座標変換X配列
{
int[,] xmat = new int[iH - 1, iH - 1];
double f;
for (int i = 0; i < iH - 1; i++)
{
for (int j = 0; j < iH - 1; j++)
{
xmat[j, i] = iH + 1;
double ch = (double)(Math.Sqrt((i - iH / 2) * (i - iH / 2) + (j - iH / 2) * (j - iH / 2)));
if (ch < iH / 2)
{
f = (1 - 2 * (double)j / (double)iH) / Math.Sin((double)ymat[i] * Math.PI / (double)iH);
if (f > 0.99)
f = 0.99;
if (f < -1)
f = -1;
xmat[j, i] = (int)((double)iH / Math.PI * Math.Acos(f));
}
}
}
return xmat;
}
次の記事へ続く。