galera tem como eu desenha a funcao seno, cosseno???
se tiver como seria?
vlw
galera tem como eu desenha a funcao seno, cosseno???
se tiver como seria?
vlw
vc ira usar a classe Math amigo aki tem tudo q vc precisa pra se virar
Eu sei q isso me da o cosseno, etc… eu gostaria de saber como se faz para plotar isso… o desenho do cosseno, seno…
vlw
/*
* plotmath.java
*
* Created on 29 de Março de 2008, 22:56
*/
package plotmath;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
/**
*
* @author luiz
*/
public class plotmath extends javax.swing.JFrame {
/** Creates new form plotmath */
public plotmath() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jPanel1 = new javax.swing.JPanel()
{
Graphics2D g;
int antigoX=0;
int antigoY=0;
int x=0;
int y=0;
public void paintComponent( Graphics G)
{
g = (Graphics2D) G.create();
plota();
g.dispose();
}
private void plota()
{
int frequencia = this.getWidth();
int amplitude = this.getHeight();
g.setColor(Color.BLACK);
for(double ang=0; ang<=360; ang+=10)
{
x = (int) (frequencia*ang/360);
//tenta mudar aqui
y = (int) (Math.sin( (Math.PI*ang/180 )) * amplitude/2 ) ;
g.drawLine( antigoX, antigoY+ amplitude/2, x, y+ amplitude/2);
antigoX = x;
antigoY = y;
}
antigoX=0;
antigoY=0;
}
};
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
}
// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new plotmath().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
// End of variables declaration
}