java某一点的极坐标,在java中绘制极坐标图

Does anyone know how I can get started to draw a polar graph in java and plot some points on this graph? I mean the circles and lines, I wish to do this with something like swing, and not use any library like Jfreechart

Thanks

解决方案

You might like to look at Lissajous curves; an example of a = 5, b = 4 (5:4) is shown below.

Addendum: Once you see how to plot points in xy coordinates, then you should look at converting between polar and Cartesian coordinates.

w7N3q.png

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);

}

});

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值