Im making an applet to graph a quadratic function...now im not going to be rude and say "tell me how to do it!" but i was just wondering if i could get some assistance on making it...
Now of course, i've had a go at it, and i've made an applet to display the z intercepts, y intercept, and vertex (turning point). This is determined by the user inputs of the three coefficients a, b, and c.
First question, is this all the information i will need?
Secondly, i am struggling to figure out how to put this information into a graph and make it a parabola...
Thank you very much for your help!
Ps. my applet is below if you wish to have a look, i've made a crude graph if that helps as well...
public void actionPerformed(ActionEvent e) { notFirst = true; if (e.getSource() == calcButton) { a = Double.parseDouble(aInput.getText()); b = Double.parseDouble(bInput.getText()); c = Double.parseDouble(cInput.getText()); if (aInput.getText().equals("")) { a = 0; } repaint(); } } }
2. question: java.awt.geom only offers straight lines and arcs of circles and ellipses. So what you need to do is to create your own renderer. The easiest way is to transform the x-coordinate on your screen into the x-coordinate of your function (you only need the offset and scale factor for that), calculate the y-value and transform it to a screen y-value. Use lines to connect the points, if you do it for every x-value on your screen, no one will ever notice. If this is to slow, then try to do it for every second x-value.
ah yes! that sounds feasible! and a fairly good way to go about it!
i dont suppose you have an example or a link that you could point me to of a guide for this sort of thing? just to help me out a bit more on coding thats all...
Thanks very much for your explanation! its helped! :)
Note: I know there are classes like AffineTransformation or whatever, so you can draw on a Canvas giving an offset and direction of the y-axis. But I never used them, so I'll convert the y-Values manually. (yScreen = y0Real - yReal)
double scaleFactor = .5; //Unit is [mm / pixel]
Point2D.Double p0Screen = new Point2D.Double (15, 300); // this is where the point (0,0) lies on the screen. You can also use fraction digits, they'll be rounded when you draw on the Graphics2D Object.
int pixelsToDraw = 300;
for (int xScreenRelative = 0; xScreenRelative < pixelsToDraw; xScreenRelative++) {
double xReal = xScreenRelative * scaleFactor; //No need to look at the offset, I use the counter as coordinate
double yReal = functionCall(xReal, [otherParameters]); //
Point2D.Double pScreen = new Point2D.Double(p0Screen.x + xScreenRelative, p0Screen.y - yReal / scaleFactor); //Draw this Point
}
I just typed this example here in the editor, didn't compile it. So you might encounter an error or two. But the code should give you the idea.
One more thing: I didn't read anything of your code, because you didn't use java tags. Next time, pelase use them. Read the "Formatting Your Post" section on the right of the input field.
Hint: If you have to modify a post, usually it's allready too late. All the blank spaces in front of the lines were removed by then. Just use the java tags for your next problem.