开发者

Plotting a Decimal valued Points in Java

I am Creating a Graph Plotting Software in java. As a part of process if the equation is of form of y = Sin(x) * Cos(x)

then in that case the value of y is a decimal valued points. But in Java we are allowed to plot only integer points. Is there any way to plot points in decimal format us开发者_如何学运维ing 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. 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.

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 getScaledInstanceSampleModel.getScaledInstance on your buffered image with the hint 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. See http://java.sun.com/docs/books/tutorial/2d/geometry/primitives.html for further details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜