简体   繁体   中英

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 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. 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 getScaledInstance SampleModel.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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