特定の範囲(ユーザーが入力)の変数tを使用して[x(t)、y(t)]をプロットするプログラムを作成しています。これまで、t、x(t)、y(t)の値を保持する3つのベクトルを作成しました。私の現在のアプローチは、ポイントのベクトル(約1000ポイント)を作成してから、ベクトル内の2つの隣接するポイントの間に線(またはパス)を描画することです。しかし、結果は私が期待したものではありません。
ユーザーからの完全な形式:
Plot [x(t),y(t)] x=a..b y=a..b t=a..b where a,b are the range of x,y,t
たとえば、ユーザーは次の関数を入力できます。
x(t) = 5*sin(3t + 5), t=-19..19
y(t) = 4*cos(2t), t=-19.19
これが私の描画コードです:
public static void drawGraph(String sf, String sx, String sy, String st) {
JFrame mygraph = new JFrame("PlotGraph v0.1");
final Vector<Double> range_t = getRangeT(st); //get the range of t
//create a corresponding vectors of x and y based on values of t
final Vector<Double> range_x = getRangeX(range_t,funcX,var);
final Vector<Double> range_y = getRangeY(range_t,funcY,var);
//draw the graph to a JPanel, our graph is actually just a collection of points connecting 2 points
mygraph.add(new JPanel() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.BLUE );
g2.setStroke(new BasicStroke(1));
GeneralPath gpx = new GeneralPath();
GeneralPath gpy = new GeneralPath();
for (int i=0; i<998; i++) {
gpy.moveTo(range_t.get(i),range_y.get(i));
gpy.curveTo(range_t.get(i),range_y.get(i),range_t.get(i+1),range_y.get(i+1),range_t.get(i+2),range_y.get(i+2));
gpx.moveTo(range_t.get(i),range_x.get(i));
gpx.curveTo(range_t.get(i),range_x.get(i),range_t.get(i+1),range_x.get(i+1),range_t.get(i+2),range_x.get(i+2));
//g2.draw(lineY);
g2.draw(gpx);
g2.draw(gpy);
}
g2.dispose();
}
});
mygraph.setBounds(125,25,650,600);
mygraph.setLocationRelativeTo(null);
mygraph.setDefaultCloseOperation(mygraph.EXIT_ON_CLOSE);
mygraph.setVisible(true);
}
そして、これが上記の2つの関数で得られるものです。
質問: プロットをより良くする(スケールアップする)方法はありますか?!