简体   繁体   English

在Java中绘制小数点

[英]Plotting a Decimal valued Points in Java

I am Creating a Graph Plotting Software in java. 我正在用Java创建图形绘图软件。 As a part of process if the equation is of form of y = Sin(x) * Cos(x) 作为方程式的一部分,如果方程式为y = Sin(x)* Cos(x)

then in that case the value of y is a decimal valued points. 那么在这种情况下,y的值是一个十进制的点。 But in Java we are allowed to plot only integer points. 但是在Java中,我们只能绘制整数点。 Is there any way to plot points in decimal format using any package ??? 有没有办法使用任何软件包以十进制格式绘制点?

The Another strategy that can be used is to convert the decimal value into corresponding integer value. 可以使用的另一种策略是将十进制值转换为相应的整数值。 But that algorithm won't give me a smooth curve ... 但是那个算法不会给我平滑的曲线...

Thanx in Advance... 提前感谢...

If your using the Graphics class to draw your picture, use a XXXX2D class rather than XXXX class with a Graphics2D. 如果您使用Graphics类来绘制图片,请使用XXXX2D类而不是带有Graphics2D的XXXX类。 For example: 例如:

Graphics2D g=(Graphics2D)g1;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.draw(new Line2D.Double(1.000,1.22,78.98098,3.098));
(...)

I suppose the integers x, y for a plot are the pixels at which they should go. 我假设绘图的整数x,y是像素应到达的像素。

If you can't get a nice curve by scaling your values, you should probably think of creating a larger image in memory ( perhaps twice the y scale) and paint on that, en then scaling that image back to your GUI using getScaledInstance SampleModel.getScaledInstance on your buffered image with the hint SCALE_SMOOTH . 如果无法通过缩放值获得漂亮的曲线,则可能应该考虑在内存中创建更大的图像(可能是y缩放的两倍)并在其上进行绘制,然后使用getScaledInstance SampleModel将图像缩放回GUI 。 getScaledInstance与提示您的缓冲图像上SCALE_SMOOTH

Though what Pierre said is possibly better. 尽管皮埃尔所说的可能更好。

It is possible to plot points at non integer positions. 可以在非整数位置绘制点。 You may use Point2D.Double or Point2D.Float . 您可以使用Point2D.DoublePoint2D.Float See http://java.sun.com/docs/books/tutorial/2d/geometry/primitives.html for further details. 有关更多详细信息,请参见http://java.sun.com/docs/books/tutorial/2d/geometry/primitives.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM