Results 1 to 1 of 1
 01232011, 09:14 PM #1Member
 Join Date
 Jan 2011
 Posts
 1
 Rep Power
 0
Help with Polynomial Graph Plotter and its scaling
I am trying to make a polynomial graph plotter. It takes the degree for a polynomial and then starts taking coefficients one by one.
I want to set its scaling like i want its coordinates not set to the pixels but each coordinate should be 10 or more pixels away from the other coordinate. And one more problem is when I give higher degrees to the program, it does not give an appropriate graph. Kindly tell what is the issue with that program. I am using two different classes. One of them is :
Java Code:import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JPanel; import java.awt.Color; public class gr03_draw extends JPanel { private int []coEffi; // array for coefficients public gr03_draw(int []userChoice) // takes an array filled with coefficients { coEffi=userChoice; //assigns the array to another one } public void paintComponent(Graphics gx){ super.paintComponent(gx); Graphics2D g=(Graphics2D)gx; int width= getWidth(); int height= getHeight(); g.setColor(Color.WHITE); //setting background color g.fillRect(0, 0, width, height); g.setColor(Color.RED); g.drawLine(0, height/2, width, height/2); // xaxis line g.drawLine(width/2, 0, width/2, height); //yaxis line int degree=coEffi.length1; for(int x=width; x<=width; x++) //finds the ordinates from given values of x { int y=0; int y2=0; for(int i=0; i<=degree; i++) //finds the y1 for the line { y+=(coEffi[i]*Math.pow(x,i)); } for(int i2=0; i2<=degree; i2++) //finds the y2 for the line { y2+=(coEffi[i2]*Math.pow(x+1,i2)); } /*Following three lines are used to hold origin at the center I am not using "translate" here, as I was unable to set the direction of yaxis from*/ int pntX=(width/2)+x; int pntY=height((height/2)+y); int pntY2=height((height/2)+y2); //it draws the lines g.drawLine(pntX, pntY, pntX+1, pntY2); }//end of loop } }
Java Code:import javax.swing.JFrame; import javax.swing.JOptionPane; public class gr03_draw2 { public static void main(String[] args) { String inputDeg=JOptionPane.showInputDialog("Tell the Degree of Polynomial"); int degree=Integer.parseInt(inputDeg); JOptionPane.showMessageDialog(null, "Start entering coefficients one by one"); int []coef=new int[degree]; for(int i=0; i<coef.length; i++) { String inputCo=JOptionPane.showInputDialog("Tell the Degree of Polynomial"); coef[i]=Integer.parseInt(inputCo); } gr03_draw panel = new gr03_draw(coef); JFrame appli= new JFrame(); // I tried the following line to set distance between the coordinates //setLayout(new GridLayout(1,1,20,20)); appli.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); appli.add(panel); appli.setSize(400, 500); appli.setVisible(true); } }
Similar Threads

[Help] Polynomial Class in Java
By AndrewSD in forum New To JavaReplies: 3Last Post: 01112011, 04:24 AM 
API polynomial java
By mcherkao in forum Advanced JavaReplies: 5Last Post: 09102010, 01:49 PM 
Polynomial Arithmetic Java
By thisisIT in forum New To JavaReplies: 3Last Post: 03092010, 05:33 PM 
Scaling a JPEG
By ScottVal in forum Advanced JavaReplies: 5Last Post: 03212009, 08:47 PM 
Help with polynomial program
By susan in forum New To JavaReplies: 1Last Post: 08072007, 04:44 AM
Bookmarks