在java中绘制极坐标图
有谁知道我如何开始在java中绘制极坐标图并在该图上绘制一些点?我的意思是圆和线,我希望用 swing 之类的东西来做到这一点,而不是使用像 Jfreechart 这样的任何库 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Java2D 是官方 JDK 的一部分,非常适合您的目的。您可以在此处找到 Java 文档:Java2d
Java2D is part of the official JDK and fits your purposes perfectly. You can find the java doc here: Java2d
您将需要使用 Java2D 来绘制适合您需要的圆形/多边形。在您想要绘制的控件的
public void Paint(Graphics g)
方法中,您可以绘制到 Graphics 对象。一些可能有用的示例:请记住,drawOval、drawRect 等调用的位置是形状的左上角,而不是形状的中心。如果您希望椭圆形以 50 为中心且宽度为 100,则需要将
xPos
和yPos
设置为 0。You'll want to use Java2D to draw circles/polygons that fit your needs. In the
public void paint(Graphics g)
method of the control you wish to draw on, you can draw to the Graphics object. Some examples of various things that might be helpful:Keep in mind that the position on calls like drawOval, drawRect, etc is for the top left corner of the shape, not the center of the shape. If you want your oval to be centered on 50 and with width 100, you'd need to set the
xPos
andyPos
to 0.您可能想查看利萨如曲线;下面显示了
a = 5, b = 4 (5:4)
的示例。附录:一旦您了解了如何在xy坐标中绘制点,那么您应该查看极坐标和笛卡尔坐标之间的转换。
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.