怎么做移动网站吗/苏州网站建设费用
有谁知道如何开始在java中绘制极坐标图并在此图上绘制一些点?我的意思是圆圈和线条,我希望用像swing这样的东西来做这件事,而不是像Jfreechart那样使用任何库
谢谢
解决方法:
你可能想看看Lissajous curves; a = 5,b = 4(5:4)的例子如下所示.
public class LissajousPanel extends JPanel {
private static final int SIZE = 400;
private GeneralPath path = new GeneralPath();
@Override
public Dimension getPreferredSize() {
return new Dimension(SIZE, SIZE);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
double dt = Math.PI / 180;
int w = getWidth() / 2;
int h = getHeight() / 2;
path.reset();
path.moveTo(w, h);
for (double t = 0; t < 2 * Math.PI; t += dt) {
double x = w * Math.sin(5 * t) + w;
double y = h * Math.sin(4 * t) + h;
path.lineTo(x, y);
}
g2d.setColor(Color.blue);
g2d.draw(path);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new LissajousPanel());
f.pack();
f.setVisible(true);
}
});
}
}
标签:java,plot,graph,draw
来源: https://codeday.me/bug/20190918/1810365.html