Off topic question - I want to plot a Math.sin() equation and I got stuck on translation values to real pixel coordinates. How to scale these values ? Assuming that I have a JPanel with 300 width and 150 height dimension. What do I need to do ? Any useful links ?
Could you please take a look at this code snippet:
It is supposed to draw a sin(x) for x=-2*pi to x=+2*pi and indeed it does. The only problem is that I need to resize the window (which is now 300 width and 200 height) to see the whole graph. I know that some part of the window is taken by the title bar, so I would have to take it into account in my calculations. However I wonder why I lack about 10 pixels to see the graph in full horizontally ? To avoid it, I need to create a window of size: JFrame(310 instead of 300 ???, 230 instead of 200 because of the title bar).
I made the following small program to display your sinusoid and it displays fine, I don't need to resize the window to see it:
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 32767
posted
0
I think this code makes a nice example for plotting a function, so I added it as sample code to the FAQ: http://faq.javaranch.com/view?PlotSineCurve. In addition, the plot adapts to the frame size, and optionally a line is drawn connecting the dots. [ July 09, 2007: Message edited by: Ulf Dittmer ]