# level curves in java

parasto harir
Greenhorn
Posts: 8
Hi,

I have to write a program which can draw contour plot(level curves) of every function, but i do not know how to calculate x and y in f(x,y)=z to draw the level curves?
I could not find any source code which can help me

parasto harir
Greenhorn
Posts: 8
Thanks for your reply but the video was not related to level curves, I did not get the idea.

parasto harir
Greenhorn
Posts: 8
I could not find my subject in that site too, you mean that I send them email?

Greg Charles
Sheriff
Posts: 2993
12

Can you explain how you'd draw these level curves without a program? If you can, we can probably help you translate the process into Java code.

parasto harir
Greenhorn
Posts: 8
Actually my program receives step size, first level and number of contours from user then it has to calculate the collection of all points (x,y) in the domain of a function f for which f(x,y) = c .
then it will show all level curves in related area
I want to have some result similar to this site:

but I do not know how to find the exact value of x and y when f(x,y)= c ?

parasto harir
Greenhorn
Posts: 8
Actually my program receives step size, first level and number of contours from user then it has to calculate the collection of all points (x,y) in the domain of a function f for which f(x,y) = c .
then it will show all level curves in related area
I want to have some result similar to this site:

but I do not know how to find the exact value of x and y when f(x,y)= c ?

Greg Charles
Sheriff
Posts: 2993
12
Well, that's a cool link. It doesn't seem to be calculating x and y for a given z though, like you would need to draw a topography map of a mountain. Instead it's drawing a three dimensional graph showing z values for all x, y over some range. It draws some lines on the graph for fixed values of x and y, but not fixed values of z.

Let's say that you actually do need to calculate f(x,y) = c though. You would need to solve for y in terms of x, and then plot that on a two-dimension graph. For example, you have the formula for a cone: z=√ (x² +y²) , and you want to solve that for z = 4. You rearrange it as y = √(16 -x²), which gives you a circle with radius 4. Again, that's math though, not Java programing. You should have a firm grasp of the math before you even think about converting it to a program.

parasto harir
Greenhorn
Posts: 8

I have two frame and I defined two different canvas for each of them, one of them which I defined another class for that does not work with my code:

public class myCanvas extends GLCanvas {

private GL gl;
private GLAutoDrawable drawable;

public void paint(GLAutoDrawable drawable) {

GLUT glut = new GLUT();
GL gl = drawable.getGL();

gl.glBegin(GL.GL_LINES);
gl.glVertex3f(0.0f, -2.5f, 0.0f);
gl.glVertex3f(0.0f, 2.5f, 0.0f);
gl.glEnd();}
}

but this canvas works with this code:

public void paint(Graphics g) {
g.drawOval(13, 23, 65, 66);
}

I do not what is wrong , because I need to draw my object by using those code, I call this class by " contour_canvas.paint(drawable); " in the main class?

parasto harir
Greenhorn
Posts: 8
Hi,

yes it seems to be easy to calculate for y in terms of x, in f(x,y)=c . but I have to find a solution which is good enough for general types of equation. in your example it was easy to calculate y and x but for example in :
x² +y²+3+log(x)-cos(x+y) = c how should I solve that?

thanks

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.