/*
* 作成日: 2005/02/09 (C) H.Ishikawa
*/
/*
* スクリーン座標と論理座標を変換するclass
*/
package window;
import java.awt.Graphics;
import java.awt.Color;
public class Window {
static int WINDOW = 5; /* (1)Windowの数 0から最大4まで */
static int win_sx1[] = new int[WINDOW]; /* (2)スクリーン座標上のx1 */
static int win_sy1[] = new int[WINDOW]; /* スクリーン座標上のy1 */
static int win_sx2[] = new int[WINDOW]; /* スクリーン座標上のx2 */
static int win_sy2[] = new int[WINDOW]; /* スクリーン座標上のy2 */
static double win_wx1[] = new double[WINDOW]; /* 論理座標上のx1 */
static double win_wy1[] = new double[WINDOW]; /* 論理座標上のy1 */
static double win_wx2[] = new double[WINDOW]; /* 論理座標上のx2 */
static double win_wy2[] = new double[WINDOW]; /* 論理座標上のy2 */
static double win_sdx[] = new double[WINDOW]; /* スクリーン座標と論理座標の比 */
static double win_sdy[] = new double[WINDOW]; /* スクリーン座標と論理座標の比 */
static double win_cpx[] = new double[WINDOW]; /* 現在位置x */
static double win_cpy[] = new double[WINDOW]; /* (3)現在位置y */
String s;
public void setWindow(int win, double wx1, double wy1, double wx2, double wy2,
int x1, int y1, int x2, int y2) {
win_sx1[win] = x1; win_sy1[win] = y1;
win_sx2[win] = x2; win_sy2[win] = y2;
win_wx1[win] = wx1; win_wy1[win] = wy1;
win_wx2[win] = wx2; win_wy2[win] = wy2;
win_sdx[win] = (double)((x2-x1) / (wx2-wx1));
win_sdy[win] = (double)((y2-y1) / (wy2-wy1));
}
public double getWx(int win, int screenx) {
return(win_wx1[win] + (double)((screenx - win_sx1[win]) / win_sdx[win]));
}
public double getWy(int win, int screeny) {
return(win_wy1[win] + (double)((screeny - win_sy1[win]) / win_sdy[win]));
}
public int getSx(int win, double x) {
return(win_sx1[win] + (int)((x - win_wx1[win]) * win_sdx[win]));
}
public int getSy(int win, double y) {
return(win_sy1[win] + (int)((y - win_wy1[win]) * win_sdy[win]));
}
public void axis(int win,
String x_axis, double x_scale, String y_axis, double y_scale, Graphics g) {
double x ;
double y ;
g.setColor(Color.lightGray);
x = x_scale;
/* 原点から右へ目盛りをかく */
while (x <= win_wx2[win]) {
if (win_wx1[win] <= x) {line( win, x, win_wy1[win], x, win_wy2[win], g);}
x = x + x_scale;
}
x = -x_scale;
/* 原点から左に目盛りをかく */
while (win_wx1[win] <= x) {
if (x <= win_wx2[win]) {line( win, x, win_wy1[win], x, win_wy2[win], g);}
x = x - x_scale;
}
y = y_scale;
/* 原点から上に目盛りをかく */
while (y <= win_wy2[win]) {
if (win_wy1[win] <= y) {line( win, win_wx1[win], y, win_wx2[win], y, g);}
y = y + y_scale;
}
y = -y_scale;
/* 原点から下に目盛りをかく */
while (win_wy1[win] <= y) {
if (y <= win_wy2[win]) line( win, win_wx1[win], y, win_wx2[win], y, g);
y = y - y_scale;
}
g.setColor(Color.black);
if (win_wy1[win] <= 0.0 && 0.0 <= win_wy2[win]) {
line(win, win_wx1[win], 0.0, win_wx2[win], 0.0, g);
} /* 縦軸 */
if (win_wx1[win] <= 0.0 && 0.0 <= win_wx2[win]) {
line(win, 0.0, win_wy1[win], 0.0, win_wy2[win], g);
} /* 横軸 */
/*タイトルをかく */
s = " Window " + win + " 横軸 : " + x_axis + " [ " + x_scale + " / div ]" +
" 縦軸 : " + y_axis + " [ " + y_scale + " / div ]";
g.drawString(s,getSx(win,win_wx1[win]) , getSy(win,win_wy1[win]) + 10);
}
public void line(int win, double x0, double y0, double x1, double y1, Graphics g) {
g.drawLine(getSx(win,x0), getSy(win, y0), getSx(win, x1), getSy(win, y1));
}
public void putPixel(int win, double x, double y, Graphics g) {
g.drawLine(getSx(win, x), getSy(win, y),getSx(win, x), getSy(win, y));
}
public void moveTo(int win, double x, double y, Graphics g) {
win_cpx[win] = x;
win_cpy[win] = y;
}
public void lineTo(int win, double x, double y, Graphics g) {
line(win, win_cpx[win], win_cpy[win], x, y, g);
moveTo(win, x, y, g);
}
}
|